-- Existing rows get email_verified = 1 (grandfathered in). New inserts will explicitly pass 0.
ALTER TABLE users ADD COLUMN email_verified INTEGER NOT NULL DEFAULT 1;

CREATE TABLE IF NOT EXISTS email_verifications (
  id         INTEGER PRIMARY KEY,
  user_id    INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  token      TEXT    NOT NULL UNIQUE,
  expires_at TEXT    NOT NULL,
  created_at TEXT    NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_email_ver_token   ON email_verifications(token);
CREATE INDEX IF NOT EXISTS idx_email_ver_user_id ON email_verifications(user_id);
