--up

CREATE TABLE email_verifications (
  id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  email VARCHAR(255) NOT NULL,
  token VARCHAR(255) NOT NULL,
  verified BOOLEAN NOT NULL DEFAULT FALSE,
  invalidated BOOLEAN NOT NULL DEFAULT FALSE,
  expires_at TIMESTAMP NOT NULL DEFAULT NOW() + INTERVAL '30 minutes',
  created_at TIMESTAMP NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

CREATE INDEX email_index ON email_verifications (email);

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON email_verifications FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

--down

DROP TABLE email_verifications;
