[BUG]: TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
What version of drizzle-orm are you using?
0.30.10
What version of drizzle-kit are you using?
0.21.2
Describe the Bug
if I have tables with no composite primary keys(table => pk: primaryKey(....) , then i can change my column names and do whatever i want with no issue in push.
issues arises when:
- changing column names, adding new columns, tables to schema that any table has composite primary key.
- if schema already exists in database and i want to add composite primary key.
everytime before pushing new version of the schema, i have to drop all my tables in db. otherwise drizzle-kit push command keeps failing with this error.
Expected behavior
No response
Environment & setup
next.js 14 app router application
This should be fixed in [email protected]. If the issue persists, feel free to reopen it!
I can confirm the issue still exists even on 22 beta.
As a variant of the problem, the same issue exists when renaming a table, not only a field.
Also having the same issues
drizzle-kit: v0.21.4
drizzle-orm: v0.30.10
No config path provided, using default path
Using 'pg' driver for database querying
[✓] Pulling schema from database...TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
at /app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:19393:67
at Array.map (<anonymous>)
at prepareDeleteCompositePrimaryKeyPg (/Users/brandon/brevian/platform/control-plane/app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:19387:33)
at applyPgSnapshotsDiff (/app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:19890:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async preparePgPush /app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:22139:52)
at async pgPush (/app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:114468:26)
at async Command.<anonymous> (/app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:121480:7)
I ran into the same issue, and I suspect this is related to naming conventions (camelCase vs snake case). As an example:
export const table = pgTable(
"tableName",
{
timestamp: timestamp("timestamp").notNull().defaultNow(),
userName: text("ws_id").notNull(),
},
(tb) => ({
pk: primaryKey({ columns: [tb.userName, tb.timestamp] }),
})
);
this will correctly create the userName_timestamp_pk, however, when additional changes occur and you're trying to push, drizzle-kit is trying to find username_timestamp_pk which cannot be found, thus throwing the undefined error.
I converted my table names to snake case and it seems like this solved the issue
I solved this issue by modifying the package source for [email protected], now have a manual patch for drizzle kit.
diff --git a/bin.cjs b/bin.cjs
index e5e7558dc577c4fba1ca4fe508a5851b4e8f4c91..e42056bb4937c68c0598be71ea8b63cea437dccc 100755
--- a/bin.cjs
+++ b/bin.cjs
@@ -27620,7 +27620,7 @@ var init_jsonStatements = __esm({
tableName,
data: it,
schema: schema5,
- constraintName: json1.tables[`${schema5}.${tableName}`].compositePrimaryKeys[PgSquasher.unsquashPK(it).name].name
+ constraintName: json1.tables[`${schema5 || "public"}.${tableName}`].compositePrimaryKeys[PgSquasher.unsquashPK(it).name].name
};
});
};
I can confirm the issue is still there and that the above fix from @LavaToaster solves the problem. @LavaToaster would you like to submit a PR? @AndriiSherman could you please reopen the issue?
@goldoraf drizzle kit is not open source yet. So, cannot.
why is this marked as closed? can you reopen this? 🙏
+1 to reopening this. Using drizzle-kit generate and then drizzle-kit migrate works, but not drizzle-kit push (I get the error described here).
Experiencing this issue as well when attempting to rename a table during both drizzle-kit generate and drizzle-kit push
Same issue on my end
Yep getting this issue as well. Whatever schema change I make, when I run push I just get that error
Yeah same issue here
@AndriiSherman, could you please reopen this issue? It is still present. @LavaToaster's solution is working, but it would be great if the patch landed in drizzle-kit.
Thank you!
Yes, the issue still persists. This error is triggered once I run the generate command.
I get this error once I rename a table name (snake case) with a composite prime key.
Versions: "drizzle-orm": "^0.31.2" "drizzle-kit": "^0.22.7"
Please re-open it
I am on latest versions
"drizzle-orm": "^0.31.2" "drizzle-kit": "^0.22.7"
Drizzle is not usable without solving this issue and it's closed!!!! it's almost 2 months :/
Thanks for @LavaToaster I can continue working!
Please reopen the issue...
I am on latest versions
"drizzle-orm": "^0.31.2" "drizzle-kit": "^0.22.7"
Drizzle is not usable without solving this issue and it's closed!!!! it's almost 2 months. maybe it was a mistake using drizzle this early. what a joke :/
Thanks for @LavaToaster I can continue working!
Please reopen the issue...
Just want to point out that this is open source software and there are real good people behind making it, putting in a ton of work, benefiting a lot of people
I am on latest versions "drizzle-orm": "^0.31.2" "drizzle-kit": "^0.22.7" Drizzle is not usable without solving this issue and it's closed!!!! it's almost 2 months. maybe it was a mistake using drizzle this early. what a joke :/ Thanks for @LavaToaster I can continue working! Please reopen the issue...
Just want to point out that this is open source software and there are real good people behind making it, putting in a ton of work, benefiting a lot of people
Still people are getting paid working on it, correct me if am wrong.
I am on latest versions "drizzle-orm": "^0.31.2" "drizzle-kit": "^0.22.7" Drizzle is not usable without solving this issue and it's closed!!!! it's almost 2 months. maybe it was a mistake using drizzle this early. what a joke :/ Thanks for @LavaToaster I can continue working! Please reopen the issue...
Just want to point out that this is open source software and there are real good people behind making it, putting in a ton of work, benefiting a lot of people
Still people are getting paid working on it, correct me if am wrong.
I can't speak to that, but I can say that even if I was getting paid to work on Drizzle, a comment like "what a joke" would be pretty off-putting and not feel that good to hear. I'm all for keeping this a supportive environment
I am on latest versions "drizzle-orm": "^0.31.2" "drizzle-kit": "^0.22.7" Drizzle is not usable without solving this issue and it's closed!!!! it's almost 2 months. maybe it was a mistake using drizzle this early. what a joke :/ Thanks for @LavaToaster I can continue working! Please reopen the issue...
Just want to point out that this is open source software and there are real good people behind making it, putting in a ton of work, benefiting a lot of people
Still people are getting paid working on it, correct me if am wrong.
I can't speak to that, but I can say that even if I was getting paid to work on Drizzle, a comment like "what a joke" would be pretty off-putting and not feel that good to hear. I'm all for keeping this a supportive environment
Sorry if anybody took it offensively, but almost 2 months for 1 line fix kinda funny no 😅
Hey everyone, sorry for the late response. I was really busy with other features we were working on. Let me push the patch update now so you can be unblocked
@LavaToaster thanks a lot!
Ok, yeah, it was my bad for not adding public by default. I'm publishing a patch update and will mention @LavaToaster as the one who fixed it
please check [email protected], should have the fix for that
Thank you @AndriiSherman you are appreciated
yup it's working now, thanks alot @LavaToaster @AndriiSherman!
Just want to point out that this is open source software and there are real good people behind making it, putting in a ton of work, benefiting a lot of people
Drizzle Kit is closed source
Still experiencing this bug after upgrading to [email protected].
In my case, when trying to rename a table with a camelCased name. The table does not contain any composite primary keys though.
Still experiencing the same bug even after the upgrade .
TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys') at ***/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:27627:79 at Array.map (<anonymous>) at prepareDeleteCompositePrimaryKeyPg (***/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:27621:33) at applyPgSnapshotsDiff (***/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:28130:33) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async preparePgPush (***/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:30406:52) at async pgPush (***/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:122504:26) at async _Command.<anonymous> (***/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:129681:7)