* feat: resolve comment (EE) * Add resolve to comment mark in editor (EE) * comment ui permissions * sticky comment state tabs (EE) * cleanup * feat: add space_id to comments and allow space admins to delete any comment - Add space_id column to comments table with data migration from pages - Add last_edited_by_id, resolved_by_id, and updated_at columns to comments - Update comment deletion permissions to allow space admins to delete any comment - Backfill space_id on old comments * fix foreign keys
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { type Kysely, sql } from 'kysely';
|
|
|
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
// Add last_edited_by_id column to comments table
|
|
await db.schema
|
|
.alterTable('comments')
|
|
.addColumn('last_edited_by_id', 'uuid', (col) =>
|
|
col.references('users.id').onDelete('set null'),
|
|
)
|
|
.execute();
|
|
|
|
// Add resolved_by_id column to comments table
|
|
await db.schema
|
|
.alterTable('comments')
|
|
.addColumn('resolved_by_id', 'uuid', (col) =>
|
|
col.references('users.id').onDelete('set null'),
|
|
)
|
|
.execute();
|
|
|
|
// Add updated_at timestamp column to comments table
|
|
await db.schema
|
|
.alterTable('comments')
|
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
|
col.notNull().defaultTo(sql`now()`),
|
|
)
|
|
.execute();
|
|
|
|
// Add space_id column to comments table
|
|
await db.schema
|
|
.alterTable('comments')
|
|
.addColumn('space_id', 'uuid', (col) =>
|
|
col.references('spaces.id').onDelete('cascade'),
|
|
)
|
|
.execute();
|
|
|
|
// Backfill space_id from the related pages
|
|
await db
|
|
.updateTable('comments as c')
|
|
.set((eb) => ({
|
|
space_id: eb.ref('p.space_id'),
|
|
}))
|
|
.from('pages as p')
|
|
.whereRef('c.page_id', '=', 'p.id')
|
|
.execute();
|
|
|
|
// Make space_id NOT NULL after populating data
|
|
await db.schema
|
|
.alterTable('comments')
|
|
.alterColumn('space_id', (col) => col.setNotNull())
|
|
.execute();
|
|
}
|
|
|
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
await db.schema
|
|
.alterTable('comments')
|
|
.dropColumn('last_edited_by_id')
|
|
.execute();
|
|
await db.schema.alterTable('comments').dropColumn('resolved_by_id').execute();
|
|
await db.schema.alterTable('comments').dropColumn('updated_at').execute();
|
|
await db.schema.alterTable('comments').dropColumn('space_id').execute();
|
|
}
|