Repository navigation
Replies: 2 comments
|
As far as I can tell, there is currently no way to register
That is why a hand-written definition such as: primaryColor: oklchColumn("primary_color").notNull()cannot currently be preserved by Options1. Code-first Treat Because drizzle-kit generate --custom --name=create-oklch-typeThen put the DDL in the generated migration: CREATE TYPE oklch AS (
l numeric,
c numeric,
h smallint,
a numeric
);That migration has to run before the migration that creates tables containing For an existing database where the type already exists, don't blindly apply the migration again; the migration should be treated as part of your database's existing migration history. 2. Keep using Keep the generated output separate from the hand-written schema, for example: export default defineConfig({
dialect: "postgresql",
out: "./drizzle/introspected",
// ...
});
3. Avoid the composite type If the PostgreSQL composite type is not important to the database API itself, a simpler representation may be easier to maintain. For example, you could use four normal columns, or store the value as color: jsonb("color").$type<Oklch>()The latter is useful for application typing, but What's missingThe real missing feature is a mapping between a PostgreSQL type name and a Drizzle builder during introspection. Conceptually, something like: export default defineConfig({
dialect: "postgresql",
customTypes: {
oklch: {
builder: "oklchColumn",
import: "./src/db/types/oklch",
},
},
});would allow import { oklchColumn } from "./src/db/types/oklch";
export const themes = pgTable("themes", {
primaryColor: oklchColumn("primary_color").notNull(),
bgColor: oklchColumn("bg_color").notNull(),
textColor: oklchColumn("text_color").notNull(),
});That mapping does not appear to exist in the current Kit configuration/introspection API, so I think this is best treated as a feature request rather than a problem with the One unrelated issue in the example is worth mentioning: |
|
One separate issue in the example is worth fixing while you keep the handwritten schema: For your numeric-only composite, return PostgreSQL's composite text input, with parentheses but no return `(${l.toFixed(fixedDigits)},${c.toFixed(fixedDigits)},${h.toFixed(0)},${alpha.toFixed(fixedDigits)})`;Alternatively, Drizzle's Validate finite values and the intended lower bounds as well as the upper bounds before serialization. Also account for nullable composite attributes if the database permits them: This addresses insert serialization, not preservation by |
Uh oh!
There was an error while loading. Please reload this page.
I'm storing oklch colors in a database, so I defined a composite type:
I defined a custom data type that can handle this:
And I can use it in a schema like this:
But
drizzle-kit pullclobbers these definitions every time. Is there a way to register this custom type so thatdrizzle-kit pullwon't do that?All reactions