Skip to content

Commit

Permalink
addressed tge comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Nargis Sultani committed Jan 2, 2024
1 parent 21052bb commit 4fd0d11
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 21 deletions.
9 changes: 8 additions & 1 deletion db_revisions/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from alembic import op
from sqlalchemy import engine_from_config
from sqlalchemy import MetaData, Table, engine_from_config
import sqlalchemy


Expand All @@ -11,3 +11,10 @@ def table_exists(table_name):
inspector = sqlalchemy.inspect(engine)
tables = inspector.get_table_names()
return table_name in tables


def get_table_by_name(table_name):
meta = MetaData()
meta.reflect(op.get_bind())
table = Table(table_name, meta)
return table
17 changes: 12 additions & 5 deletions db_revisions/versions/26a742d97ad9_seed_federal_regulator_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from typing import Sequence, Union
from alembic import op
from entities.models.dao import Base
from sqlalchemy import MetaData, Table


# revision identifiers, used by Alembic.
Expand All @@ -16,8 +16,6 @@
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:
seed_data = [
Expand All @@ -29,8 +27,17 @@ def upgrade() -> None:
{"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)

meta = MetaData()
meta.reflect(op.get_bind())
table = Table("federal_regulator", meta)

op.bulk_insert(table, seed_data)


def downgrade() -> None:
op.execute(federal_regulator_table.delete())
meta = MetaData()
meta.reflect(op.get_bind())
table = Table("federal_regulator", meta)

op.execute(table.delete())
16 changes: 11 additions & 5 deletions db_revisions/versions/7b6ff51002b5_seed_address_state_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from typing import Sequence, Union
from alembic import op
from entities.models.dao import Base
from sqlalchemy import MetaData, Table


# revision identifiers, used by Alembic.
Expand All @@ -16,8 +16,6 @@
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:
seed_data = [
Expand Down Expand Up @@ -80,8 +78,16 @@ def upgrade() -> None:
{"code": "VI", "name": "Virgin Islands, U.S."},
]

op.bulk_insert(address_state_table, seed_data)
meta = MetaData()
meta.reflect(op.get_bind())
table = Table("address_state", meta)

op.bulk_insert(table, seed_data)


def downgrade() -> None:
op.execute(address_state_table.delete())
meta = MetaData()
meta.reflect(op.get_bind())
table = Table("address_state", meta)

op.execute(table.delete())
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
"""
from typing import Sequence, Union
from alembic import op
from entities.models.dao import Base
from sqlalchemy import MetaData, Table

# 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:
seed_data = [
Expand All @@ -34,8 +32,17 @@ def upgrade() -> None:
{"id": "12", "name": "Online lender."},
{"id": "13", "name": "Other"},
]
op.bulk_insert(sbl_institution_type_table, seed_data)

meta = MetaData()
meta.reflect(op.get_bind())
table = Table("sbl_institution_type", meta)

op.bulk_insert(table, seed_data)


def downgrade() -> None:
op.execute(sbl_institution_type_table.delete())
meta = MetaData()
meta.reflect(op.get_bind())
table = Table("sbl_institution_type", meta)

op.execute(table.delete())
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from typing import Sequence, Union
from alembic import op
from entities.models.dao import Base
from sqlalchemy import MetaData, Table


# revision identifiers, used by Alembic.
Expand All @@ -16,8 +16,6 @@
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:
seed_data = [
Expand All @@ -40,8 +38,16 @@ def upgrade() -> None:
{"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)
meta = MetaData()
meta.reflect(op.get_bind())
table = Table("hmda_institution_type", meta)

op.bulk_insert(table, seed_data)


def downgrade() -> None:
op.execute(hmda_institution_type_table.delete())
meta = MetaData()
meta.reflect(op.get_bind())
table = Table("hmda_institution_type", meta)

op.execute(table.delete())

0 comments on commit 4fd0d11

Please sign in to comment.