Skip to content

Commit

Permalink
debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mzappitello committed Feb 14, 2024
1 parent 90c24cd commit ebfd14b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python_src/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ version_locations = src/lamp_py/migrations/versions/performance_manager_prod
[metadata_dev]
sqlalchemy.url = driver://user:pass@localhost/dbname
script_location = src/lamp_py/migrations
version_locations = src/lamp_py/migrations/versions/metadatad_dev
version_locations = src/lamp_py/migrations/versions/metadata_dev

[metadata_staging]
sqlalchemy.url = driver://user:pass@localhost/dbname
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
branch_labels = None
depends_on = None

logging.getLogger().setLevel("INFO")

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
logging.info("Starting Migration")
op.create_table(
"metadata_log",
sa.Column("pk_id", sa.Integer(), nullable=False),
Expand All @@ -47,10 +49,12 @@ def upgrade() -> None:
postgresql_where=sa.text("rail_pm_processed = false"),
)

logging.error("Tables and Index Created")
# pull metadata from the rail performance manager database into the
# metadata database. the table may or may not exist, so wrap this in a try
# except
try:
logging.error("Reading Metadata")
rpm_db_manager = DatabaseManager(
db_index=DatabaseIndex.RAIL_PERFORMANCE_MANAGER
)
Expand Down Expand Up @@ -84,13 +88,18 @@ def upgrade() -> None:
and hasattr(original_error, "pgcode")
and original_error.pgcode == "42P01"
):
logging.info("No Metadata Table in Rail Performance Manager")
logging.exception("No Metadata Table in Rail Performance Manager")
else:
logging.exception("Error Reading Metadata Table")
raise

# insert data into the metadata database
if insert_data:
op.bulk_insert(MetadataLog.__table__, insert_data)
try:
logging.error("Inserting Metadata")
# insert data into the metadata database
if insert_data:
op.bulk_insert(MetadataLog.__table__, insert_data)
except Exception as error:
logging.exception("Metadata Insert Failed")

# ### end Alembic commands ###

Expand Down
5 changes: 5 additions & 0 deletions python_src/src/lamp_py/runtime_utils/alembic_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def alembic_upgrade_to_head(db_name: str) -> None:
# load alembic configuation for db_name
alembic_cfg = get_alembic_config(db_name)

# Configure logging to display Alembic logs at the INFO level
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('alembic.runtime.migration')
logger.setLevel(logging.INFO)

command.upgrade(alembic_cfg, revision="head")


Expand Down

0 comments on commit ebfd14b

Please sign in to comment.