From 01f589b6031a5fbbc2f844e2b0534249eb700058 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 6 Feb 2025 17:18:26 +0300 Subject: [PATCH] fix: don't dynamically populate document kind in schema (#769) --- docs/03-blocks.md | 25 +++++++++++++++++++++++++ lib/db/schema.ts | 4 +++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/03-blocks.md b/docs/03-blocks.md index 6a2a28e..a21f016 100644 --- a/docs/03-blocks.md +++ b/docs/03-blocks.md @@ -222,6 +222,31 @@ export const documentHandlersByBlockKind: Array = [ export const blockKinds = [..., "custom"] as const; ``` +Specify it in document schema at `lib/db/schema.ts`. + +```ts +export const document = pgTable( + "Document", + { + id: uuid("id").notNull().defaultRandom(), + createdAt: timestamp("createdAt").notNull(), + title: text("title").notNull(), + content: text("content"), + kind: varchar("text", { enum: [..., "custom"] }) // Add the custom block kind here + .notNull() + .default("text"), + userId: uuid("userId") + .notNull() + .references(() => user.id), + }, + (table) => { + return { + pk: primaryKey({ columns: [table.id, table.createdAt] }), + }; + }, +); +``` + And also add the client-side block to the `blockDefinitions` array in the `components/block.tsx` file. ```ts diff --git a/lib/db/schema.ts b/lib/db/schema.ts index 882b061..defa78f 100644 --- a/lib/db/schema.ts +++ b/lib/db/schema.ts @@ -73,7 +73,9 @@ export const document = pgTable( createdAt: timestamp('createdAt').notNull(), title: text('title').notNull(), content: text('content'), - kind: varchar('text', { enum: blockKinds }).notNull().default('text'), + kind: varchar('text', { enum: ['text', 'code', 'image', 'sheet'] }) + .notNull() + .default('text'), userId: uuid('userId') .notNull() .references(() => user.id),