Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix alembic migration scripts and tests, add additional custom test #52

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading