xataio / client-ts

Xata.io SDK for TypeScript and JavaScript
https://xata.io/docs/sdk/typescript/overview
Apache License 2.0
123 stars 8 forks source link

PayloadCMS: type "serial" does not exist #1465

Closed j-mcgregor closed 3 months ago

j-mcgregor commented 6 months ago

Describe the bug

First off, love Xata! We want to adapt it into our full code base and it works for everything except for PayloadCMS. I've left comments on relevant PayloadCMS issues.

After creating a new Postgres-enabled database and storing the DATABASE_URI with fresh API key, I try and spin up a new payload (beta) app. 2 things then happen:

 ⨯ Internal error: error: unknown statement [<nil>] on regular level, see https://xata.io/sql-support for the support matrix
    at /root/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async DrizzleORMPgClient.query (/root/node_modules/drizzle-kit/payload.js:34498:21)
    at async apply (/root/node_modules/drizzle-kit/payload.js:36648:9)
    at async pushDevSchema (../../node_modules/@payloadcms/db-postgres/dist/utilities/pushDevSchema.js:47:5)
    at async Object.connect (../../node_modules/@payloadcms/db-postgres/dist/connect.js:84:5)
    at async BasePayload.init (../../node_modules/payload/dist/index.js:215:13)
 ⨯ Internal error: error: type "serial" does not exist
    at /root/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async DrizzleORMPgClient.query (/root/node_modules/drizzle-kit/payload.js:34498:21)
    at async apply (/root/node_modules/drizzle-kit/payload.js:36648:9)
    at async pushDevSchema (../../node_modules/@payloadcms/db-postgres/dist/utilities/pushDevSchema.js:47:5)
    at async Object.connect (../../node_modules/@payloadcms/db-postgres/dist/connect.js:84:5)
    at async BasePayload.init (../../node_modules/payload/dist/index.js:215:13)

I'm guessing its a version / pg flavour mismatch but I don't know

To Reproduce

  1. Create a postgres-enabled Xata database and copy the API key-populated Database URI
  2. Install beta Payload app: npx create-payload-app@beta and paste the URI into the terminal when prompted
  3. Run the app
  4. In the Xata UI, you should see an option pop up (in the schema panel or individual tables) to allow Xata to make the necessary changes
  5. Bug 2 should appear in the terminal

Expected behavior

I should be able to use Xata Postgres for my PayloadCMS database

Software version

// package json
"dependencies": {
    "@payloadcms/db-postgres": "beta",
    "@payloadcms/next": "beta",
    "@payloadcms/plugin-cloud": "beta",
    "@payloadcms/richtext-lexical": "beta",
    "cross-env": "^7.0.3",
    "next": "^14.3.0-canary.7",
    "payload": "beta",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "sharp": "0.32.6"
  },
  "devDependencies": {
    "@types/node": "^20.11.25",
    "@types/react": "^18.2.64",
    "@types/react-dom": "^18.2.21",
    "dotenv": "^16.4.5",
    "tsx": "^4.7.1",
    "typescript": "^5.4.2"
  },

Additional context

I'm following up enquiries with Payload too. Since both Xata and Payload features right now are in beta, I know its a longshot but you lot seem like wizards so thought I'd ask

karranx commented 3 months ago

I am not using xata yet getting the "serial does not exist error" so maybe its something with payload itself. Did you find a fix?

SferaDev commented 3 months ago

I'm going to close this issue as it's fixed, thanks for the bump.

PayloadCMS uses drizzle behind the scenes for Postgres connection, we worked with Drizzle and they fixed the problem with serial types in their codebase.

@karranx Are you using Drizzle by any chance, wave you updated to a recent version?

karranx commented 3 months ago

@SferaDev i am using payload. the issue was on my end. i had conflicting table names.