drizzle-team / drizzle-team/drizzle-orm
[BUG] `drizzle-kit generate` created PG migration is wrong for "time" type
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
**Using:**
drizzle-kit "0.22.8"
drizzle-orm "0.31.4"
bun 1.1.17
## Problem
A schema using pg-core's `time` type is creating the wrong migration. In this case the migration should contain:
` "audio_length" time(3) NOT NULL`
instead we get
` "audio_length" "time(3)" NOT NULL`
drizzle-kit.config.ts
```typescript
import { defineConfig } from "drizzle-kit";
export default defineConfig({
schema: "./src/db/schema.ts",
out: "./migrations",
dialect: "postgresql",
dbCredentials: {
url: process.env.DATABASE_URL ?? "",
},
});
```
Source Schema:
```typescript
import { char, pgTable, text, time, timestamp } from "drizzle-orm/pg-core";
export const transcriptions = pgTable("transcriptions", {
id: char("id", { length: 25 })
.primaryKey()
.$defaultFn(() => getEntityId("transcription")),
audioLength: time("audio_length", { precision: 3 }).notNull(),
userId: char("user_id", { length: 25 })
.references(() => users.id)
.notNull(),
createdAt: timestamp("created_at", { withTimezone: false }).defaultNow(),
decodedAt: timestamp("decoded_at", { withTimezone: false }),
retrievedAt: timestamp("retrieved_at", { withTimezone: false }),
transcriptionText: text("transcription_text"),
});
```
Generated migration:
```sql
CREATE TABLE IF NOT EXISTS "transcriptions" (
"id" char(25) PRIMARY KEY NOT NULL,
"audio_length" "time(3)" NOT NULL,
"user_id" char(25) NOT NULL,
"created_at" timestamp DEFAULT now(),
"decoded_at" timestamp,
"retrieved_at" timestamp,
"transcription_text" text
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "transcriptions" ADD CONSTRAINT "transcriptions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
```
Contributor guide
Assessment
This issue has not been assessed yet.