-- Two-factor authentication (TOTP) and single-use recovery codes. Applied by store/migrate.rs. -- totp_secret_sealed holds the instance-key sealed secret (secret::seal output, UTF-8 bytes). -- totp_enabled stays 0 until the user confirms a code. totp_last_step is the replay guard. ALTER TABLE users ADD COLUMN totp_secret_sealed BLOB NULL; ALTER TABLE users ADD COLUMN totp_enabled INTEGER NOT NULL DEFAULT 0; ALTER TABLE users ADD COLUMN totp_last_step INTEGER NOT NULL DEFAULT 0; CREATE TABLE recovery_codes ( id TEXT PRIMARY KEY, user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, code_hash TEXT NOT NULL, -- hex sha256 of the normalized code used_at TEXT NULL ); CREATE INDEX recovery_codes_user_id ON recovery_codes(user_id);