From: Christian Heller Date: Tue, 7 Jan 2025 00:19:31 +0000 (+0100) Subject: Only commit migrations once all performed successfully. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7Bprefix%7D%7D/bar%20baz.html?a=commitdiff_plain;h=01659cc94919d34770c2a93f2e177628cb17c31e;p=plomtask Only commit migrations once all performed successfully. --- diff --git a/plomtask/db.py b/plomtask/db.py index e505b0e..2695bda 100644 --- a/plomtask/db.py +++ b/plomtask/db.py @@ -45,12 +45,13 @@ class DatabaseFile: f'Cannot migrate {from_version} to {EXPECTED_DB_VERSION}') migrations = cls._available_migrations() migrations_todo = migrations[from_version+1:] - with sql_connect(path) as conn: + with sql_connect(path, autocommit=False) as conn: for j, filename in enumerate(migrations_todo): with open(f'{MIGRATIONS_DIR}/{filename}', 'r', encoding='utf-8') as f: conn.executescript(f.read()) conn.execute(f'PRAGMA user_version = {from_version + j + 1}') + conn.commit() return cls(path) def _check(self) -> None: