You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Add payment_method column to transactions if it doesn't exist
109
116
try{
@@ -128,11 +135,14 @@ export function initializeDatabase(): void {
128
135
129
136
// Ensure we have a usable unique constraint for import_hash (skip duplicates on import)
130
137
try{
138
+
// Drop old global index if it exists
139
+
db.exec('DROP INDEX IF EXISTS idx_transactions_import_hash');
140
+
// Create new profile-scoped unique index
131
141
db.exec(
132
-
"CREATE UNIQUE INDEX IF NOT EXISTS idx_transactions_import_hash ON transactions(import_hash) WHERE import_hash IS NOT NULL AND TRIM(import_hash) != ''"
142
+
"CREATE UNIQUE INDEX IF NOT EXISTS idx_transactions_import_hash_scoped ON transactions(import_hash, profile_id) WHERE import_hash IS NOT NULL AND TRIM(import_hash) != ''"
133
143
);
134
-
}catch{
135
-
// Ignore index creation failures (e.g. on corrupted/unsupported schema)
144
+
}catch(error){
145
+
console.warn('Failed to update import_hash index (might be expected):',error);
136
146
}
137
147
138
148
// Backfill missing import_hash values so older data also dedupes correctly
@@ -312,12 +322,71 @@ export function initializeDatabase(): void {
312
322
// MAJOR MIGRATION: Consolidate shared_iban_merchants into address_book
313
323
consolidateSharedIbanMerchantsIntoAddressBook();
314
324
315
-
// MIGRATION: Multi-tenant profile support
316
-
// migrateToMultiTenant(); // Commented out since schema.sql already defines the columns
325
+
// Ensure all data has a profile_id
326
+
backfillMissingProfileIds();
327
+
328
+
// Ensure all transactions have the correct profile_id from their account
0 commit comments