forked from mtusi2026/mtusi2026lab3
25 lines
584 B
Python
25 lines
584 B
Python
"""Run database migrations as a dedicated deployment step."""
|
|
import asyncio
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from . import db
|
|
|
|
|
|
def read_secret(name: str, fallback: str) -> str:
|
|
path = os.environ.get(name)
|
|
if path:
|
|
return Path(path).read_text(encoding="utf-8").strip()
|
|
value = os.environ.get(fallback)
|
|
if not value:
|
|
raise RuntimeError(f"{name} or {fallback} is required")
|
|
return value
|
|
|
|
|
|
async def main() -> None:
|
|
await db.run_migrations(read_secret("DATABASE_URL_FILE", "DATABASE_URL"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|