Skip to content

Commit

Permalink
Removed the table_exists condition from updating financial institutio…
Browse files Browse the repository at this point in the history
…n alembic script
  • Loading branch information
Nargis Sultani committed Dec 8, 2023
1 parent 2957ad6 commit 8ab4c6e
Showing 1 changed file with 60 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from alembic import op
import sqlalchemy as sa


from db_revisions.utils import table_exists


# revision identifiers, used by Alembic.
revision: str = "045aa502e050"
down_revision: Union[str, None] = "549c612bf1c9"
Expand All @@ -22,72 +18,71 @@


def upgrade() -> None:
if table_exists("financial_institutions"):
op.add_column("financial_institutions", sa.Column("tax_id", sa.String(length=9), nullable=True))
op.add_column("financial_institutions", sa.Column("rssd_id", sa.Integer(), nullable=True))
op.create_unique_constraint("unique_association", "financial_institutions", ["tax_id", "rssd_id"])
op.add_column(
"financial_institutions", sa.Column("primary_federal_regulator_id", sa.String(length=4), nullable=True)
)
op.add_column("financial_institutions", sa.Column("hmda_institution_type_id", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("sbl_institution_type_id", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("hq_address_street_1", sa.String(), nullable=False))
op.add_column("financial_institutions", sa.Column("hq_address_street_2", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("hq_address_city", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("hq_address_state", sa.String(length=2), nullable=True))
op.add_column("financial_institutions", sa.Column("hq_address_zip", sa.String(length=5), nullable=False))
op.add_column("financial_institutions", sa.Column("parent_lei", sa.String(length=20), nullable=True))
op.add_column("financial_institutions", sa.Column("parent_legal_name", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("parent_rssd_id", sa.Integer(), nullable=True))
op.add_column("financial_institutions", sa.Column("top_holder_lei", sa.String(length=20), nullable=True))
op.add_column("financial_institutions", sa.Column("top_holder_legal_name", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("top_holder_rssd_id", sa.Integer(), nullable=True))
op.create_index(
op.f("ix_financial_institutions_hmda_institution_type_id"),
"financial_institutions",
["hmda_institution_type_id"],
unique=False,
op.add_column("financial_institutions", sa.Column("tax_id", sa.String(length=9), nullable=True))
op.add_column("financial_institutions", sa.Column("rssd_id", sa.Integer(), nullable=True))
op.create_unique_constraint("unique_association", "financial_institutions", ["tax_id", "rssd_id"])
op.add_column(
"financial_institutions", sa.Column("primary_federal_regulator_id", sa.String(length=4), nullable=True)
)
op.add_column("financial_institutions", sa.Column("hmda_institution_type_id", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("sbl_institution_type_id", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("hq_address_street_1", sa.String(), nullable=False))
op.add_column("financial_institutions", sa.Column("hq_address_street_2", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("hq_address_city", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("hq_address_state", sa.String(length=2), nullable=True))
op.add_column("financial_institutions", sa.Column("hq_address_zip", sa.String(length=5), nullable=False))
op.add_column("financial_institutions", sa.Column("parent_lei", sa.String(length=20), nullable=True))
op.add_column("financial_institutions", sa.Column("parent_legal_name", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("parent_rssd_id", sa.Integer(), nullable=True))
op.add_column("financial_institutions", sa.Column("top_holder_lei", sa.String(length=20), nullable=True))
op.add_column("financial_institutions", sa.Column("top_holder_legal_name", sa.String(), nullable=True))
op.add_column("financial_institutions", sa.Column("top_holder_rssd_id", sa.Integer(), nullable=True))
op.create_index(
op.f("ix_financial_institutions_hmda_institution_type_id"),
"financial_institutions",
["hmda_institution_type_id"],
unique=False,
)
op.create_index(
op.f("ix_financial_institutions_hq_address_state"),
"financial_institutions",
["hq_address_state"],
unique=False,
)
op.create_index(
op.f("ix_financial_institutions_primary_federal_regulator_id"),
"financial_institutions",
["primary_federal_regulator_id"],
unique=False,
)
op.create_index(
op.f("ix_financial_institutions_sbl_institution_type_id"),
"financial_institutions",
["sbl_institution_type_id"],
unique=False,
)
with op.batch_alter_table("financial_institutions") as batch_op:
batch_op.create_foreign_key(
"fk_federal_regulator_financial_institutions",
"federal_regulator",
["primary_federal_regulator_id"],
["id"],
)
op.create_index(
op.f("ix_financial_institutions_hq_address_state"),
"financial_institutions",
["hq_address_state"],
unique=False,
batch_op.create_foreign_key(
"fk_address_state_financial_institutions", "address_state", ["hq_address_state"], ["code"]
)
op.create_index(
op.f("ix_financial_institutions_primary_federal_regulator_id"),
"financial_institutions",
["primary_federal_regulator_id"],
unique=False,
batch_op.create_foreign_key(
"fk_hmda_institution_type_financial_institutions",
"hmda_institution_type",
["hmda_institution_type_id"],
["id"],
)
op.create_index(
op.f("ix_financial_institutions_sbl_institution_type_id"),
"financial_institutions",
batch_op.create_foreign_key(
"fk_sbl_institution_type_financial_institutions",
"sbl_institution_type",
["sbl_institution_type_id"],
unique=False,
["id"],
)
with op.batch_alter_table("financial_institutions") as batch_op:
batch_op.create_foreign_key(
"fk_federal_regulator_financial_institutions",
"federal_regulator",
["primary_federal_regulator_id"],
["id"],
)
batch_op.create_foreign_key(
"fk_address_state_financial_institutions", "address_state", ["hq_address_state"], ["code"]
)
batch_op.create_foreign_key(
"fk_hmda_institution_type_financial_institutions",
"hmda_institution_type",
["hmda_institution_type_id"],
["id"],
)
batch_op.create_foreign_key(
"fk_sbl_institution_type_financial_institutions",
"sbl_institution_type",
["sbl_institution_type_id"],
["id"],
)


def downgrade() -> None:
Expand Down

0 comments on commit 8ab4c6e

Please sign in to comment.