-
-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]:Composite primary key not added to postgres schema when using array return in pgTable #3596
Comments
I can confirm this bug, I was trying to get ride of deprecation warnings based on https://github.com/drizzle-team/drizzle-orm/releases/tag/0.36.0, but noticed the composed PK is not added to my pg db. |
I just ran into this as well, seems to also happen with unique constraints. Going to revert back to |
also happing with mysql |
TLDR (table) => [
{
pk: primaryKey({ columns: [table.postId, table.categoryId] }),
},
], to: (table) => [primaryKey({ columns: [table.postId, table.categoryId] })], Don't know whether it is postgres specific or not, but the solution I've given here works for this case as well. (Tested locally with the given drizzle & drizzle-kit versions): #3873 (comment) |
Still present and above hack still works with |
This appears to be an issue with the docs: https://github.com/drizzle-team/drizzle-orm-docs/pull/4530 The 0.36.0 release notes and the /**
* @deprecated The third parameter of pgTable is changing and will only accept an array instead of an object
*
* @example
* Deprecated version:
* ```ts
* export const users = pgTable("users", {
* id: integer(),
* }, (t) => ({
* idx: index('custom_name').on(t.id)
* }));
* ```
*
* New API:
* ```ts
* export const users = pgTable("users", {
* id: integer(),
* }, (t) => [
* index('custom_name').on(t.id)
* ]);
* ```
*/ The bug here seems to be a type issue with the new function signature, as import { pgTable, text } from 'drizzle-orm/pg-core'
export const test = pgTable(
'test',
{
id: text('id').primaryKey().notNull(),
},
(t) => [{ one: 2 }, false, 1, new Set()],
) |
The docs have been updated to reflect the new syntax for declaring constraints. |
Report hasn't been filed before.
What version of
drizzle-orm
are you using?0.36.3
What version of
drizzle-kit
are you using?0.28.1
Other packages
No response
Describe the Bug
What is the undesired behavior?
When I return an array from pgTable callback, composite primary key not adds to my schema in postgres. but without array it works.
steps to reproduce
the code below not create primary key in postgress:
export const postOnCategories = pgTable(
"post_categories",
{
postId: serial("post_id")
.notNull()
.references(() => posts.id),
categoryId: serial("category_id")
.notNull()
.references(() => categories.id),
},
(table) => [
{
pk: primaryKey({ columns: [table.postId, table.categoryId] }),
},
]
);
result:

but old way of returning an object works properly:
export const postOnCategories = pgTable(
"post_categories",
{
postId: serial("post_id")
.notNull()
.references(() => posts.id),
categoryId: serial("category_id")
.notNull()
.references(() => categories.id),
},
(table) => ({
pk: primaryKey({ columns: [table.postId, table.categoryId] }),
})
);
The text was updated successfully, but these errors were encountered: