🔧 Migration base v2: colonnes created_at/last_seen_at absentes des bases tres anciennes
This commit is contained in:
1 parent
6191b32bf7
commit
c793411595
2 files changed
+79
-4
No files matched your search
@@ -42,7 +42,10 @@ def test_db_migration_from_legacy_schema(tmp_path) -> None:
|
||||
|
||||
applied = run_db_migrations(engine)
|
||||
|
||||
assert applied == ["iso_movies: colonnes de suivi des conversions"]
|
||||
assert applied == [
|
||||
"iso_movies: colonnes de suivi des conversions",
|
||||
"iso_movies: colonnes created_at/last_seen_at sur les bases anciennes",
|
||||
]
|
||||
columns = {col["name"] for col in inspect(engine).get_columns("iso_movies")}
|
||||
assert {
|
||||
"processed_at",
|
||||
@@ -51,6 +54,7 @@ def test_db_migration_from_legacy_schema(tmp_path) -> None:
|
||||
"last_error",
|
||||
"poster_url",
|
||||
"radarr_linked",
|
||||
"created_at",
|
||||
} <= columns
|
||||
|
||||
# Les donnees existantes sont conservees.
|
||||
@@ -58,10 +62,10 @@ def test_db_migration_from_legacy_schema(tmp_path) -> None:
|
||||
rows = list(conn.execute(text("SELECT title, radarr_linked FROM iso_movies")))
|
||||
assert rows == [("ISO Movie", 1)]
|
||||
|
||||
# La version est tracee et la migration n'est pas rejouee.
|
||||
# Les versions sont tracees et les migrations ne sont pas rejouees.
|
||||
with engine.connect() as conn:
|
||||
recorded = list(conn.execute(text("SELECT version FROM schema_migrations")))
|
||||
assert [row[0] for row in recorded] == [1]
|
||||
assert [row[0] for row in recorded] == [1, 2]
|
||||
assert run_db_migrations(engine) == []
|
||||
|
||||
|
||||
@@ -73,7 +77,10 @@ def test_db_migration_fresh_database(tmp_path) -> None:
|
||||
|
||||
applied = run_db_migrations(engine)
|
||||
|
||||
assert applied == ["iso_movies: colonnes de suivi des conversions"]
|
||||
assert applied == [
|
||||
"iso_movies: colonnes de suivi des conversions",
|
||||
"iso_movies: colonnes created_at/last_seen_at sur les bases anciennes",
|
||||
]
|
||||
assert run_db_migrations(engine) == []
|
||||
|
||||
|
||||
@@ -136,3 +143,47 @@ def test_appconfig_version_matches_registry(monkeypatch) -> None:
|
||||
migrations conf.json."""
|
||||
monkeypatch.setattr("app.migrations.CONF_MIGRATIONS", CONF_MIGRATIONS)
|
||||
assert AppConfig().version == current_conf_version()
|
||||
|
||||
|
||||
def test_db_migration_adds_created_at_on_very_old_database(tmp_path) -> None:
|
||||
"""Une base d'epoque, sans created_at/last_seen_at, est reparee par la
|
||||
migration v2 et redevient utilisable par l'application."""
|
||||
from sqlalchemy import create_engine, inspect, text
|
||||
|
||||
from app.database import Base
|
||||
from app.migrations import run_db_migrations
|
||||
|
||||
engine = create_engine(f"sqlite:///{tmp_path / 'old.db'}")
|
||||
with engine.begin() as conn:
|
||||
conn.execute(
|
||||
text(
|
||||
"""
|
||||
CREATE TABLE iso_movies (
|
||||
id INTEGER PRIMARY KEY,
|
||||
radarr_movie_id INTEGER,
|
||||
radarr_movie_file_id INTEGER,
|
||||
title TEXT,
|
||||
year INTEGER,
|
||||
path TEXT,
|
||||
size INTEGER,
|
||||
status TEXT
|
||||
)
|
||||
"""
|
||||
)
|
||||
)
|
||||
conn.execute(
|
||||
text(
|
||||
"INSERT INTO iso_movies (radarr_movie_id, radarr_movie_file_id,"
|
||||
" title, status) VALUES (1, 2, 'Vieux Film', 'detected')"
|
||||
)
|
||||
)
|
||||
|
||||
run_db_migrations(engine)
|
||||
|
||||
columns = {col["name"] for col in inspect(engine).get_columns("iso_movies")}
|
||||
assert {"created_at", "last_seen_at", "radarr_linked", "last_error"} <= columns
|
||||
with engine.connect() as conn:
|
||||
rows = list(conn.execute(text("SELECT title, status FROM iso_movies")))
|
||||
assert rows == [("Vieux Film", "detected")]
|
||||
# La table est conforme au modele: create_all ne change rien.
|
||||
Base.metadata.create_all(bind=engine)
|
||||
Reference in new issue
Block a user