-- Beezifi Identity SSO support

ALTER TABLE users
  ADD COLUMN IF NOT EXISTS beezifi_sub VARCHAR(255) DEFAULT NULL;

ALTER TABLE users
  ADD UNIQUE KEY IF NOT EXISTS uq_beezifi_sub (beezifi_sub);

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',
  user_id    INT UNSIGNED DEFAULT NULL,
  expires_at TIMESTAMP    NOT NULL,
  INDEX idx_expires (expires_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
