Skip to content

Commit

Permalink
fix: changed dialog schema type to customJson beacuse of drizzle-team…
Browse files Browse the repository at this point in the history
  • Loading branch information
lopesdasilva committed Jun 24, 2024
1 parent 284057a commit 47316c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions web/dashboard/src/data/components/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { json, pgEnum, pgTable, primaryKey, text, timestamp, uuid } from 'drizzle-orm/pg-core';
import { pgEnum, pgTable, primaryKey, text, timestamp, uuid } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';
import { customJsonb } from '@/db/custom-types';
import { customJson } from '@/db/custom-types';

export const assetTypeEnum = pgEnum('asset_type', ['css', 'js', 'chunk', 'server']);

Expand All @@ -19,7 +19,7 @@ export const componentVersions = pgTable("component_version", {
id: uuid('id').unique().notNull().defaultRandom(),
component_id: uuid('component_id').notNull().references(() => components.id, { onDelete: 'cascade' }),
version: text('version').notNull(),
dialog: customJsonb('dialog'),
dialog: customJson('dialog'),
created_at: timestamp("created_at").defaultNow().notNull(),
readme: text("readme"),
changelog: text("changelog"),
Expand Down
18 changes: 18 additions & 0 deletions web/dashboard/src/db/custom-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,21 @@ export const customJsonb = customType<{ data: unknown }>({
return value;
},
});
export const customJson = customType<{ data: unknown }>({
dataType() {
return 'json';
},
toDriver(value) {
return value;
},
fromDriver(value): unknown {
if (typeof value === 'string') {
try {
return JSON.parse(value);
} catch {
console.warn('Failed to parse json - the default value will be used');
}
}
return value;
},
});

0 comments on commit 47316c0

Please sign in to comment.