20240531140741_create_auth.ts (1432B)
1 import { 2 AbstractMigration, 3 ClientPostgreSQL, 4 Info, 5 } from "https://deno.land/x/nessie@2.0.11/mod.ts"; 6 7 export default class extends AbstractMigration<ClientPostgreSQL> { 8 /** Runs on migrate */ 9 async up(_info: Info): Promise<void> { 10 await this.client.queryArray`create table "auth" ( 11 "uuid" uuid not null, 12 13 -- EMAIL 14 "email" varchar not null, 15 "emailVerified" boolean not null default false, 16 "emailCode" varchar null, 17 "emailCodeExpire" timestamp not null default ('1970-01-01 00:00:00'), 18 "emailChallengeRequest" int4 not null default 0, 19 "emailChallengeRequestExpire" timestamp not null default ('1970-01-01 00:00:00'), 20 "emailChallengeAttempt" int4 not null default 0, 21 "emailChallengeAttemptExpire" timestamp not null default ('1970-01-01 00:00:00'), 22 23 -- PASSWORD 24 "passwordHash" varchar not null, 25 "passwordAttempt" int4 not null default 0, 26 "passwordAttemptExpire" timestamp not null default ('1970-01-01 00:00:00'), 27 28 -- SESSION TOKEN 29 "sessionToken" varchar null, 30 "sessionExpire" timestamp not null default ('1970-01-01 00:00:00'), 31 "version" int4 not null default (0), 32 33 constraint auth_pk primary key ("uuid"), 34 constraint auth_email_uk unique ("email") 35 );`; 36 } 37 38 /** Runs on rollback */ 39 async down(_info: Info): Promise<void> { 40 await this.client.queryArray`drop table auth cascade;`; 41 } 42 }