package store const schemaVersion = 2 // schemaSQL is the full current schema. All statements are idempotent via IF NOT EXISTS. const schemaSQL = ` CREATE TABLE IF NOT EXISTS settings ( key TEXT PRIMARY KEY, value TEXT NOT NULL ); CREATE TABLE IF NOT EXISTS accounts ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, mode TEXT NOT NULL CHECK (mode IN ('RO','RW')), imap_host TEXT NOT NULL, imap_port INTEGER NOT NULL, imap_security TEXT NOT NULL CHECK (imap_security IN ('tls','starttls')), smtp_host TEXT, smtp_port INTEGER, smtp_security TEXT, auth_type TEXT NOT NULL CHECK (auth_type IN ('password','oauth2')), username TEXT NOT NULL, from_address TEXT, enc_password BLOB, enc_oauth_client_id BLOB, enc_oauth_client_secret BLOB, enc_oauth_refresh_token BLOB, whitelist_in_enabled INTEGER NOT NULL DEFAULT 0, whitelist_out_enabled INTEGER NOT NULL DEFAULT 0, subject_regex TEXT, process_backlog INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE IF NOT EXISTS whitelist_in ( account_id INTEGER NOT NULL REFERENCES accounts(id) ON DELETE CASCADE, address TEXT NOT NULL, PRIMARY KEY (account_id, address) ); CREATE TABLE IF NOT EXISTS whitelist_out ( account_id INTEGER NOT NULL REFERENCES accounts(id) ON DELETE CASCADE, address TEXT NOT NULL, PRIMARY KEY (account_id, address) ); CREATE TABLE IF NOT EXISTS folder_state ( account_id INTEGER NOT NULL REFERENCES accounts(id) ON DELETE CASCADE, folder TEXT NOT NULL, uidvalidity INTEGER NOT NULL, floor_uid INTEGER NOT NULL, PRIMARY KEY (account_id, folder) ); CREATE TABLE IF NOT EXISTS acked ( account_id INTEGER NOT NULL REFERENCES accounts(id) ON DELETE CASCADE, folder TEXT NOT NULL, uidvalidity INTEGER NOT NULL, uid INTEGER NOT NULL, PRIMARY KEY (account_id, folder, uid) ); CREATE TABLE IF NOT EXISTS audit_log ( id INTEGER PRIMARY KEY AUTOINCREMENT, ts TEXT NOT NULL, account TEXT NOT NULL, action TEXT NOT NULL, target TEXT NOT NULL, result TEXT NOT NULL, reason TEXT ); `