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

56 lines
1.8 KiB
TypeScript

import { Kysely, sql } from 'kysely';
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable('attachments')
.addColumn('id', 'uuid', (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn('fileName', 'varchar', (col) => col.notNull())
.addColumn('filePath', 'varchar', (col) => col.notNull())
.addColumn('fileSize', 'int8', (col) => col)
.addColumn('fileExt', 'varchar', (col) => col.notNull())
.addColumn('mimeType', 'varchar', (col) => col)
.addColumn('type', 'varchar', (col) => col)
.addColumn('creatorId', 'uuid', (col) =>
col.references('users.id').notNull(),
)
.addColumn('pageId', 'uuid', (col) => col.references('pages.id'))
.addColumn('spaceId', 'uuid', (col) => col.references('spaces.id'))
.addColumn('workspaceId', 'uuid', (col) =>
col.references('workspaces.id').onDelete('cascade').notNull(),
)
.addColumn('createdAt', 'timestamp', (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn('updatedAt', 'timestamp', (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn('deletedAt', 'timestamp', (col) => col)
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema
.alterTable('attachments')
.dropConstraint('attachments_creatorId_fkey')
.execute();
await db.schema
.alterTable('attachments')
.dropConstraint('attachments_pageId_fkey')
.execute();
await db.schema
.alterTable('attachments')
.dropConstraint('attachments_spaceId_fkey')
.execute();
await db.schema
.alterTable('attachments')
.dropConstraint('attachments_workspaceId_fkey')
.execute();
await db.schema.dropTable('attachments').execute();
}