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.44k stars 484 forks source link

[BUG]: Cannot rename table with composite primary keys #2533

Open Lodimup opened 1 week ago

Lodimup commented 1 week ago

What version of drizzle-orm are you using?

0.31.2

What version of drizzle-kit are you using?

0.22.7

Describe the Bug

export const viewCounts = pgTable(
  "viewCounts", <---- change this to viewCount
  {
    shortLinkId: text("shortLinkId")
      .references(() => shortLinks.id, {
        onDelete: "cascade",
      })
      .notNull(),
    date: date("date").notNull(),
    count: bigint("count", { mode: "number" }).notNull(),
  },
  (table) => {
    return {
      pk: primaryKey({ columns: [table.shortLinkId, table.date] }),
    };
  }
);

change viewCounts to viewCount in line: 2 run npx drizzle-kit push

error

...
~ viewCounts › viewCount table will be renamed/moved
--- all table conflicts resolved ---

TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
    at /workspaces/.../app/node_modules/drizzle-kit/bin.cjs:27627:67
    at Array.map (<anonymous>)
    at prepareDeleteCompositePrimaryKeyPg (/workspaces/.../app/node_modules/drizzle-kit/bin.cjs:27621:33)
    at applyPgSnapshotsDiff (/workspaces/.../app/node_modules/drizzle-kit/bin.cjs:28130:33)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async preparePgPush (/workspaces/.../app/node_modules/drizzle-kit/bin.cjs:30406:52)
    at async pgPush (/workspaces/.../app/node_modules/drizzle-kit/bin.cjs:122504:26)
    at async _Command.<anonymous> (/workspaces/.../app/node_modules/drizzle-kit/bin.cjs:129681:7)

adding pkWithCustomName: primaryKey({... does not resolve the issue

Expected behavior

able to push the changes to db

Environment & setup

No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 11 (bullseye) Release: 11 Codename: bullseye

DoseOfCode commented 2 days ago

bump

cawak commented 1 day ago

I think this bug is the same as https://github.com/drizzle-team/drizzle-orm/issues/2344. I use the exact drizzle dependency versions as you do, and I get the same error while running generate after renaming a table with a composite key

AndriiSherman commented 2 hours ago

please check drizzle-kit@0.22.8, should have the fix for that