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
This commit is contained in:
@@ -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<void> {
|
||||
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<void> {
|
||||
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');
|
||||
|
||||
@@ -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;
|
||||
`
|
||||
}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user