diff --git a/superset/migrations/env.py b/superset/migrations/env.py index ab9dea78554a8..a92b3a1cb69f0 100755 --- a/superset/migrations/env.py +++ b/superset/migrations/env.py @@ -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 @@ -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. @@ -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: @@ -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 @@ -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()