Refactoring

* replace TypeORM with Kysely query builder
* refactor migrations
* other changes and fixes
This commit is contained in:
Philipinho
2024-03-29 01:46:11 +00:00
parent cacb5606b1
commit c18c9ae02b
122 changed files with 2619 additions and 3541 deletions

View File

@ -6,16 +6,22 @@ export async function up(db: Kysely<any>): Promise<void> {
.addColumn('id', 'uuid', (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn('pageId', 'uuid', (col) => col.notNull())
.addColumn('pageId', 'uuid', (col) =>
col.references('pages.id').onDelete('cascade').notNull(),
)
.addColumn('title', 'varchar', (col) => col)
.addColumn('content', 'jsonb', (col) => col)
.addColumn('slug', 'varchar', (col) => col)
.addColumn('icon', 'varchar', (col) => col)
.addColumn('coverPhoto', 'varchar', (col) => col)
.addColumn('version', 'int4', (col) => col.notNull())
.addColumn('lastUpdatedById', 'uuid', (col) => col.notNull())
.addColumn('spaceId', 'uuid', (col) => col.notNull())
.addColumn('workspaceId', 'uuid', (col) => col.notNull())
.addColumn('lastUpdatedById', 'uuid', (col) => col.references('users.id'))
.addColumn('spaceId', 'uuid', (col) =>
col.references('spaces.id').onDelete('cascade').notNull(),
)
.addColumn('workspaceId', 'uuid', (col) =>
col.references('workspaces.id').onDelete('cascade').notNull(),
)
.addColumn('createdAt', 'timestamp', (col) =>
col.notNull().defaultTo(sql`now()`),
)
@ -23,72 +29,27 @@ export async function up(db: Kysely<any>): Promise<void> {
col.notNull().defaultTo(sql`now()`),
)
.execute();
// foreign key relations
await db.schema
.alterTable('page_history')
.addForeignKeyConstraint(
'FK_page_history_pages_pageId',
['pageId'],
'pages',
['id'],
)
.onDelete('cascade')
.execute();
await db.schema
.alterTable('page_history')
.addForeignKeyConstraint(
'FK_page_history_users_lastUpdatedById',
['lastUpdatedById'],
'users',
['id'],
)
.execute();
await db.schema
.alterTable('page_history')
.addForeignKeyConstraint(
'FK_page_history_spaces_spaceId',
['spaceId'],
'spaces',
['id'],
)
.onDelete('cascade')
.execute();
await db.schema
.alterTable('page_history')
.addForeignKeyConstraint(
'FK_page_history_workspaces_workspaceId',
['workspaceId'],
'workspaces',
['id'],
)
.onDelete('cascade')
.onUpdate('no action')
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema
.alterTable('page_history')
.dropConstraint('FK_page_history_pages_pageId')
.dropConstraint('page_history_pageId_fkey')
.execute();
await db.schema
.alterTable('page_history')
.dropConstraint('FK_page_history_users_lastUpdatedById')
.dropConstraint('page_history_lastUpdatedById_fkey')
.execute();
await db.schema
.alterTable('page_history')
.dropConstraint('FK_page_history_spaces_spaceId')
.dropConstraint('page_history_spaceId_fkey')
.execute();
await db.schema
.alterTable('page_history')
.dropConstraint('FK_page_history_workspaces_workspaceId')
.dropConstraint('page_history_workspaceId_fkey')
.execute();
await db.schema.dropTable('page_history').execute();