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
21.57k stars 490 forks source link

[BUG]: Column conflicts are not getting resolved by drizzle-kit #2346

Closed SabirKhanek closed 1 month ago

SabirKhanek commented 1 month ago

What version of drizzle-orm are you using?

0.21.2

What version of drizzle-kit are you using?

0.30.6

Describe the Bug

Simulate the column conflicts:

  1. Write schema for demo_table:
    export const demo_user = pgTable("demo_user", {
    username: text("username").primaryKey(),
    password: text("password")
    })
  2. Generate migration file for the schema:
    drizzle-kit generate
  3. Check the migration file (0001_opposite_thena.sql in my case):
    CREATE TABLE IF NOT EXISTS "demo_user" (
    "username" text PRIMARY KEY NOT NULL,
    "password" text
    );
  4. Now update the schema:
    export const user = pgTable("user", {
    username: text("username").primaryKey(),
    password_hash: text("password_hash")
    })

    Notice I altered table name from demo_user -> user to simulate table level conflict, similarly I altered password -> password_hash to simulate column level conflict.

  5. Now run the generate command again:
    drizzle-kit generate

    drizzle-kit prompts to choose if user is new table or renamed from demo_user.

  6. Check the migration file 0002_stormy_dreadnoughts.sql in my case:
    ALTER TABLE "demo_user" RENAME TO "user";

Expected behavior

  1. drizzle-kit should've prompted to resolve column conflicts (if password_hash renamed from password)
  2. Generated migration file should've included
    ALTER TABLE "user" RENAME COLUMN "password" TO "password_hash";

Environment & setup

This issue only occurs if we have table conflict as well. I have tested while only simulating column conflict and it worked as expected. I've been using drizzle-kit@^0.20.0 and this issue wasn't there. I observed this issue after updating to drizzle-kit@^0.21.2

SabirKhanek commented 1 month ago

this issue seems to be related with #2336 #2335

AndriiSherman commented 1 month ago

This should be fixed in drizzle-kit@0.21.3. If the issue persists, feel free to reopen it!