✨ Migrations versionnees de la base et de conf.json (schema_migrations + cle version)
This commit is contained in:
1 parent
3a75527135
commit
c7344f8988
5 files changed
+325
-28
No files matched your search
+10
-21
@@ -10,7 +10,7 @@ import httpx
|
||||
from fastapi import Cookie, Depends, FastAPI, HTTPException, Response
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse
|
||||
from sqlalchemy import inspect, select, text, update
|
||||
from sqlalchemy import select, update
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app import auth
|
||||
@@ -27,6 +27,7 @@ from app.conf_store import (
|
||||
)
|
||||
from app.converter import cancel_conversion, conversion_paths, finalize_validation
|
||||
from app.database import Base, engine, get_db
|
||||
from app.migrations import migrate_conf_file, run_db_migrations
|
||||
from app.models import IsoMovie
|
||||
from app.qbittorrent import QbittorrentClient, match_torrent
|
||||
from app.radarr import RadarrClient, movie_file_path
|
||||
@@ -53,26 +54,14 @@ from app.worker import conversion_worker
|
||||
async def lifespan(_: FastAPI):
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
# Very small "migration" helper for dev: add new columns if the SQLite DB already exists.
|
||||
# (SQLAlchemy create_all doesn't alter existing tables.)
|
||||
try:
|
||||
inspector = inspect(engine)
|
||||
columns = {col["name"] for col in inspector.get_columns("iso_movies")}
|
||||
migrations = {
|
||||
"processed_at": "DATETIME",
|
||||
"completed_at": "DATETIME",
|
||||
"failed_step": "TEXT",
|
||||
"last_error": "TEXT",
|
||||
"poster_url": "TEXT",
|
||||
"radarr_linked": "BOOLEAN DEFAULT 1",
|
||||
}
|
||||
with engine.begin() as conn:
|
||||
for column, ddl in migrations.items():
|
||||
if column not in columns:
|
||||
conn.execute(text(f"ALTER TABLE iso_movies ADD COLUMN {column} {ddl}"))
|
||||
except Exception:
|
||||
# Don't fail app startup for a best-effort migration.
|
||||
pass
|
||||
# Migrations versionnees (base + conf.json), tracees au demarrage.
|
||||
db_applied = run_db_migrations(engine)
|
||||
if db_applied:
|
||||
print(f"migrations de base appliquees: {', '.join(db_applied)}", flush=True)
|
||||
conf_applied = migrate_conf_file()
|
||||
if conf_applied:
|
||||
print(f"migrations conf.json: {', '.join(conf_applied)}", flush=True)
|
||||
|
||||
auth.bootstrap_setup()
|
||||
_log_config_summary()
|
||||
worker_task = asyncio.create_task(conversion_worker())
|
||||
|
||||
Reference in new issue
Block a user