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 all commits
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
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

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,13 @@
# ... etc.


def print_duration(start_time: float) -> None:
logger.info(

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

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L57-L58

Added lines #L57 - L58 were not covered by tests
"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 @@
script output.

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

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

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L76-L77

Added lines #L76 - L77 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 84 in superset/migrations/env.py

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L84

Added line #L84 was not covered by tests


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

"""

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

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

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L95-L96

Added lines #L95 - L96 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 +131,7 @@
try:
with context.begin_transaction():
context.run_migrations()
print_duration(start_time)

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

View check run for this annotation

Codecov / codecov/patch

superset/migrations/env.py#L134

Added line #L134 was not covered by tests
finally:
connection.close()

Expand Down
Loading