fix(mcp): apply_pending tolère l'absence de api_tokens (migration 0007, scope B #111)
This commit is contained in:
+8
-2
@@ -66,9 +66,15 @@ def apply_pending() -> None:
|
|||||||
except sqlite3.OperationalError as exc:
|
except sqlite3.OperationalError as exc:
|
||||||
# Sur une DB fraîche (schéma déjà à jour), certaines migrations
|
# Sur une DB fraîche (schéma déjà à jour), certaines migrations
|
||||||
# sont sans effet : ADD COLUMN → "duplicate column name",
|
# sont sans effet : ADD COLUMN → "duplicate column name",
|
||||||
# RENAME COLUMN → "no such column". On les ignore.
|
# RENAME COLUMN → "no such column", et un ALTER sur une table pas
|
||||||
|
# encore créée → "no such table" (elle sera créée plus tard par
|
||||||
|
# init_schema avec la colonne déjà dans SCHEMA).
|
||||||
err = str(exc)
|
err = str(exc)
|
||||||
if "duplicate column name" not in err and "no such column" not in err:
|
if (
|
||||||
|
"duplicate column name" not in err
|
||||||
|
and "no such column" not in err
|
||||||
|
and "no such table" not in err
|
||||||
|
):
|
||||||
raise
|
raise
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"INSERT INTO schema_migrations (id, applied_at) VALUES (?, ?)",
|
"INSERT INTO schema_migrations (id, applied_at) VALUES (?, ?)",
|
||||||
|
|||||||
@@ -27,3 +27,18 @@ def test_migration_0007_adds_kind_to_legacy_api_tokens(monkeypatch, tmp_path):
|
|||||||
# idempotent : un second passage ne lève pas
|
# idempotent : un second passage ne lève pas
|
||||||
migrations.apply_pending()
|
migrations.apply_pending()
|
||||||
auth_db.reset_conn_for_tests()
|
auth_db.reset_conn_for_tests()
|
||||||
|
|
||||||
|
|
||||||
|
def test_apply_pending_tolerates_missing_api_tokens_table(monkeypatch, tmp_path):
|
||||||
|
from src import migrations
|
||||||
|
from src.auth import db as auth_db
|
||||||
|
from src.subscriptions import db as sub_db
|
||||||
|
|
||||||
|
db_path = tmp_path / "users.test.sqlite"
|
||||||
|
monkeypatch.setenv("USERS_DB_PATH", str(db_path))
|
||||||
|
auth_db.reset_conn_for_tests()
|
||||||
|
auth_db.init_schema()
|
||||||
|
sub_db.init_schema()
|
||||||
|
# api_tokens volontairement NON créée (chemin init_subscriptions sans init_api)
|
||||||
|
migrations.apply_pending() # ne doit pas lever
|
||||||
|
auth_db.reset_conn_for_tests()
|
||||||
|
|||||||
Reference in New Issue
Block a user