mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-04-08 00:27:44 -04:00
Update datamodel upgrade logic for browser extension to fix pragma conflicts
This commit is contained in:
committed by
Leendert de Borst
parent
eadcd97121
commit
87c31fc3c7
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user