Реализовать лабораторную 4 на оценку 5
Добавить приватное S3-хранилище, вложения, presigned upload, reconciler и доказательства.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""One-shot schema migrator.
|
||||
|
||||
Run as ``python -m app.migrate`` from the dedicated Compose service. It waits
|
||||
for PostgreSQL, takes the application advisory lock and applies only missing
|
||||
migration files. Exiting non-zero blocks API replicas via
|
||||
``depends_on: service_completed_successfully``.
|
||||
"""
|
||||
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")
|
||||
log = logging.getLogger("messenger.migrate")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
log.info("waiting for PostgreSQL and applying migrations")
|
||||
db.open_pool(timeout=60.0)
|
||||
applied = db.apply_migrations()
|
||||
if applied:
|
||||
log.info("applied migrations: %s", ", ".join(applied))
|
||||
else:
|
||||
log.info("schema already current at %s", db.required_version())
|
||||
with db.pool().connection() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT version, applied_at FROM schema_migrations ORDER BY version"
|
||||
).fetchall()
|
||||
for row in rows:
|
||||
log.info("schema version %s applied at %s", row["version"], row["applied_at"].isoformat())
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user