-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Features/61 alembic seed lookup tables #65
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f619a59
Updated institution model, modified unit tests, and added new tests
2957ad6
Added Alembic files and changes
8ab4c6e
Removed the table_exists condition from updating financial institutio…
9bce1b0
Fixed alembic issues
609863d
changed address_state_code name in db_revision to match that of in th…
b7af90f
Ticket 61: Feeding lookup tables with alembic
8a6e0be
Fixed merge conflict and changed the test case name in test_migrations
a59f6a6
Modified test cases
b39dd24
Address the comment and moved data-feed-related tests to a new file (…
4424a46
removed commented code
35d8c4c
harcoded table names in the revision script and test cases instead of…
bea2615
removed unused imports
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
code|name | ||
AL|Alabama | ||
AK|Alaska | ||
AZ|Arizona | ||
AR|Arkansas | ||
CA|California | ||
CO|Colorado | ||
CT|Connecticut | ||
DE|Delaware | ||
FL|Florida | ||
GA|Georgia | ||
HI|Hawaii | ||
ID|Idaho | ||
IL|Illinois | ||
IN|Indiana | ||
IA|Iowa | ||
KS|Kansas | ||
KY|Kentucky | ||
LA|Louisiana | ||
ME|Maine | ||
MD|Maryland | ||
MA|Massachusetts | ||
MI|Michigan | ||
MN|Minnesota | ||
MS|Mississippi | ||
MO|Missouri | ||
MT|Montana | ||
NE|Nebraska | ||
NV|Nevada | ||
NH|New Hampshire | ||
NJ|New Jersey | ||
NM|New Mexico | ||
NY|New York | ||
NC|North Carolina | ||
ND|North Dakota | ||
OH|Ohio | ||
OK|Oklahoma | ||
OR|Oregon | ||
PA|Pennsylvania | ||
RI|Rhode Island | ||
SC|South Carolina | ||
SD|South Dakota | ||
TN|Tennessee | ||
TX|Texas | ||
UT|Utah | ||
VT|Vermont | ||
VA|Virginia | ||
WA|Washington | ||
WV|West Virginia | ||
WI|Wisconsin | ||
WY|Wyoming | ||
DC|District of Columbia | ||
AS|American Samoa | ||
GU|Guam | ||
MP|Northern Mariana Islands | ||
PR|Puerto Rico | ||
UM|United States Minor Outlying Islands | ||
VI|Virgin Islands, U.S. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
id|name | ||
FCA|Farm Credit Administration | ||
FDIC|Federal Deposit Insurance Corporation | ||
FHFA|Federal Housing Finance Agency | ||
FRS|Federal Reserve System | ||
NCUA|National Credit Union Administration | ||
OCC|Office of the Comptroller of the Currency | ||
OTS|Office of Thrift Supervision (only valid until July 21, 2011) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
id|name | ||
1|National Bank (OCC supervised) | ||
2|State Member Bank (FRS Supervised): | ||
3|State non-member bank (FDIC supervised) | ||
4|State Chartered Thrift (FDIC supervised) | ||
5|Federal Chartered Thrift (OCC supervised) | ||
6|Credit Union (NCUA supervised) | ||
7|Federal Branch or Agency of Foreign Banking Organization (FBO) | ||
8|Branch or Agency of FBO (FRS supervised) | ||
9|MBS of national Bank (OCC supervised) | ||
10|MBS of state member bank (FRS supervised) | ||
11|MBS of state non-member bank (FDIC supervised) | ||
12|MBS of Bank Holding Company (BHC) (FRS supervised) | ||
13|MBS of credit union (NCUA supervised) | ||
14|independent MBS, no depository affiliation | ||
15|MBS of Savings and Loan Holding Co | ||
16|MBS of state chartered Thrift | ||
17|MBS of federally chartered thrift (OCC supervised) | ||
18|Affiliate of depository institution. MBS is in the same ownership org as a depository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
id|name | ||
1|Bank or savings association. | ||
2|Minority depository institution. | ||
3|Credit union. | ||
4|Nondepository institution. | ||
5|Community development financial institution (CDFI). | ||
6|Other nonprofit financial institution. | ||
7|Farm Credit System institution. | ||
8|Government lender. | ||
9|Commercial finance company. | ||
10|Equipment finance company. | ||
11|Industrial loan company. | ||
12|Online lender. | ||
13|Other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
db_revisions/versions/26a742d97ad9_feed_federal_regulator_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Feed Federal Regulator table | ||
|
||
Revision ID: 26a742d97ad9 | ||
Revises: 7b6ff51002b5 | ||
Create Date: 2023-12-14 01:23:17.872728 | ||
|
||
""" | ||
from typing import Sequence, Union | ||
from alembic import op | ||
from db_revisions.utils import get_feed_data_from_file | ||
from entities.models import FederalRegulatorDao | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "26a742d97ad9" | ||
down_revision: Union[str, None] = "7b6ff51002b5" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
data = get_feed_data_from_file(FederalRegulatorDao.__tablename__) | ||
|
||
op.bulk_insert(FederalRegulatorDao.__table__, data) | ||
|
||
|
||
def downgrade() -> None: | ||
op.execute(FederalRegulatorDao.__table__.delete()) |
28 changes: 28 additions & 0 deletions
28
db_revisions/versions/7b6ff51002b5_feed_address_state_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Feed Address State table | ||
|
||
Revision ID: 7b6ff51002b5 | ||
Revises: 045aa502e050 | ||
Create Date: 2023-12-14 01:21:48.325752 | ||
|
||
""" | ||
from typing import Sequence, Union | ||
from alembic import op | ||
from db_revisions.utils import get_feed_data_from_file | ||
from entities.models import AddressStateDao | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "7b6ff51002b5" | ||
down_revision: Union[str, None] = "045aa502e050" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
data = get_feed_data_from_file(AddressStateDao.__tablename__) | ||
|
||
op.bulk_insert(AddressStateDao.__table__, data) | ||
|
||
|
||
def downgrade() -> None: | ||
op.execute(AddressStateDao.__table__.delete()) |
27 changes: 27 additions & 0 deletions
27
db_revisions/versions/a41281b1e109_feed_sbl_institution_type_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Feed SBL Institution Type table | ||
|
||
Revision ID: a41281b1e109 | ||
Revises: f4ff7d1aa6df | ||
Create Date: 2023-12-14 01:24:00.120073 | ||
|
||
""" | ||
from typing import Sequence, Union | ||
from alembic import op | ||
from db_revisions.utils import get_feed_data_from_file | ||
from entities.models import SBLInstitutionTypeDao | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "a41281b1e109" | ||
down_revision: Union[str, None] = "f4ff7d1aa6df" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
data = get_feed_data_from_file(SBLInstitutionTypeDao.__tablename__) | ||
|
||
op.bulk_insert(SBLInstitutionTypeDao.__table__, data) | ||
|
||
|
||
def downgrade() -> None: | ||
op.execute(SBLInstitutionTypeDao.__table__.delete()) |
28 changes: 28 additions & 0 deletions
28
db_revisions/versions/f4ff7d1aa6df_feed_hmda_institution_type_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Feed HMDA Institution Type table | ||
|
||
Revision ID: f4ff7d1aa6df | ||
Revises: 26a742d97ad9 | ||
Create Date: 2023-12-14 01:23:47.017878 | ||
|
||
""" | ||
from typing import Sequence, Union | ||
from alembic import op | ||
from db_revisions.utils import get_feed_data_from_file | ||
from entities.models import HMDAInstitutionTypeDao | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "f4ff7d1aa6df" | ||
down_revision: Union[str, None] = "26a742d97ad9" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
data = get_feed_data_from_file(HMDAInstitutionTypeDao.__tablename__) | ||
|
||
op.bulk_insert(HMDAInstitutionTypeDao.__table__, data) | ||
|
||
|
||
def downgrade() -> None: | ||
op.execute(HMDAInstitutionTypeDao.__table__.delete()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import os | ||
import csv | ||
from sqlalchemy import select | ||
from sqlalchemy.engine import Engine | ||
from pytest_alembic import MigrationContext | ||
from entities.models import AddressStateDao, FederalRegulatorDao, HMDAInstitutionTypeDao, SBLInstitutionTypeDao | ||
|
||
|
||
def data_feed_helper(table_name): | ||
file_dir = os.path.dirname(os.path.realpath(__file__)) | ||
data_file_path = f"{file_dir}/../../db_revisions/feed/%s.csv" % table_name | ||
with open(data_file_path) as f: | ||
reader = csv.reader(f, delimiter="|") | ||
next(reader) | ||
output_list = list(tuple(line) for line in reader) | ||
return output_list | ||
|
||
|
||
def test_address_state_data_feed(alembic_runner: MigrationContext, alembic_engine: Engine): | ||
# Migrate up to, but not including this new migration | ||
alembic_runner.migrate_up_before("7b6ff51002b5") | ||
|
||
# Test address_state feed | ||
alembic_runner.migrate_up_one() | ||
|
||
with alembic_engine.connect() as conn: | ||
address_state_rows = conn.execute(select(AddressStateDao.code, AddressStateDao.name)).fetchall() | ||
address_state_expected = data_feed_helper(AddressStateDao.__tablename__) | ||
assert address_state_rows == address_state_expected | ||
|
||
|
||
def test_federal_regulator_data_feed(alembic_runner: MigrationContext, alembic_engine: Engine): | ||
# Migrate up to, but not including this new migration | ||
alembic_runner.migrate_up_before("26a742d97ad9") | ||
|
||
# Test federal_regulator feed | ||
alembic_runner.migrate_up_one() | ||
with alembic_engine.connect() as conn: | ||
federal_regulator_rows = conn.execute(select(FederalRegulatorDao.id, FederalRegulatorDao.name)).fetchall() | ||
federal_regulator_expected = data_feed_helper(FederalRegulatorDao.__tablename__) | ||
assert federal_regulator_rows == federal_regulator_expected | ||
|
||
|
||
def test_hmda_institution_type_data_feed(alembic_runner: MigrationContext, alembic_engine: Engine): | ||
# Migrate up to, but not including this new migration | ||
alembic_runner.migrate_up_before("f4ff7d1aa6df") | ||
|
||
# Test hmda_institution_type feed | ||
alembic_runner.migrate_up_one() | ||
with alembic_engine.connect() as conn: | ||
hmda_institution_type_rows = conn.execute( | ||
select(HMDAInstitutionTypeDao.id, HMDAInstitutionTypeDao.name) | ||
).fetchall() | ||
hmda_institution_type_expected = data_feed_helper(HMDAInstitutionTypeDao.__tablename__) | ||
assert hmda_institution_type_rows == hmda_institution_type_expected | ||
|
||
|
||
def test_sbl_institution_type_data_feed(alembic_runner: MigrationContext, alembic_engine: Engine): | ||
# Migrate up to, but not including this new migration | ||
alembic_runner.migrate_up_before("a41281b1e109") | ||
|
||
# Test sbl_institution_type feed | ||
alembic_runner.migrate_up_one() | ||
with alembic_engine.connect() as conn: | ||
sbl_institution_type_rows = conn.execute( | ||
select(SBLInstitutionTypeDao.id, SBLInstitutionTypeDao.name) | ||
).fetchall() | ||
sbl_institution_type_expected = data_feed_helper(SBLInstitutionTypeDao.__tablename__) | ||
assert sbl_institution_type_rows == sbl_institution_type_expected |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mentioned in chat, but let's use the actual table names here and the other scripts, instead of relying on the dao property so that in a rare case should there actually be a change in the table name for the dao there is a history, and there wouldn't be conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure