diff --git a/migrations/0003_add_email_verification.sql b/migrations/0003_add_email_verification.sql new file mode 100644 index 0000000..8d589bd --- /dev/null +++ b/migrations/0003_add_email_verification.sql @@ -0,0 +1,27 @@ +-- Migration 0003: Add email verification support + +-- Add email_verified column to users (existing users are grandfathered as verified) +ALTER TABLE users ADD COLUMN email_verified INTEGER NOT NULL DEFAULT 0; +UPDATE users SET email_verified = 1; + +-- Email verification tokens table +CREATE TABLE IF NOT EXISTS email_verification_tokens ( + id TEXT PRIMARY KEY, + user_id TEXT NOT NULL, + token_hash TEXT NOT NULL UNIQUE, + expires_at TEXT NOT NULL, + created_at TEXT NOT NULL DEFAULT (datetime('now')), + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE +); + +CREATE INDEX IF NOT EXISTS idx_evtoken_user ON email_verification_tokens(user_id); + +CREATE TABLE IF NOT EXISTS password_reset_tokens ( + id TEXT PRIMARY KEY, + user_id TEXT NOT NULL, + token_hash TEXT NOT NULL UNIQUE, + expires_at TEXT NOT NULL, + created_at TEXT NOT NULL DEFAULT (datetime('now')), + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE +); +CREATE INDEX IF NOT EXISTS idx_prtoken_user ON password_reset_tokens(user_id); \ No newline at end of file