From b6d9b29720080a8b8cf7c9f11fda8d7cf10202f1 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Thu, 5 Jun 2025 05:37:18 +0000 Subject: [PATCH] refactor(sqlite): align database implementation with sacred-sql BREAKING CHANGE: Removes database encryption in favor of simpler implementation - Remove encryption from SQLite initialization and connection options - Change journal mode from WAL to MEMORY to match sacred-sql - Simplify PRAGMA settings and remove WAL-specific configurations - Remove secret table and encryption-related migrations - Update database schema to use non-encrypted storage - Clean up database initialization process This change aligns the TimeSafari Electron SQLite implementation with sacred-sql, improving compatibility and simplifying the database layer. Existing databases will need to be cleared and recreated due to the removal of encryption support. Migration: 1. Delete existing database at ~/Databases/TimeSafari/timesafariSQLite.db 2. Restart application to create fresh database with new schema --- electron/src/rt/sqlite-init.ts | 13 +++++-------- electron/src/rt/sqlite-migrations.ts | 15 ++------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/electron/src/rt/sqlite-init.ts b/electron/src/rt/sqlite-init.ts index 6ce1b1d4..eddfe89e 100644 --- a/electron/src/rt/sqlite-init.ts +++ b/electron/src/rt/sqlite-init.ts @@ -99,7 +99,6 @@ interface SQLiteConnectionOptions { version?: number; readOnly?: boolean; readonly?: boolean; - encryption?: string; mode?: string; useNative?: boolean; [key: string]: unknown; @@ -478,12 +477,11 @@ export async function initializeSQLite(): Promise { throw new SQLiteError('Plugin state verification failed', 'initializeSQLite'); } - // Set up database connection + // Set up database connection - simplified to match sacred-sql const connectionOptions = { database: 'timesafari', version: 1, readOnly: false, - encryption: 'no-encryption', useNative: true, mode: 'rwc' }; @@ -508,16 +506,15 @@ export async function initializeSQLite(): Promise { mode: 'rwc' }); - // Set PRAGMAs with detailed logging + // Set PRAGMAs to match sacred-sql approach const pragmaStatements = [ + 'PRAGMA journal_mode = MEMORY;', // Changed to MEMORY mode to match sacred-sql 'PRAGMA foreign_keys = ON;', - 'PRAGMA journal_mode = WAL;', // Changed to WAL for better concurrency 'PRAGMA synchronous = NORMAL;', 'PRAGMA temp_store = MEMORY;', 'PRAGMA page_size = 4096;', - 'PRAGMA cache_size = 2000;', - 'PRAGMA busy_timeout = 15000;', // Increased to 15 seconds - 'PRAGMA wal_autocheckpoint = 1000;' // Added WAL checkpoint setting + 'PRAGMA cache_size = 2000;' + // Removed WAL-specific settings ]; logger.debug('Setting database PRAGMAs'); diff --git a/electron/src/rt/sqlite-migrations.ts b/electron/src/rt/sqlite-migrations.ts index 2a7e68c9..c537c8cd 100644 --- a/electron/src/rt/sqlite-migrations.ts +++ b/electron/src/rt/sqlite-migrations.ts @@ -432,19 +432,9 @@ const MIGRATIONS: Migration[] = [ INITIAL_MIGRATION, { version: 2, - name: '002_secret_and_settings', - description: 'Add secret, settings, contacts, logs, and temp tables with initial data', + name: '002_settings_and_contacts', + description: 'Add settings and contacts tables', sql: ` - -- Secret table for storing encryption keys - -- Note: This is a temporary solution until better secure storage is implemented - CREATE TABLE IF NOT EXISTS secret ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - secretBase64 TEXT NOT NULL - ); - - -- Insert initial secret only if no secret exists - INSERT OR IGNORE INTO secret (id, secretBase64) VALUES (1, '${INITIAL_SECRET}'); - -- Settings table for user preferences and app state CREATE TABLE IF NOT EXISTS settings ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -521,7 +511,6 @@ const MIGRATIONS: Migration[] = [ DROP TABLE IF EXISTS contacts; DROP INDEX IF EXISTS idx_settings_accountDid; DROP TABLE IF EXISTS settings; - DROP TABLE IF EXISTS secret; ` } ];