-- Email Confirmation tracks all email confirmations that have been sent out.
CREATE TABLE "email_confirmation" (
  "email_address" citext      NOT NULL,
  "selector"      text        NOT NULL,
  "verifier"      bytea       NOT NULL,
  "valid_until"   timestamptz NOT NULL,
  FOREIGN KEY ("email_address")
    REFERENCES "email" ("address")
    ON DELETE CASCADE
    ON UPDATE RESTRICT,
  PRIMARY KEY ("email_address")
);
CREATE UNIQUE INDEX "email_confirmation_selector_key"
  ON "email_confirmation" ("selector");

-- Password reset keeps track of the password reset tokens.
CREATE TABLE "password_reset" (
  "identity_id" bigserial NOT NULL,
  "selector"    text  NOT NULL,
  "verifier"    bytea NOT NULL,
  "valid_until" timestamptz NOT NULL,
  FOREIGN KEY ("identity_id")
    REFERENCES "person" ("identity_id")
    ON DELETE CASCADE
    ON UPDATE RESTRICT,
  PRIMARY KEY ("identity_id")
);
CREATE UNIQUE INDEX "password_reset_selector_key" ON "password_reset" ("selector");