Browse Source

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
sql-absurd-sql-further
Matthew Raymer 3 days ago
parent
commit
b6d9b29720
  1. 13
      electron/src/rt/sqlite-init.ts
  2. 15
      electron/src/rt/sqlite-migrations.ts

13
electron/src/rt/sqlite-init.ts

@ -99,7 +99,6 @@ interface SQLiteConnectionOptions {
version?: number; version?: number;
readOnly?: boolean; readOnly?: boolean;
readonly?: boolean; readonly?: boolean;
encryption?: string;
mode?: string; mode?: string;
useNative?: boolean; useNative?: boolean;
[key: string]: unknown; [key: string]: unknown;
@ -478,12 +477,11 @@ export async function initializeSQLite(): Promise<void> {
throw new SQLiteError('Plugin state verification failed', 'initializeSQLite'); throw new SQLiteError('Plugin state verification failed', 'initializeSQLite');
} }
// Set up database connection // Set up database connection - simplified to match sacred-sql
const connectionOptions = { const connectionOptions = {
database: 'timesafari', database: 'timesafari',
version: 1, version: 1,
readOnly: false, readOnly: false,
encryption: 'no-encryption',
useNative: true, useNative: true,
mode: 'rwc' mode: 'rwc'
}; };
@ -508,16 +506,15 @@ export async function initializeSQLite(): Promise<void> {
mode: 'rwc' mode: 'rwc'
}); });
// Set PRAGMAs with detailed logging // Set PRAGMAs to match sacred-sql approach
const pragmaStatements = [ const pragmaStatements = [
'PRAGMA journal_mode = MEMORY;', // Changed to MEMORY mode to match sacred-sql
'PRAGMA foreign_keys = ON;', 'PRAGMA foreign_keys = ON;',
'PRAGMA journal_mode = WAL;', // Changed to WAL for better concurrency
'PRAGMA synchronous = NORMAL;', 'PRAGMA synchronous = NORMAL;',
'PRAGMA temp_store = MEMORY;', 'PRAGMA temp_store = MEMORY;',
'PRAGMA page_size = 4096;', 'PRAGMA page_size = 4096;',
'PRAGMA cache_size = 2000;', 'PRAGMA cache_size = 2000;'
'PRAGMA busy_timeout = 15000;', // Increased to 15 seconds // Removed WAL-specific settings
'PRAGMA wal_autocheckpoint = 1000;' // Added WAL checkpoint setting
]; ];
logger.debug('Setting database PRAGMAs'); logger.debug('Setting database PRAGMAs');

15
electron/src/rt/sqlite-migrations.ts

@ -432,19 +432,9 @@ const MIGRATIONS: Migration[] = [
INITIAL_MIGRATION, INITIAL_MIGRATION,
{ {
version: 2, version: 2,
name: '002_secret_and_settings', name: '002_settings_and_contacts',
description: 'Add secret, settings, contacts, logs, and temp tables with initial data', description: 'Add settings and contacts tables',
sql: ` 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 -- Settings table for user preferences and app state
CREATE TABLE IF NOT EXISTS settings ( CREATE TABLE IF NOT EXISTS settings (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -521,7 +511,6 @@ const MIGRATIONS: Migration[] = [
DROP TABLE IF EXISTS contacts; DROP TABLE IF EXISTS contacts;
DROP INDEX IF EXISTS idx_settings_accountDid; DROP INDEX IF EXISTS idx_settings_accountDid;
DROP TABLE IF EXISTS settings; DROP TABLE IF EXISTS settings;
DROP TABLE IF EXISTS secret;
` `
} }
]; ];

Loading…
Cancel
Save