-
Notifications
You must be signed in to change notification settings - Fork 2
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
Nov 2, 2023
1 parent
c145f8b
commit 02f731f
Showing
8 changed files
with
128 additions
and
75 deletions.
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
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,11 @@ | ||
from alembic import op | ||
from sqlalchemy import engine_from_config | ||
from sqlalchemy.engine import reflection | ||
|
||
|
||
def table_exists(table_name): | ||
config = op.get_context().config | ||
engine = engine_from_config(config.get_section(config.config_ini_section), prefix="sqlalchemy.") | ||
inspector = reflection.Inspector.from_engine(engine) | ||
tables = inspector.get_table_names() | ||
return table_name in tables |
44 changes: 44 additions & 0 deletions
44
db_revisions/versions/20e0d51d8be9_create_financial_institution_domains_.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,44 @@ | ||
"""Create financial_institution_domains table | ||
Revision ID: 20e0d51d8be9 | ||
Revises: f76c5004993f | ||
Create Date: 2023-11-02 11:37:52.487064 | ||
""" | ||
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 = "20e0d51d8be9" | ||
down_revision: Union[str, None] = "f76c5004993f" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
# depends_on: Union[str, Sequence[str], None] = None | ||
depends_on = ["f76c5004993f"] | ||
|
||
|
||
def upgrade() -> None: | ||
if not table_exists("financial_institution_domains"): | ||
op.create_table( | ||
"financial_institution_domains", | ||
sa.Column("domain", sa.String(), nullable=False), | ||
sa.Column("lei", sa.String(), nullable=False), | ||
sa.Column("event_time", sa.DateTime(), server_default=sa.text("now()"), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["lei"], | ||
["financial_institutions.lei"], | ||
), | ||
sa.PrimaryKeyConstraint("domain", "lei"), | ||
) | ||
op.create_index( | ||
op.f("ix_financial_institution_domains_domain"), "financial_institution_domains", ["domain"], unique=False | ||
) | ||
op.create_index( | ||
op.f("ix_financial_institution_domains_lei"), "financial_institution_domains", ["lei"], unique=False | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("financial_institution_domains") |
34 changes: 34 additions & 0 deletions
34
db_revisions/versions/a98b11074c54_create_denied_domains_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,34 @@ | ||
"""Create denied_domains table | ||
Revision ID: a98b11074c54 | ||
Revises: | ||
Create Date: 2023-11-02 11:31:54.882727 | ||
""" | ||
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 = "a98b11074c54" | ||
down_revision: Union[str, None] = None | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
if not table_exists("denied_domains"): | ||
op.create_table( | ||
"denied_domains", | ||
sa.Column("domain", sa.String(), nullable=False), | ||
sa.Column("event_time", sa.DateTime(), server_default=sa.text("now()"), nullable=False), | ||
sa.PrimaryKeyConstraint("domain"), | ||
) | ||
op.create_index(op.f("ix_denied_domains_domain"), "denied_domains", ["domain"], unique=False) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("denied_domains") |
60 changes: 0 additions & 60 deletions
60
db_revisions/versions/aa098560725b_create_a_baseline_migration.py
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
db_revisions/versions/f76c5004993f_create_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,36 @@ | ||
"""Create financial_institutions table | ||
Revision ID: f76c5004993f | ||
Revises: a98b11074c54 | ||
Create Date: 2023-11-02 11:34:43.808166 | ||
""" | ||
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 = "f76c5004993f" | ||
down_revision: Union[str, None] = "a98b11074c54" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
if not table_exists("financial_institutions"): | ||
op.create_table( | ||
"financial_institutions", | ||
sa.Column("lei", sa.String(), nullable=False), | ||
sa.Column("name", sa.String(), nullable=False), | ||
sa.Column("event_time", sa.DateTime(), server_default=sa.text("now()"), nullable=False), | ||
sa.PrimaryKeyConstraint("lei"), | ||
) | ||
op.create_index(op.f("ix_financial_institutions_lei"), "financial_institutions", ["lei"], unique=True) | ||
op.create_index(op.f("ix_financial_institutions_name"), "financial_institutions", ["name"], unique=False) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("financial_institutions") |
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
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