doxa-maps-cdn/migrations/011_add_invite_fields.ts
corsacca 54aaef6bae
User invitation (#3)
* Implement user invitation

* fix /admin styles clash on dev

* Fix user invite issues
2026-04-28 06:26:59 -05:00

38 lines
1.1 KiB
TypeScript

import { Kysely, sql } from 'kysely'
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.alterTable('users')
.alterColumn('password', col => col.dropNotNull())
.execute()
await sql`ALTER TABLE users ALTER COLUMN password DROP DEFAULT`.execute(db)
await db.schema
.alterTable('users')
.addColumn('token_expires_at', 'timestamptz')
.execute()
// Existing unverified rows had no expiry — give them a 7-day grace window
// from the migration time so nobody is locked out the moment this ships.
await sql`
UPDATE users
SET token_expires_at = now() + interval '7 days'
WHERE verified = false
`.execute(db)
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema
.alterTable('users')
.dropColumn('token_expires_at')
.execute()
await sql`ALTER TABLE users ALTER COLUMN password SET DEFAULT ''`.execute(db)
await sql`UPDATE users SET password = '' WHERE password IS NULL`.execute(db)
await db.schema
.alterTable('users')
.alterColumn('password', col => col.setNotNull())
.execute()
}