Files
docmost/apps/server/src/kysely/migrations/20240324T086600-comments.ts
Philipinho c18c9ae02b Refactoring
* replace TypeORM with Kysely query builder
* refactor migrations
* other changes and fixes
2024-03-29 01:46:11 +00:00

53 lines
1.5 KiB
TypeScript

import { Kysely, sql } from 'kysely';
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable('comments')
.addColumn('id', 'uuid', (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn('content', 'jsonb', (col) => col)
.addColumn('selection', 'varchar', (col) => col)
.addColumn('type', 'varchar', (col) => col)
.addColumn('creatorId', 'uuid', (col) => col.references('users.id'))
.addColumn('pageId', 'uuid', (col) =>
col.references('pages.id').onDelete('cascade').notNull(),
)
.addColumn('parentCommentId', 'uuid', (col) =>
col.references('comments.id').onDelete('cascade'),
)
.addColumn('workspaceId', 'uuid', (col) =>
col.references('workspaces.id').notNull(),
)
.addColumn('createdAt', 'timestamp', (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn('editedAt', 'timestamp', (col) => col)
.addColumn('deletedAt', 'timestamp', (col) => col)
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema
.alterTable('comments')
.dropConstraint('comments_creatorId_fkey')
.execute();
await db.schema
.alterTable('comments')
.dropConstraint('comments_pageId_fkey')
.execute();
await db.schema
.alterTable('comments')
.dropConstraint('comments_parentCommentId_fkey')
.execute();
await db.schema
.alterTable('comments')
.dropConstraint('comments_workspaceId_fkey')
.execute();
await db.schema.dropTable('comments').execute();
}