| 1 | -- Email-address verification: a nullable verified timestamp plus single-use, |
| 2 | -- expiring verification tokens. Addresses that predate this migration are |
| 3 | -- trusted (back-filled as verified). |
| 4 | ALTER TABLE user_emails ADD COLUMN verified_at BIGINT; |
| 5 | UPDATE user_emails SET verified_at = created_at; |
| 6 | |
| 7 | CREATE TABLE email_tokens ( |
| 8 | token TEXT PRIMARY KEY, |
| 9 | email_id TEXT NOT NULL REFERENCES user_emails(id) ON DELETE CASCADE, |
| 10 | expires_at BIGINT NOT NULL, |
| 11 | created_at BIGINT NOT NULL |
| 12 | ); |
| 13 | CREATE INDEX idx_email_tokens_email ON email_tokens (email_id); |