payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
23.14k stars 1.45k forks source link

Can't import demo page preset with PostgreSQL 16 #7039

Open LordSimal opened 2 months ago

LordSimal commented 2 months ago

Link to reproduction

No response

Describe the Bug

When trying to create a fresh installation of the payload app with the demo page preset it can't import/seed the postgresql database.

To Reproduce

This will lead to the following output/error:

~/payload» pnpm run build                                                                                                                                                                                                                     [16:46:47]

> .@1.0.0 build /my/absolute/path/payload
> cross-env NODE_ENV=production pnpm build:payload && pnpm build:server && pnpm copyfiles && pnpm build:next

> .@1.0.0 build:payload /my/absolute/path/payload
> cross-env PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload build

> .@1.0.0 build:server /my/absolute/path/payload
> tsc --project tsconfig.server.json

> .@1.0.0 copyfiles /my/absolute/path/payload
> copyfiles -u 1 "src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}" dist/

> .@1.0.0 build:next /my/absolute/path/payload
> cross-env PAYLOAD_CONFIG_PATH=dist/payload/payload.config.js NEXT_BUILD=true node dist/server.js

[16:47:08] INFO (payload): Starting Payload...
[16:47:08] INFO (payload): Payload Admin URL: http://localhost:3000/admin
[16:47:08] INFO (payload): Seeding database...
[16:47:08] INFO (payload): — Clearing media...
[16:47:08] INFO (payload): — Clearing collections and globals...
[16:47:09] INFO (payload): — Seeding demo author and user...
error: invalid input syntax for type timestamp with time zone: ""
    at /my/absolute/path/payload/node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/client.js:526:17
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /my/absolute/path/payload/node_modules/.pnpm/drizzle-orm@0.29.3_@libsql+client@0.3.6_@types+react@18.3.3_pg@8.11.3_react@18.3.1/node_modules/drizzle-orm/node-postgres/session.cjs:81:22
    at async upsertRow (/my/absolute/path/payload/node_modules/.pnpm/@payloadcms+db-postgres@0.8.5_@types+react@18.3.3_payload@2.23.1_@swc+helpers@0.5.5_@types+re_7ynksvd3t6jkdwjm2ejrkjmp2i/node_modules/@payloadcms/db-postgres/dist/upsertRow/index.js:49:29)
    at async Object.create (/my/absolute/path/payload/node_modules/.pnpm/@payloadcms+db-postgres@0.8.5_@types+react@18.3.3_payload@2.23.1_@swc+helpers@0.5.5_@types+re_7ynksvd3t6jkdwjm2ejrkjmp2i/node_modules/@payloadcms/db-postgres/dist/create.js:22:20)
    at async create (/my/absolute/path/payload/node_modules/.pnpm/payload@2.23.1_@swc+helpers@0.5.5_@types+react@18.3.3_esbuild@0.19.12_typescript@5.2.2_webpac_4ctwszy5cpauz6kb5e4zmf335y/node_modules/payload/dist/collections/operations/create.js:169:19) {
  length: 158,
  severity: 'ERROR',
  code: '22007',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: "unnamed portal parameter $4 = ''",
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'datetime.c',
  line: '4015',
  routine: 'DateTimeParseError'
}
  ▲ Next.js 14.2.4
  - Environments: .env

[16:47:10] INFO (payload): — Seeding media...
[16:47:10] ERROR (payload): Error seeding database.

I am on PostgreSQL 16.3 and NodeJS 20.15.0

Payload Version

2.23.1

Adapters and Plugins

db-postgres

devwithjsantos commented 1 month ago

Are there any workarounds?

DanRibbens commented 1 month ago

Payload should handle converting dates for you. There may have been a regression in the recent db work made to get ready to release sqlite.

A workaround is to send any dates as string by calling .toISOString().

EDIT: I didn't notice before that this is for v2. I bet it is fixed in v3. @JessChowdhury if this is something you want to take, look at the recent changes in https://github.com/payloadcms/payload/blob/beta/packages/drizzle/src/transform/write/traverseFields.ts#L544

waelhassine commented 1 month ago

Try to update node and npm to latest version