Skip to content

Commit

Permalink
Addressed the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nargis Sultani committed Jan 2, 2024
1 parent f584799 commit 21052bb
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 151 deletions.
119 changes: 0 additions & 119 deletions db_revisions/seed.py

This file was deleted.

18 changes: 14 additions & 4 deletions db_revisions/versions/26a742d97ad9_seed_federal_regulator_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"""
from typing import Sequence, Union
from alembic import op
from entities.models import FederalRegulatorDao
from db_revisions.seed import federal_regulator_seed
from entities.models.dao import Base


# revision identifiers, used by Alembic.
Expand All @@ -17,10 +16,21 @@
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

federal_regulator_table = Base.metadata.tables.get("federal_regulator")


def upgrade() -> None:
op.bulk_insert(FederalRegulatorDao.__table__, federal_regulator_seed)
seed_data = [
{"id": "FCA", "name": "Farm Credit Administration"},
{"id": "FDIC", "name": "Federal Deposit Insurance Corporation"},
{"id": "FHFA", "name": "Federal Housing Finance Agency"},
{"id": "FRS", "name": "Federal Reserve System"},
{"id": "NCUA", "name": "National Credit Union Administration"},
{"id": "OCC", "name": "Office of the Comptroller of the Currency"},
{"id": "OTS", "name": "Office of Thrift Supervision (only valid until July 21, 2011)"},
]
op.bulk_insert(federal_regulator_table, seed_data)


def downgrade() -> None:
op.execute(FederalRegulatorDao.__table__.delete())
op.execute(federal_regulator_table.delete())
69 changes: 65 additions & 4 deletions db_revisions/versions/7b6ff51002b5_seed_address_state_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"""
from typing import Sequence, Union
from alembic import op
from entities.models import AddressStateDao
from db_revisions.seed import address_state_seed
from entities.models.dao import Base


# revision identifiers, used by Alembic.
Expand All @@ -17,10 +16,72 @@
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

address_state_table = Base.metadata.tables.get("address_state")


def upgrade() -> None:
op.bulk_insert(AddressStateDao.__table__, address_state_seed)
seed_data = [
{"code": "AL", "name": "Alabama"},
{"code": "AK", "name": "Alaska"},
{"code": "AZ", "name": "Arizona"},
{"code": "AR", "name": "Arkansas"},
{"code": "CA", "name": "California"},
{"code": "CO", "name": "Colorado"},
{"code": "CT", "name": "Connecticut"},
{"code": "DE", "name": "Delaware"},
{"code": "FL", "name": "Florida"},
{"code": "GA", "name": "Georgia"},
{"code": "HI", "name": "Hawaii"},
{"code": "ID", "name": "Idaho"},
{"code": "IL", "name": "Illinois"},
{"code": "IN", "name": "Indiana"},
{"code": "IA", "name": "Iowa"},
{"code": "KS", "name": "Kansas"},
{"code": "KY", "name": "Kentucky"},
{"code": "LA", "name": "Louisiana"},
{"code": "ME", "name": "Maine"},
{"code": "MD", "name": "Maryland"},
{"code": "MA", "name": "Massachusetts"},
{"code": "MI", "name": "Michigan"},
{"code": "MN", "name": "Minnesota"},
{"code": "MS", "name": "Mississippi"},
{"code": "MO", "name": "Missouri"},
{"code": "MT", "name": "Montana"},
{"code": "NE", "name": "Nebraska"},
{"code": "NV", "name": "Nevada"},
{"code": "NH", "name": "New Hampshire"},
{"code": "NJ", "name": "New Jersey"},
{"code": "NM", "name": "New Mexico"},
{"code": "NY", "name": "New York"},
{"code": "NC", "name": "North Carolina"},
{"code": "ND", "name": "North Dakota"},
{"code": "OH", "name": "Ohio"},
{"code": "OK", "name": "Oklahoma"},
{"code": "OR", "name": "Oregon"},
{"code": "PA", "name": "Pennsylvania"},
{"code": "RI", "name": "Rhode Island"},
{"code": "SC", "name": "South Carolina"},
{"code": "SD", "name": "South Dakota"},
{"code": "TN", "name": "Tennessee"},
{"code": "TX", "name": "Texas"},
{"code": "UT", "name": "Utah"},
{"code": "VT", "name": "Vermont"},
{"code": "VA", "name": "Virginia"},
{"code": "WA", "name": "Washington"},
{"code": "WV", "name": "West Virginia"},
{"code": "WI", "name": "Wisconsin"},
{"code": "WY", "name": "Wyoming"},
{"code": "DC", "name": "District of Columbia"},
{"code": "AS", "name": "American Samoa"},
{"code": "GU", "name": "Guam"},
{"code": "MP", "name": "Northern Mariana Islands"},
{"code": "PR", "name": "Puerto Rico"},
{"code": "UM", "name": "United States Minor Outlying Islands"},
{"code": "VI", "name": "Virgin Islands, U.S."},
]

op.bulk_insert(address_state_table, seed_data)


def downgrade() -> None:
op.execute(AddressStateDao.__table__.delete())
op.execute(address_state_table.delete())
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@
"""
from typing import Sequence, Union
from alembic import op
from entities.models import SBLInstitutionTypeDao
from db_revisions.seed import sbl_institution_type_seed
from entities.models.dao import Base

# 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

sbl_institution_type_table = Base.metadata.tables.get("sbl_institution_type")


def upgrade() -> None:
op.bulk_insert(SBLInstitutionTypeDao.__table__, sbl_institution_type_seed)
seed_data = [
{"id": "1", "name": "Bank or savings association."},
{"id": "2", "name": "Minority depository institution."},
{"id": "3", "name": "Credit union."},
{"id": "4", "name": "Nondepository institution."},
{"id": "5", "name": "Community development financial institution (CDFI)."},
{"id": "6", "name": "Other nonprofit financial institution."},
{"id": "7", "name": "Farm Credit System institution."},
{"id": "8", "name": "Government lender."},
{"id": "9", "name": "Commercial finance company."},
{"id": "10", "name": "Equipment finance company."},
{"id": "11", "name": "Industrial loan company."},
{"id": "12", "name": "Online lender."},
{"id": "13", "name": "Other"},
]
op.bulk_insert(sbl_institution_type_table, seed_data)


def downgrade() -> None:
op.execute(SBLInstitutionTypeDao.__table__.delete())
op.execute(sbl_institution_type_table.delete())
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"""
from typing import Sequence, Union
from alembic import op
from entities.models import HMDAInstitutionTypeDao
from db_revisions.seed import hmda_institution_type_seed
from entities.models.dao import Base


# revision identifiers, used by Alembic.
Expand All @@ -17,10 +16,32 @@
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

hmda_institution_type_table = Base.metadata.tables.get("hmda_institution_type")


def upgrade() -> None:
op.bulk_insert(HMDAInstitutionTypeDao.__table__, hmda_institution_type_seed)
seed_data = [
{"id": "1", "name": "National Bank (OCC supervised)"},
{"id": "2", "name": "State Member Bank (FRS Supervised)"},
{"id": "3", "name": "State non-member bank (FDIC supervised)"},
{"id": "4", "name": "State Chartered Thrift (FDIC supervised)"},
{"id": "5", "name": "Federal Chartered Thrift (OCC supervised)"},
{"id": "6", "name": "Credit Union (NCUA supervised)"},
{"id": "7", "name": "Federal Branch or Agency of Foreign Banking Organization (FBO)"},
{"id": "8", "name": "Branch or Agency of FBO (FRS supervised)"},
{"id": "9", "name": "MBS of national Bank (OCC supervised)"},
{"id": "10", "name": "MBS of state member bank (FRS supervised)"},
{"id": "11", "name": "MBS of state non-member bank (FDIC supervised)"},
{"id": "12", "name": "MBS of Bank Holding Company (BHC) (FRS supervised)"},
{"id": "13", "name": "MBS of credit union (NCUA supervised)"},
{"id": "14", "name": "independent MBS, no depository affiliation"},
{"id": "15", "name": "MBS of Savings and Loan Holding Co"},
{"id": "16", "name": "MBS of state chartered Thrift"},
{"id": "17", "name": "MBS of federally chartered thrift (OCC supervised)"},
{"id": "18", "name": "Affiliate of depository institution. MBS is in the same ownership org as a depository."},
]
op.bulk_insert(hmda_institution_type_table, seed_data)


def downgrade() -> None:
op.execute(HMDAInstitutionTypeDao.__table__.delete())
op.execute(hmda_institution_type_table.delete())
32 changes: 16 additions & 16 deletions tests/migrations/test_lookup_tables_data_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
from sqlalchemy.engine import Engine
from pytest_alembic import MigrationContext

from seed import (
address_state_seed,
federal_regulator_seed,
hmda_institution_type_seed,
sbl_institution_type_seed,
)


def test_address_state_data_seed(alembic_runner: MigrationContext, alembic_engine: Engine):
# Migrate up to, but not including this new migration
Expand All @@ -18,9 +11,10 @@ def test_address_state_data_seed(alembic_runner: MigrationContext, alembic_engin
address_state_tablename = "address_state"
alembic_runner.migrate_up_one()
with alembic_engine.connect() as conn:
address_state_rows = conn.execute(text("SELECT code, name from %s" % address_state_tablename)).fetchall()
address_state_expected = [tuple(dict.values()) for dict in address_state_seed]

address_state_rows = conn.execute(
text("SELECT code, name from %s where code = :code" % address_state_tablename), (dict(code="AL"))
).fetchall()
address_state_expected = [("AL", "Alabama")]
assert address_state_rows == address_state_expected


Expand All @@ -32,8 +26,12 @@ def test_federal_regulator_data_seed(alembic_runner: MigrationContext, alembic_e
federal_regulator_tablename = "federal_regulator"
alembic_runner.migrate_up_one()
with alembic_engine.connect() as conn:
federal_regulator_rows = conn.execute(text("SELECT id, name from %s" % federal_regulator_tablename)).fetchall()
federal_regulator_expected = [tuple(dict.values()) for dict in federal_regulator_seed]
federal_regulator_rows = conn.execute(
text("SELECT id, name from %s where id = :id" % federal_regulator_tablename), (dict(id="FCA"))
).fetchall()
federal_regulator_expected = [
("FCA", "Farm Credit Administration"),
]

assert federal_regulator_rows == federal_regulator_expected

Expand All @@ -47,9 +45,11 @@ def test_hmda_institution_type_data_seed(alembic_runner: MigrationContext, alemb
alembic_runner.migrate_up_one()
with alembic_engine.connect() as conn:
hmda_institution_type_rows = conn.execute(
text("SELECT id, name from %s" % hmda_institution_type_tablename)
# text("SELECT id, name from %s" % hmda_institution_type_tablename)
text("SELECT id, name from %s where id = :id" % hmda_institution_type_tablename),
(dict(id="1")),
).fetchall()
hmda_institution_type_expected = [tuple(dict.values()) for dict in hmda_institution_type_seed]
hmda_institution_type_expected = [("1", "National Bank (OCC supervised)")]

assert hmda_institution_type_rows == hmda_institution_type_expected

Expand All @@ -63,8 +63,8 @@ def test_sbl_institution_type_data_seed(alembic_runner: MigrationContext, alembi
alembic_runner.migrate_up_one()
with alembic_engine.connect() as conn:
sbl_institution_type_rows = conn.execute(
text("SELECT id, name from %s" % sbl_institution_type_tablename)
text("SELECT id, name from %s where id = :id " % sbl_institution_type_tablename), (dict(id="1"))
).fetchall()
sbl_institution_type_expected = [tuple(dict.values()) for dict in sbl_institution_type_seed]
sbl_institution_type_expected = [("1", "Bank or savings association.")]

assert sbl_institution_type_rows == sbl_institution_type_expected

0 comments on commit 21052bb

Please sign in to comment.