Skip to content

Commit

Permalink
fix alembic migration scripts and tests, add additional custom test
Browse files Browse the repository at this point in the history
  • Loading branch information
lchen-2101 committed Nov 24, 2023
1 parent de058eb commit 6be4f36
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 36 deletions.
16 changes: 8 additions & 8 deletions db_revisions/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
fileConfig(config.config_file_name, disable_existing_loggers=False)

# this specific to SBL configuration

Expand Down Expand Up @@ -82,18 +82,18 @@ def run_migrations_online() -> None:

if connectable is None:
connectable = engine_from_config(
context.config.get_section(context.config.config_ini_section),
context.config.get_section(context.config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)

with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata, version_table_schema=target_metadata.schema
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata, version_table_schema=target_metadata.schema
)

with context.begin_transaction():
context.run_migrations()
with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
Expand Down
8 changes: 5 additions & 3 deletions db_revisions/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from alembic import op
from sqlalchemy import engine_from_config
from sqlalchemy.engine import reflection
import sqlalchemy


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)
engine = config.attributes.get("connection", None)
if engine is None:
engine = engine_from_config(config.get_section(config.config_ini_section), prefix="sqlalchemy.")
inspector = sqlalchemy.inspect(engine)
tables = inspector.get_table_names()
return table_name in tables
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def upgrade() -> None:
"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.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False),
sa.ForeignKeyConstraint(
["lei"],
["financial_institutions.lei"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def upgrade() -> None:
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.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False),
sa.PrimaryKeyConstraint("domain"),
)
op.create_index(op.f("ix_denied_domains_domain"), "denied_domains", ["domain"], unique=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def upgrade() -> None:
"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.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False),
sa.PrimaryKeyConstraint("lei"),
)
op.create_index(op.f("ix_financial_institutions_lei"), "financial_institutions", ["lei"], unique=True)
Expand Down
Loading

0 comments on commit 6be4f36

Please sign in to comment.