Migrationen versioniert: migrations.py mit PRAGMA user_version
- db.py enthält nur noch Schema (neuester Stand), Verbindungen und Start - Neue Datenbank: direkt im neuesten Schema, erste Liste "Zuhause", Version = Anzahl der Schritte - Bestehende Datenbank: nur fehlende Schritte, jeder genau einmal - Bisherige Einzel-Umstellungen als Schritt 1 "Altbestand" (prüfen weiter selbst, was nötig ist); künftige Schritte werden einfach angehängt - Tests für Versionsnummer und "Schritt läuft nur einmal" Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79cbaab092
commit
d28e6b2e4b
4 files changed
+214
-154
No files matched your search
@@ -136,3 +136,25 @@ def test_geloeschte_listen_kommen_nicht_zurueck(conn):
|
||||
conn.execute("DELETE FROM shopping_lists")
|
||||
db.init()
|
||||
assert conn.execute("SELECT COUNT(*) FROM shopping_lists").fetchone()[0] == 0
|
||||
|
||||
|
||||
def test_neue_datenbank_hat_neueste_version(conn):
|
||||
from app import migrations
|
||||
assert conn.execute("PRAGMA user_version").fetchone()[0] == len(migrations.STEPS)
|
||||
|
||||
|
||||
def test_alte_datenbank_bekommt_neueste_version(old_db):
|
||||
from app import migrations
|
||||
conn = old_db(HAUSHALT_OHNE_LISTEN)
|
||||
assert conn.execute("PRAGMA user_version").fetchone()[0] == len(migrations.STEPS)
|
||||
|
||||
|
||||
def test_schritt_laeuft_nur_einmal(old_db, monkeypatch):
|
||||
from app import migrations
|
||||
calls = []
|
||||
conn = old_db(HAUSHALT_OHNE_LISTEN)
|
||||
monkeypatch.setattr(migrations, "STEPS", [*migrations.STEPS, lambda c: calls.append(1)])
|
||||
db.init()
|
||||
db.init()
|
||||
assert calls == [1]
|
||||
assert conn.execute("PRAGMA user_version").fetchone()[0] == len(migrations.STEPS)
|
||||
Reference in new issue
Block a user