Drizzle
Migrations
When using introspect “pull” the migration is created but commented out. Uncomment the code to run the migration to keep crizzle in sync, otherwise it will error from seeing the migration. Remove the tables you don’t wish to migrate.
Schemas
Schemas can be seperated into multiple files.
src/db/schemas/users.ts
src/db/schemas/products.ts
and when creating the db instance, merge them together:
import * as usersSchema from "drizzle/schema/users";
const mergedSchema = {
...productsSchema,
...usersSchema
}
zod
db/schema/index can export the types:
export * as users from "./users"
and the types can be imported from the index:
import {users} from "@/db/schema/"
Zod Helpers
The helpers (createSelectSchema(), etc.) need the actual drizzle object.
import { events } from "@/db/schema/events"; // the object is imported
export const getEventSchema = {
tags: ["events"],
params: z.object({
id: z.string(),
}),
response: {
200: createSelectSchema(events),
...errorResponses,
},
};
Learning Lab Notes