| 1 | -- SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | -- |
| 3 | -- Email verification tokens. Same pattern as password_resets but keyed |
| 4 | -- to a specific user_email row (a user with multiple emails verifies |
| 5 | -- each one separately). TTL 24h. Single-use via used_at. |
| 6 | |
| 7 | -- +goose Up |
| 8 | CREATE TABLE email_verifications ( |
| 9 | id bigserial PRIMARY KEY, |
| 10 | user_email_id bigint NOT NULL REFERENCES user_emails(id) ON DELETE CASCADE, |
| 11 | token_hash bytea NOT NULL UNIQUE, |
| 12 | expires_at timestamptz NOT NULL, |
| 13 | used_at timestamptz, |
| 14 | created_at timestamptz NOT NULL DEFAULT now() |
| 15 | ); |
| 16 | |
| 17 | CREATE INDEX email_verifications_email_id_idx ON email_verifications (user_email_id); |
| 18 | CREATE INDEX email_verifications_expires_at_idx ON email_verifications (expires_at); |
| 19 | |
| 20 | -- +goose Down |
| 21 | DROP TABLE IF EXISTS email_verifications; |
| 22 |