fix: Identify and fix migration tracking issue with proper parameter binding

- Root cause: Migration names were not being properly inserted into migrations table
- Fixed parameter binding in Capacitor platform service migration functions
- Added detailed debugging to track SQL execution and parameter passing
- Reverted migrations back to proper form (without IF NOT EXISTS workarounds)
- Enhanced extractMigrationNames to handle Capacitor SQLite result format

The migration system should now properly track applied migrations and avoid
re-running them on subsequent app starts.
This commit is contained in:
Matthew Raymer
2025-06-30 07:09:35 +00:00
parent 4120f5a94e
commit 4a01df509b
3 changed files with 78 additions and 90 deletions

View File

@@ -40,12 +40,13 @@ const randomBytes = crypto.getRandomValues(new Uint8Array(32));
const secretBase64 = arrayBufferToBase64(randomBytes);
// Each migration can include multiple SQL statements (with semicolons)
// NOTE: These should run only once per migration. The migration system tracks
// which migrations have been applied in the 'migrations' table.
const MIGRATIONS = [
{
name: "001_initial",
sql: `
-- Create accounts table only if it doesn't exist
CREATE TABLE IF NOT EXISTS accounts (
CREATE TABLE accounts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
dateCreated TEXT NOT NULL,
derivationPath TEXT,
@@ -56,19 +57,16 @@ const MIGRATIONS = [
publicKeyHex TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_accounts_did ON accounts(did);
CREATE INDEX idx_accounts_did ON accounts(did);
-- Create secret table only if it doesn't exist
CREATE TABLE IF NOT EXISTS secret (
CREATE TABLE secret (
id INTEGER PRIMARY KEY AUTOINCREMENT,
secretBase64 TEXT NOT NULL
);
-- Insert secret only if table is empty
INSERT OR IGNORE INTO secret (id, secretBase64) VALUES (1, '${secretBase64}');
INSERT INTO secret (id, secretBase64) VALUES (1, '${secretBase64}');
-- Create settings table only if it doesn't exist
CREATE TABLE IF NOT EXISTS settings (
CREATE TABLE settings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
accountDid TEXT,
activeDid TEXT,
@@ -100,13 +98,11 @@ const MIGRATIONS = [
webPushServer TEXT
);
CREATE INDEX IF NOT EXISTS idx_settings_accountDid ON settings(accountDid);
CREATE INDEX idx_settings_accountDid ON settings(accountDid);
-- Insert default settings only if table is empty
INSERT OR IGNORE INTO settings (id, apiServer) VALUES (1, '${DEFAULT_ENDORSER_API_SERVER}');
INSERT INTO settings (id, apiServer) VALUES (1, '${DEFAULT_ENDORSER_API_SERVER}');
-- Create contacts table only if it doesn't exist
CREATE TABLE IF NOT EXISTS contacts (
CREATE TABLE contacts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
did TEXT NOT NULL,
name TEXT,
@@ -119,17 +115,15 @@ const MIGRATIONS = [
registered BOOLEAN
);
CREATE INDEX IF NOT EXISTS idx_contacts_did ON contacts(did);
CREATE INDEX IF NOT EXISTS idx_contacts_name ON contacts(name);
CREATE INDEX idx_contacts_did ON contacts(did);
CREATE INDEX idx_contacts_name ON contacts(name);
-- Create logs table only if it doesn't exist
CREATE TABLE IF NOT EXISTS logs (
CREATE TABLE logs (
date TEXT NOT NULL,
message TEXT NOT NULL
);
-- Create temp table only if it doesn't exist
CREATE TABLE IF NOT EXISTS temp (
CREATE TABLE temp (
id TEXT PRIMARY KEY,
blobB64 TEXT
);
@@ -139,7 +133,6 @@ const MIGRATIONS = [
name: "002_add_iViewContent_to_contacts",
sql: `
-- Add iViewContent column to contacts table
-- The migration service will check if the column already exists
ALTER TABLE contacts ADD COLUMN iViewContent BOOLEAN DEFAULT TRUE;
`,
},