-- Users table to store user accounts and their master keys/hashes CREATE TABLE IF NOT EXISTS users ( id TEXT PRIMARY KEY NOT NULL, name TEXT, email TEXT NOT NULL UNIQUE, email_verified BOOLEAN NOT NULL DEFAULT 0, master_password_hash TEXT NOT NULL, master_password_hint TEXT, password_salt TEXT, -- Salt for server-side PBKDF2 hashing (NULL for legacy users pending migration) key TEXT NOT NULL, -- The encrypted symmetric key private_key TEXT NOT NULL, -- encrypted asymmetric private_key public_key TEXT NOT NULL, -- asymmetric public_key kdf_type INTEGER NOT NULL DEFAULT 0, -- 0 for PBKDF2, 1 for Argon2id kdf_iterations INTEGER NOT NULL DEFAULT 600000, kdf_memory INTEGER, -- Argon2 memory parameter in MB (15-1024), NULL for PBKDF2 kdf_parallelism INTEGER, -- Argon2 parallelism parameter (1-16), NULL for PBKDF2 security_stamp TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL ); -- Ciphers table for storing encrypted vault items CREATE TABLE IF NOT EXISTS ciphers ( id TEXT PRIMARY KEY NOT NULL, user_id TEXT, organization_id TEXT, type INTEGER NOT NULL, data TEXT NOT NULL, -- JSON blob of all encrypted fields (name, notes, login, etc.) favorite BOOLEAN NOT NULL DEFAULT 0, folder_id TEXT, deleted_at TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (folder_id) REFERENCES folders(id) ON DELETE SET NULL ); -- Folders table for organizing ciphers CREATE TABLE IF NOT EXISTS folders ( id TEXT PRIMARY KEY NOT NULL, user_id TEXT NOT NULL, name TEXT NOT NULL, -- Encrypted folder name created_at TEXT NOT NULL, updated_at TEXT NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE );