From faefaa79663de70623ea28d220a909fc624aba66 Mon Sep 17 00:00:00 2001 From: pablo Date: Mon, 18 Aug 2025 16:40:58 +0300 Subject: [PATCH] fix: pr comment --- chat_sdk/migration.nim | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/chat_sdk/migration.nim b/chat_sdk/migration.nim index 45ea614..a23f740 100644 --- a/chat_sdk/migration.nim +++ b/chat_sdk/migration.nim @@ -32,10 +32,15 @@ proc runMigrations*(db: DbConn, dir = "migrations") = else: info "Applying migration", file let sqlContent = readFile(file) - # Split by semicolon and execute each statement separately - let statements = sqlContent.split(';') - for stmt in statements: - let trimmedStmt = stmt.strip() - if trimmedStmt.len > 0: - db.exec(sql(trimmedStmt)) - markMigrationRun(db, file) + db.exec(sql"BEGIN TRANSACTION") + try: + # Split by semicolon and execute each statement separately + for stmt in sqlContent.split(';'): + let trimmedStmt = stmt.strip() + if trimmedStmt.len > 0: + db.exec(sql(trimmedStmt)) + markMigrationRun(db, file) + db.exec(sql"COMMIT") + except: + db.exec(sql"ROLLBACK") + raise newException(ValueError, "Migration failed: " & file & " - " & getCurrentExceptionMsg())