From 6032c598b0bef1ab8051834eaacc1ae2f8ff2312 Mon Sep 17 00:00:00 2001 From: L1nSn0w Date: Fri, 13 Feb 2026 12:57:14 +0800 Subject: [PATCH] fix(api): improve logging for database migration lock release - Added a migration_succeeded flag to track the success of database migrations. - Enhanced logging messages to indicate the status of the migration when releasing the lock, providing clearer context for potential issues. (cherry picked from commit e74be0392995d16d288eed2175c51148c9e5b9c0) --- api/commands.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/api/commands.py b/api/commands.py index 4cc2f476f2..ada2099058 100644 --- a/api/commands.py +++ b/api/commands.py @@ -773,6 +773,7 @@ def upgrade_db(): daemon=True, ) heartbeat_thread.start() + migration_succeeded = False try: click.echo(click.style("Starting database migration.", fg="green")) @@ -781,6 +782,7 @@ def upgrade_db(): flask_migrate.upgrade() + migration_succeeded = True click.echo(click.style("Database migration successful!", fg="green")) except Exception as e: @@ -794,9 +796,15 @@ def upgrade_db(): try: lock.release() except LockNotOwnedError: - logger.warning("DB migration lock not owned on release (likely expired); ignoring.") + status = "successful" if migration_succeeded else "failed" + logger.warning("DB migration lock not owned on release after %s migration (likely expired); ignoring.", status) except RedisError: - logger.warning("Failed to release DB migration lock due to Redis error; ignoring.", exc_info=True) + status = "successful" if migration_succeeded else "failed" + logger.warning( + "Failed to release DB migration lock due to Redis error after %s migration; ignoring.", + status, + exc_info=True, + ) else: click.echo("Database migration skipped")