Skip to content

Commit

Permalink
chore: Logs the duration of migrations execution (#29893)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Aug 9, 2024
1 parent 222c46f commit 57a4199
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion superset/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import logging
import time
import urllib.parse
from logging.config import fileConfig

Expand Down Expand Up @@ -54,6 +54,13 @@
# ... etc.


def print_duration(start_time: float) -> None:
logger.info(
"Migration scripts completed. Duration: %s",
time.strftime("%H:%M:%S", time.gmtime(time.time() - start_time)),
)


def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
Expand All @@ -66,11 +73,15 @@ def run_migrations_offline() -> None:
script output.
"""
start_time = time.time()
logger.info("Starting the migration scripts.")

url = config.get_main_option("sqlalchemy.url")
context.configure(url=url)

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


def run_migrations_online() -> None:
Expand All @@ -81,6 +92,9 @@ def run_migrations_online() -> None:
"""

start_time = time.time()
logger.info("Starting the migration scripts.")

# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: https://alembic.sqlalchemy.org/en/latest/cookbook.html
Expand Down Expand Up @@ -117,6 +131,7 @@ def process_revision_directives( # pylint: disable=redefined-outer-name, unused
try:
with context.begin_transaction():
context.run_migrations()
print_duration(start_time)
finally:
connection.close()

Expand Down

0 comments on commit 57a4199

Please sign in to comment.