Реализовать лабораторную 3 на оценку 5 (трек 1)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""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())
|
||||
Reference in New Issue
Block a user