mirror of
https://github.com/docmost/docmost.git
synced 2025-11-18 19:21:08 +10:00
Refactoring
* replace TypeORM with Kysely query builder * refactor migrations * other changes and fixes
This commit is contained in:
@ -9,112 +9,43 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
.addColumn('content', 'jsonb', (col) => col)
|
||||
.addColumn('selection', 'varchar', (col) => col)
|
||||
.addColumn('type', 'varchar', (col) => col)
|
||||
.addColumn('creatorId', 'uuid', (col) => col.notNull())
|
||||
.addColumn('pageId', 'uuid', (col) => col.notNull())
|
||||
.addColumn('parentCommentId', 'uuid', (col) => col)
|
||||
.addColumn('resolvedById', 'uuid', (col) => col)
|
||||
.addColumn('resolvedAt', 'timestamp', (col) => col)
|
||||
.addColumn('spaceId', 'uuid', (col) => col.notNull())
|
||||
.addColumn('workspaceId', 'uuid', (col) => col.notNull())
|
||||
.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();
|
||||
|
||||
// foreign key relations
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.addForeignKeyConstraint(
|
||||
'FK_comments_users_creatorId',
|
||||
['creatorId'],
|
||||
'users',
|
||||
['id'],
|
||||
)
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.addForeignKeyConstraint('FK_comments_pages_pageId', ['pageId'], 'pages', [
|
||||
'id',
|
||||
])
|
||||
.onDelete('cascade')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.addForeignKeyConstraint(
|
||||
'FK_comments_comments_parentCommentId',
|
||||
['parentCommentId'],
|
||||
'comments',
|
||||
['id'],
|
||||
)
|
||||
.onDelete('cascade')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.addForeignKeyConstraint(
|
||||
'FK_comments_users_resolvedById',
|
||||
['resolvedById'],
|
||||
'users',
|
||||
['id'],
|
||||
)
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.addForeignKeyConstraint(
|
||||
'FK_comments_spaces_spaceId',
|
||||
['spaceId'],
|
||||
'spaces',
|
||||
['id'],
|
||||
)
|
||||
.onDelete('cascade')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.addForeignKeyConstraint(
|
||||
'FK_comments_workspaces_workspaceId',
|
||||
['workspaceId'],
|
||||
'workspaces',
|
||||
['id'],
|
||||
)
|
||||
.onDelete('cascade')
|
||||
.execute();
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.dropConstraint('FK_comments_users_creatorId')
|
||||
.dropConstraint('comments_creatorId_fkey')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.dropConstraint('FK_comments_pages_pageId')
|
||||
.dropConstraint('comments_pageId_fkey')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.dropConstraint('FK_comments_comments_parentCommentId')
|
||||
.dropConstraint('comments_parentCommentId_fkey')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.dropConstraint('FK_comments_users_resolvedById')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.dropConstraint('FK_comments_spaces_spaceId')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('comments')
|
||||
.dropConstraint('FK_comments_workspaces_workspaceId')
|
||||
.dropConstraint('comments_workspaceId_fkey')
|
||||
.execute();
|
||||
|
||||
await db.schema.dropTable('comments').execute();
|
||||
|
||||
Reference in New Issue
Block a user