From 71ad4dd1ca26178e5272f7d437d12775b11b1f0d Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Fri, 10 Jul 2026 15:19:58 +0200 Subject: [PATCH] =?UTF-8?q?fix(mcp):=20apply=5Fpending=20tol=C3=A8re=20l'a?= =?UTF-8?q?bsence=20de=20api=5Ftokens=20(migration=200007,=20scope=20B=20#?= =?UTF-8?q?111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/migrations.py | 10 ++++++++-- tests/api/test_migrations.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/migrations.py b/src/migrations.py index 3afa102..71c08e8 100644 --- a/src/migrations.py +++ b/src/migrations.py @@ -66,9 +66,15 @@ def apply_pending() -> None: except sqlite3.OperationalError as exc: # Sur une DB fraîche (schéma déjà à jour), certaines migrations # 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) - 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 conn.execute( "INSERT INTO schema_migrations (id, applied_at) VALUES (?, ?)", diff --git a/tests/api/test_migrations.py b/tests/api/test_migrations.py index a28eae7..5b5a84b 100644 --- a/tests/api/test_migrations.py +++ b/tests/api/test_migrations.py @@ -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 migrations.apply_pending() 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()