mirror of
https://github.com/docmost/docmost.git
synced 2025-11-26 10:01:10 +10:00
Refactoring
* replace TypeORM with Kysely query builder * refactor migrations * other changes and fixes
This commit is contained in:
@ -6,95 +6,57 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
.addColumn('id', 'uuid', (col) =>
|
||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
||||
)
|
||||
.addColumn('userId', 'uuid', (col) => col)
|
||||
.addColumn('groupId', 'uuid', (col) => col)
|
||||
.addColumn('spaceId', 'uuid', (col) => col.notNull())
|
||||
.addColumn('userId', 'uuid', (col) =>
|
||||
col.references('users.id').onDelete('cascade'),
|
||||
)
|
||||
.addColumn('groupId', 'uuid', (col) =>
|
||||
col.references('groups.id').onDelete('cascade'),
|
||||
)
|
||||
.addColumn('spaceId', 'uuid', (col) =>
|
||||
col.references('spaces.id').onDelete('cascade').notNull(),
|
||||
)
|
||||
.addColumn('role', 'varchar', (col) => col.notNull())
|
||||
.addColumn('creatorId', 'uuid', (col) => col)
|
||||
.addColumn('creatorId', 'uuid', (col) => col.references('users.id'))
|
||||
.addColumn('createdAt', 'timestamp', (col) =>
|
||||
col.notNull().defaultTo(sql`now()`),
|
||||
)
|
||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
||||
col.notNull().defaultTo(sql`now()`),
|
||||
)
|
||||
.addUniqueConstraint('UQ_space_members_spaceId_userId', [
|
||||
.addUniqueConstraint('space_members_spaceId_userId_unique', [
|
||||
'spaceId',
|
||||
'userId',
|
||||
])
|
||||
.addUniqueConstraint('UQ_space_members_spaceId_groupId', [
|
||||
.addUniqueConstraint('space_members_spaceId_groupId_unique', [
|
||||
'spaceId',
|
||||
'groupId',
|
||||
])
|
||||
.addCheckConstraint(
|
||||
'CHK_allow_userId_or_groupId',
|
||||
'allow_either_userId_or_groupId_check',
|
||||
sql`(("userId" IS NOT NULL AND "groupId" IS NULL) OR ("userId" IS NULL AND "groupId" IS NOT NULL))`,
|
||||
)
|
||||
.execute();
|
||||
|
||||
// foreign key relations
|
||||
await db.schema
|
||||
.alterTable('space_members')
|
||||
.addForeignKeyConstraint(
|
||||
'FK_space_members_users_userId',
|
||||
['userId'],
|
||||
'users',
|
||||
['id'],
|
||||
)
|
||||
.onDelete('cascade')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('space_members')
|
||||
.addForeignKeyConstraint(
|
||||
'FK_space_members_groups_groupId',
|
||||
['groupId'],
|
||||
'groups',
|
||||
['id'],
|
||||
)
|
||||
.onDelete('cascade')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('space_members')
|
||||
.addForeignKeyConstraint(
|
||||
'FK_space_members_spaces_spaceId',
|
||||
['spaceId'],
|
||||
'spaces',
|
||||
['id'],
|
||||
)
|
||||
.onDelete('cascade')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('space_members')
|
||||
.addForeignKeyConstraint(
|
||||
'FK_space_members_users_creatorId',
|
||||
['creatorId'],
|
||||
'users',
|
||||
['id'],
|
||||
)
|
||||
.execute();
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.alterTable('space_members')
|
||||
.dropConstraint('FK_space_members_users_userId')
|
||||
.dropConstraint('space_members_userId_fkey')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('space_members')
|
||||
.dropConstraint('FK_space_members_groups_groupId')
|
||||
.dropConstraint('space_members_groupId_fkey')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('space_members')
|
||||
.dropConstraint('FK_space_members_spaces_spaceId')
|
||||
.dropConstraint('space_members_spaceId_fkey')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('space_members')
|
||||
.dropConstraint('FK_space_members_users_creatorId')
|
||||
.dropConstraint('space_members_creatorId_fkey')
|
||||
.execute();
|
||||
await db.schema.dropTable('space_members').execute();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user