From 01659cc94919d34770c2a93f2e177628cb17c31e Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 7 Jan 2025 01:19:31 +0100 Subject: [PATCH] Only commit migrations once all performed successfully. --- plomtask/db.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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: -- 2.30.2