-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nargis Sultani
committed
Dec 8, 2023
1 parent
f619a59
commit 2957ad6
Showing
7 changed files
with
275 additions
and
1 deletion.
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
119 changes: 119 additions & 0 deletions
119
db_revisions/versions/045aa502e050_update_financial_institutions_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,119 @@ | ||
"""Update Financial Institutions Table | ||
Revision ID: 045aa502e050 | ||
Revises: "549c612bf1c9" | ||
Create Date: 2023-11-29 11:55:10.328766 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
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" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
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.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"], | ||
) | ||
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: | ||
op.drop_constraint( | ||
constraint_name="fk_federal_regulator_financial_institutions", table_name="financial_institutions" | ||
) | ||
op.drop_constraint(constraint_name="fk_address_state_financial_institutions", table_name="financial_institutions") | ||
op.drop_constraint( | ||
constraint_name="fk_hmda_institution_type_financial_institutions", table_name="financial_institutions" | ||
) | ||
op.drop_constraint( | ||
constraint_name="fk_sbl_institution_type_financial_institutions", table_name="financial_institutions" | ||
) | ||
op.drop_column("financial_institutions", "top_holder_rssd_id") | ||
op.drop_column("financial_institutions", "top_holder_legal_name") | ||
op.drop_column("financial_institutions", "top_holder_lei") | ||
op.drop_column("financial_institutions", "parent_rssd_id") | ||
op.drop_column("financial_institutions", "parent_legal_name") | ||
op.drop_column("financial_institutions", "parent_lei") | ||
op.drop_column("financial_institutions", "hq_address_zip") | ||
op.drop_column("financial_institutions", "hq_address_state") | ||
op.drop_column("financial_institutions", "hq_address_city") | ||
op.drop_column("financial_institutions", "hq_address_street_2") | ||
op.drop_column("financial_institutions", "hq_address_street_1") | ||
op.drop_column("financial_institutions", "sbl_institution_type_id") | ||
op.drop_column("financial_institutions", "hmda_institution_type_id") | ||
op.drop_column("financial_institutions", "primary_federal_regulator_id") | ||
op.drop_column("financial_institutions", "rssd_id") | ||
op.drop_column("financial_institutions", "tax_id") |
37 changes: 37 additions & 0 deletions
37
db_revisions/versions/1f6c33f20a2e_create_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,37 @@ | ||
"""Create Address State Table | ||
Revision ID: 1f6c33f20a2e | ||
Revises: "20e0d51d8be9" | ||
Create Date: 2023-11-29 12:03:41.737864 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
from db_revisions.utils import table_exists | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "1f6c33f20a2e" | ||
down_revision: Union[str, None] = "20e0d51d8be9" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
if not table_exists("address_state"): | ||
op.create_table( | ||
"address_state", | ||
sa.Column("code", sa.String(length=2), nullable=False), | ||
sa.Column("name", sa.String(), nullable=False), | ||
sa.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False), | ||
sa.PrimaryKeyConstraint("code"), | ||
sa.UniqueConstraint("name"), | ||
) | ||
op.create_index(op.f("ix_address_state_code"), "address_state", ["code"], unique=False) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("address_state") |
36 changes: 36 additions & 0 deletions
36
db_revisions/versions/549c612bf1c9_create_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,36 @@ | ||
"""Create Federal Regulator Table | ||
Revision ID: 549c612bf1c9 | ||
Revises: "8b1ba6a3275b" | ||
Create Date: 2023-11-29 12:09:20.012400 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
from db_revisions.utils import table_exists | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "549c612bf1c9" | ||
down_revision: Union[str, None] = "8b1ba6a3275b" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
if not table_exists("federal_regulator"): | ||
op.create_table( | ||
"federal_regulator", | ||
sa.Column("id", sa.String(length=4), nullable=False), | ||
sa.Column("name", sa.String(), nullable=False), | ||
sa.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint("name"), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("federal_regulator") |
37 changes: 37 additions & 0 deletions
37
db_revisions/versions/56ef0b5cd2d4_create_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,37 @@ | ||
"""Create SBL Institution Type Table | ||
Revision ID: 56ef0b5cd2d4 | ||
Revises: "1f6c33f20a2e" | ||
Create Date: 2023-11-29 12:20:05.593826 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
from db_revisions.utils import table_exists | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "56ef0b5cd2d4" | ||
down_revision: Union[str, None] = "1f6c33f20a2e" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
if not table_exists("sbl_institution_type"): | ||
op.create_table( | ||
"sbl_institution_type", | ||
sa.Column("id", sa.String(), nullable=False), | ||
sa.Column("name", sa.String(), nullable=False), | ||
sa.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint("name"), | ||
) | ||
op.create_index(op.f("ix_sbl_institution_type_id"), "sbl_institution_type", ["id"], unique=False) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("sbl_institution_type") |
37 changes: 37 additions & 0 deletions
37
db_revisions/versions/8b1ba6a3275b_create_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,37 @@ | ||
"""Create HMDA Institution Type Table | ||
Revision ID: 8b1ba6a3275b | ||
Revises: "56ef0b5cd2d4" | ||
Create Date: 2023-11-29 12:14:16.694281 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
from db_revisions.utils import table_exists | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "8b1ba6a3275b" | ||
down_revision: Union[str, None] = "56ef0b5cd2d4" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
if not table_exists("hmda_institution_type"): | ||
op.create_table( | ||
"hmda_institution_type", | ||
sa.Column("id", sa.String(), nullable=False), | ||
sa.Column("name", sa.String(), nullable=False), | ||
sa.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint("name"), | ||
) | ||
op.create_index(op.f("ix_hmda_institution_type_id"), "hmda_institution_type", ["id"], unique=False) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("hmda_institution_type") |
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