warden-worker/migrations/0003_add_twofactor.sql

22 lines
716 B
SQL

-- Migration: Add totp_recover column and twofactor table
-- Adds recovery code storage and twofactor providers for TOTP/remember tokens.
--
-- TwoFactor types:
-- 0 = Authenticator (TOTP)
-- 1 = Email
-- 5 = Remember (device trust token)
-- 8 = RecoveryCode
CREATE TABLE IF NOT EXISTS twofactor (
uuid TEXT PRIMARY KEY NOT NULL,
user_uuid TEXT NOT NULL,
atype INTEGER NOT NULL,
enabled INTEGER NOT NULL DEFAULT 1,
data TEXT NOT NULL,
last_used INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (user_uuid) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE(user_uuid, atype)
);
-- Add totp_recover column to users table for recovery codes
ALTER TABLE users ADD COLUMN totp_recover TEXT;