drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.35k stars 571 forks source link

[BUG]: Migrate text field to uuid field #2974

Open callmetwan opened 6 days ago

callmetwan commented 6 days ago

What version of drizzle-orm are you using?

0.33.0

What version of drizzle-kit are you using?

0.23.2

Describe the Bug

Changing a (postgres) schema from text to uuid results in the error:

PostgresError: column user_id cannot be cast automatically to type uuid

MigrationSQL generated:

ALTER TABLE "schemaname"."tablename" ALTER COLUMN "user_id" SET DATA TYPE uuid;

Expected behavior

Adding USING user_id::uuid seems to resolve the issue:

ALTER TABLE "schemaname"."tablename" ALTER COLUMN "user_id" SET DATA TYPE uuid
USING user_id::uuid;

Environment & setup

Sample schema:

pgSchema("schemaname").table("tablename", {
  id: uuid("id").defaultRandom().primaryKey(),
  userId: text("user_id").notNull(),
});

Changed to this:

pgSchema("schemaname").table("tablename", {
  id: uuid("id").defaultRandom().primaryKey(),
  userId: uuid("user_id").notNull(),
});

MigrationSQL generated:

ALTER TABLE "schemaname"."tablename" ALTER COLUMN "user_id" SET DATA TYPE uuid;
hilja commented 6 days ago

I think these are the same issue https://github.com/drizzle-team/drizzle-orm/issues/2751

callmetwan commented 5 days ago

I think these are the same issue #2751

Yup, looks to be the same! I’ll close this one.