mirror of
https://github.com/Cccc-owo/CheckInApp.git
synced 2026-06-17 05:56:29 +00:00
feat(backend): add automatic DB migrations
Add a lightweight migration runner with schema_migrations tracking, run pending migrations during backend startup before the scheduler, and keep a manual backend-migrate entrypoint. The change also moves the existing lockout and task-thread-ID schema steps into shared migration modules, updates docs, and archives the OpenSpec change.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
运行数据库迁移的脚本。
|
||||
|
||||
使用方法:
|
||||
uv run python -m backend.scripts.run_migrations
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from backend.migrations import MigrationExecutionError, run_pending_migrations
|
||||
from backend.models import init_db
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
try:
|
||||
init_db()
|
||||
result = run_pending_migrations()
|
||||
except MigrationExecutionError as exc:
|
||||
logger.error("❌ 迁移失败: %s", exc)
|
||||
return 1
|
||||
|
||||
logger.info("✅ 迁移完成:applied=%s skipped=%s", len(result.applied), len(result.skipped))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user