Generated DB Schema `pgTable` Syntax is Deprecated
Closed this issue · 3 comments
Describe the Bug
Using payload generate:db-schema the schema is generated using deprecated syntax:
export const products = pgTable(
"products",
{
id: serial("id").primaryKey(),
name: varchar("name"),
description: jsonb("description"),
price: numeric("price"),
category: integer("category_id").references(() => categories.id, {
onDelete: "set null",
}),
saddle: integer("saddle_id").references(() => saddles.id, {
onDelete: "set null",
}),
updatedAt: timestamp("updated_at", {
mode: "string",
withTimezone: true,
precision: 3,
})
.defaultNow()
.notNull(),
createdAt: timestamp("created_at", {
mode: "string",
withTimezone: true,
precision: 3,
})
.defaultNow()
.notNull(),
},
(columns) => ({
products_category_idx: index("products_category_idx").on(columns.category),
products_saddle_idx: index("products_saddle_idx").on(columns.saddle),
products_updated_at_idx: index("products_updated_at_idx").on(
columns.updatedAt,
),
products_created_at_idx: index("products_created_at_idx").on(
columns.createdAt,
),
}),
);Note in VSCode:
@deprecated — The third parameter of pgTable is changing and will only accept an array instead of an object
@example
Deprecated version:
export const users = pgTable("users", {
id: integer(),
}, (t) => ({
idx: index('custom_name').on(t.id)
}));
New API:
export const users = pgTable("users", {
id: integer(),
}, (t) => [
index('custom_name').on(t.id)
]);Link to the code that reproduces this issue
https://github.com/Dan6erbond/deprecated-drizzle-orm-schema
Reproduction Steps
- Run
payload generate:db-schemaafter declaring some collections. - Check the generated
src/payload-generated-schema.tsto see the deprecated syntax.
Which area(s) are affected? (Select all that apply)
db-postgres
Environment Info
Binaries:
Node: 22.14.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
payload: 3.57.0
next: 15.4.4
@payloadcms/db-postgres: 3.57.0
@payloadcms/email-nodemailer: 3.57.0
@payloadcms/graphql: 3.57.0
@payloadcms/next/utilities: 3.57.0
@payloadcms/plugin-cloud-storage: 3.57.0
@payloadcms/plugin-seo: 3.57.0
@payloadcms/richtext-lexical: 3.57.0
@payloadcms/storage-s3: 3.57.0
@payloadcms/translations: 3.57.0
@payloadcms/ui/shared: 3.57.0
react: 19.1.1
react-dom: 19.1.1
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Home
Available memory (MB): 64630
Available CPU cores: 16
I know about this, the reason it wasn't changed is because it could be a breaking change, since we support modifying the schema with the schema hooks https://payloadcms.com/docs/database/postgres#drizzle-schema-hooks including indexes. And since it changes an object to an array - those who modify indexes via a hook would likely need to change their implementation a bit as well.
^ Actually for the generated schema it doesn't matter, since it's not a runtime thing. Opened #14031
This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.