fix: don't dynamically populate document kind in schema (#769)

This commit is contained in:
Jeremy 2025-02-06 17:18:26 +03:00 committed by GitHub
parent dfc07ce0ae
commit 01f589b603
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -222,6 +222,31 @@ export const documentHandlersByBlockKind: Array<DocumentHandler> = [
export const blockKinds = [..., "custom"] as const; 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. And also add the client-side block to the `blockDefinitions` array in the `components/block.tsx` file.
```ts ```ts

View file

@ -73,7 +73,9 @@ export const document = pgTable(
createdAt: timestamp('createdAt').notNull(), createdAt: timestamp('createdAt').notNull(),
title: text('title').notNull(), title: text('title').notNull(),
content: text('content'), 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') userId: uuid('userId')
.notNull() .notNull()
.references(() => user.id), .references(() => user.id),