-- Beezifi Identity OAuth integration
-- Run after schema.sql

ALTER TABLE users
  ADD COLUMN beezifi_sub VARCHAR(255) DEFAULT NULL UNIQUE;

CREATE TABLE IF NOT EXISTS beezifi_oauth_states (
  state      VARCHAR(64)  NOT NULL PRIMARY KEY,
  nonce      VARCHAR(64)  NOT NULL,
  flow       VARCHAR(10)  NOT NULL DEFAULT 'login',  -- 'login' or 'link'
  user_id    INT UNSIGNED DEFAULT NULL,              -- set for 'link' flow only
  expires_at TIMESTAMP    NOT NULL,
  INDEX idx_expires (expires_at)
) ENGINE=InnoDB;
