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)
This commit is contained in:
L1nSn0w
2026-02-13 12:57:14 +08:00
parent afdd5b6c86
commit 6032c598b0

View File

@@ -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")