mirror of
https://github.com/docmost/docmost.git
synced 2025-11-16 15:41:11 +10:00
* replace TypeORM with Kysely query builder * refactor migrations * other changes and fixes
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { Kysely, sql } from 'kysely';
|
|
|
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
await db.schema
|
|
.createTable('group_users')
|
|
.addColumn('id', 'uuid', (col) =>
|
|
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
|
)
|
|
.addColumn('userId', 'uuid', (col) =>
|
|
col.references('users.id').onDelete('cascade').notNull(),
|
|
)
|
|
.addColumn('groupId', 'uuid', (col) =>
|
|
col.references('groups.id').onDelete('cascade').notNull(),
|
|
)
|
|
.addColumn('createdAt', 'timestamp', (col) =>
|
|
col.notNull().defaultTo(sql`now()`),
|
|
)
|
|
.addColumn('updatedAt', 'timestamp', (col) =>
|
|
col.notNull().defaultTo(sql`now()`),
|
|
)
|
|
.addUniqueConstraint('group_users_groupId_userId_unique', [
|
|
'groupId',
|
|
'userId',
|
|
])
|
|
.execute();
|
|
}
|
|
|
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
await db.schema
|
|
.alterTable('group_users')
|
|
.dropConstraint('group_users_userId_fkey')
|
|
.execute();
|
|
|
|
await db.schema
|
|
.alterTable('group_users')
|
|
.dropConstraint('group_users_groupId_fkey')
|
|
.execute();
|
|
|
|
await db.schema.dropTable('group_users').execute();
|
|
}
|