/** * Adds `password_reset_tokens`, which holds the single-use tokens that * password-reset-service emails to users who forgot their password. * * @module */ import type { DatabaseSync } from "node:sqlite"; /** * Run once by `runMigrations`. A database made from schema.sql already has the * table. */ export function up(db: DatabaseSync): void { const tables = new Set( (db.prepare( `SELECT name FROM sqlite_master WHERE type = 'table';`, ).all() as { name: string }[]).map((r) => r.name), ); if (!tables.has("password_reset_tokens")) { db.exec( `CREATE TABLE password_reset_tokens ( token TEXT PRIMARY KEY, user_id TEXT NOT NULL, expires_at TEXT NOT NULL, used_at TEXT, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE );`, ); } }