From 87c31fc3c7f3fc525b89cde0b67c50c19dca9bbc Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Sun, 1 Feb 2026 15:31:04 +0100 Subject: [PATCH] Update datamodel upgrade logic for browser extension to fix pragma conflicts --- .../src/entrypoints/popup/pages/auth/Upgrade.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Upgrade.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Upgrade.tsx index 9ad1895db..2d58febac 100644 --- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Upgrade.tsx +++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Upgrade.tsx @@ -131,12 +131,14 @@ const Upgrade: React.FC = () => { return; } - // Use the useVaultMutate hook to handle the upgrade and vault upload + /** + * Use the useVaultMutate hook to handle the upgrade and vault upload. + * IMPORTANT: Do NOT wrap migration SQL in beginTransaction/commitTransaction! + * The migration SQL contains PRAGMA foreign_keys statements that MUST be executed + * outside of any transaction to take effect. The SQL handles its own transactions. + */ await executeVaultMutationAsync(async () => { - // Begin transaction - sqliteClient.beginTransaction(); - - // Execute each SQL command + // Execute each SQL command (each migration script handles its own transactions) for (let i = 0; i < upgradeResult.sqlCommands.length; i++) { const sqlCommand = upgradeResult.sqlCommands[i]; @@ -144,13 +146,9 @@ const Upgrade: React.FC = () => { sqliteClient.executeRaw(sqlCommand); } catch (error) { console.error(`Error executing SQL command ${i + 1}:`, sqlCommand, error); - sqliteClient.rollbackTransaction(); throw new Error(t('upgrade.alerts.failedToApplyMigration', { current: i + 1, total: upgradeResult.sqlCommands.length })); } } - - // Commit transaction - sqliteClient.commitTransaction(); }); await handleUpgradeSuccess();