forked from mtusi2026/mtusi2026lab3
34 lines
872 B
Python
34 lines
872 B
Python
"""One-shot migration entry point used by Compose.
|
|
|
|
Run after PostgreSQL is healthy and before API replicas start:
|
|
|
|
python -m app.migrate
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import sys
|
|
|
|
from . import db
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s")
|
|
|
|
|
|
def main() -> int:
|
|
try:
|
|
db.pool().open(wait=True, timeout=60)
|
|
db.apply_migrations()
|
|
if not db.schema_is_current():
|
|
raise RuntimeError("schema verification failed after migration")
|
|
except Exception as exc:
|
|
logging.getLogger("messenger.migrate").error("migration failed: %s", type(exc).__name__)
|
|
return 1
|
|
finally:
|
|
db.close_pool()
|
|
logging.getLogger("messenger.migrate").info("migrations applied and verified")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|