Open andreterron opened 1 year ago
I am using "drizzle-kit": "0.22.6".
I just ran into this as well. I am adding a primary key to some existing tables that don't have one. I workaround for the migration issue is to do it in two passes:
export const testTable = pgTable("test", {
id: uuid("id").defaultRandom().notNull(), // <- Don't add the primary key
createdAt: timestamp("created_at").notNull().defaultNow(),
});
Output (first migration)
ALTER TABLE "test" ADD COLUMN "id" uuid DEFAULT gen_random_uuid() NOT NULL;--> statement-breakpoint
export const testTable = pgTable("test", {
id: uuid("id").defaultRandom().notNull().primaryKey(),
createdAt: timestamp("created_at").notNull().defaultNow(),
});
Output (second migration)
ALTER TABLE "test" ADD PRIMARY KEY ("id");
Creating a new table on our schema:
Correctly generates the sql migration (With
PRIMARY KEY
):But if I start with the following schema
And then add the
id
property, I get the following migration (Nothing about the primary key):I would expect the sql migration to also set
id
as the primary key, but I had to manually add the following SQL statement to our migration:Sharing it here so that others can be aware of it, and hopefully be fixed!
Environment:
drizzle-orm/pg-core
drizzle-kit generate:pg