Skip to content

Commit

Permalink
refactor: print elapsed time for db migration (#5610)
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHYang authored Dec 4, 2024
1 parent bab7b39 commit bc64f95
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/phoenix/db/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from queue import Empty, SimpleQueue
from threading import Thread
from time import perf_counter
from typing import Optional

from alembic import command
Expand Down Expand Up @@ -47,12 +48,14 @@ def migrate(
alembic_cfg.set_main_option("script_location", scripts_location)
url = str(engine.url).replace("%", "%%")
alembic_cfg.set_main_option("sqlalchemy.url", url)
start_time = perf_counter()
with engine.connect() as conn:
alembic_cfg.attributes["connection"] = conn
command.upgrade(alembic_cfg, "head")
elapsed_time = perf_counter() - start_time
engine.dispose()
printif(log_migrations, "---------------------------")
printif(log_migrations, "✅ Migrations complete.")
printif(log_migrations, f"✅ Migrations completed in {elapsed_time:.3f} seconds.")
except BaseException as e:
if error_queue:
error_queue.put(e)
Expand Down

0 comments on commit bc64f95

Please sign in to comment.