add refresh tokens migration
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user