API, Postgres, Redis и HAProxy остаются базой для вложений: сессии и история уже общие для нескольких реплик.
30 lines
640 B
Python
30 lines
640 B
Python
"""One-shot schema apply. API replicas do not run this on startup."""
|
|
import asyncio
|
|
import logging
|
|
import sys
|
|
|
|
from app import config, db
|
|
|
|
|
|
async def _main() -> None:
|
|
if not config.DATABASE_URL:
|
|
raise SystemExit("DATABASE_URL is not set")
|
|
await db.connect()
|
|
try:
|
|
await db.apply_migrations()
|
|
finally:
|
|
await db.close()
|
|
|
|
|
|
def main() -> None:
|
|
logging.basicConfig(
|
|
level=getattr(logging, config.LOG_LEVEL.upper(), logging.INFO),
|
|
format="%(asctime)s %(levelname)s %(name)s %(message)s",
|
|
stream=sys.stdout,
|
|
)
|
|
asyncio.run(_main())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|