add refresh tokens migration

This commit is contained in:
Paul Coral
2025-08-17 15:00:38 +02:00
parent 3b304e4158
commit 2d3d1f57a7

View File

@@ -0,0 +1,33 @@
import { Kysely, sql } from 'kysely';
export async function up(db: Kysely<unknown>): Promise<void> {
await db.schema
.createTable('refresh_tokens')
.addColumn('id', 'bigserial', (col) => col.primaryKey())
.addColumn('user_id', 'bigserial', (col) => col.notNull())
.addForeignKeyConstraint(
'fk_user_id_refresh_tokens_users',
['user_id'],
'users',
['id'],
(col) => col.onDelete('cascade'),
)
.addColumn('token', 'text', (col) => col.notNull())
.addUniqueConstraint('uniq_user_id_tokens_refresh_tokens', [
'user_id',
'token',
])
.addColumn('valid_until', 'timestamptz', (col) => col.notNull())
.addColumn('created_at', 'timestamptz', (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn('updated_at', 'timestamptz', (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn('deleted_at', 'timestamptz')
.execute();
}
export async function down(db: Kysely<unknown>): Promise<void> {
await db.schema.dropTable('refresh_tokens').execute();
}