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

chore: Logs the duration of migrations execution #29893

Merged
Merged
Changes from 1 commit
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: 15 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

Check warning on line 18 in superset/migrations/env.py

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L18

Added line #L18 was not covered by tests
import urllib.parse
from logging.config import fileConfig

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


def print_duration(start_time: float) -> None:
duration = time.time() - start_time
formatted_time = time.strftime("%H:%M:%S", time.gmtime(duration))
logger.info(f"Migration scripts completed. Duration: {formatted_time}")

Check warning on line 60 in superset/migrations/env.py

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L57-L60

Added lines #L57 - L60 were not covered by tests
giftig marked this conversation as resolved.
Show resolved Hide resolved


def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.

Expand All @@ -66,11 +72,15 @@
script output.

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

Check warning on line 76 in superset/migrations/env.py

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L75-L76

Added lines #L75 - L76 were not covered by tests

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

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

Check warning on line 83 in superset/migrations/env.py

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L83

Added line #L83 was not covered by tests


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

"""

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

Check warning on line 95 in superset/migrations/env.py

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L94-L95

Added lines #L94 - L95 were not covered by tests

# 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 +130,7 @@
try:
with context.begin_transaction():
context.run_migrations()
print_duration(start_time)

Check warning on line 133 in superset/migrations/env.py

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L133

Added line #L133 was not covered by tests
giftig marked this conversation as resolved.
Show resolved Hide resolved
finally:
connection.close()

Expand Down
Loading