Skip to content

Postgres Adapter throws error: relation "users" does not exist on Production Builds and Local API #6244

@emonadeo

Description

@emonadeo

Link to reproduction

No response

Describe the Bug

The Postgres Adapter errors due to missing relations (specifically users, but others error as well when queried using the Local API), either using the Local API or the built nextjs admin panel.

This only errors if next dev has never been run.
I assume running next dev seeds the postgres database so from that point on both the local api, and the admin panel are able to resolve the postgres relations. However this should be able work without seeding the database.

To Reproduce

  1. Clone and cd into payloadcms/payload-3.0-demo
  2. Run pnpm install
  3. Use Postgres:
    // payload.config.ts
    import { postgresAdapter } from '@payloadcms/db-postgres'
    export default buildConfig({
      // ...
      db: postgresAdapter({
        pool: {
          connectionString: process.env.POSTGRES_URI || '',
        },
      })
      // ...
    })
  4. Start the database:
    $ ./start-database.sh
    
  5. Build it:
    $ PAYLOAD_SECRET=secret POSTGRES_URI=postgresql://postgres:password@127.0.0.1:5432/next-payload-3 pnpm build
    
    This already errors because my-route tries to query the empty postgres database:
    error: relation "users" does not exist
    
  6. Remove my-route:
    $ rm -rf src/app/my-route
    
  7. Build it again:
    $ pnpm build
    
  8. Start it:
    $ PAYLOAD_SECRET=secret POSTGRES_URI=postgresql://postgres:password@127.0.0.1:5432/next-payload-3 pnpm start
    
  9. Navigate to http://localhost:3000/admin and receive the same error.

Payload Version

3.0

Adapters and Plugins

db-postgres

Metadata

Metadata

Assignees

Labels

db: postgres@payloadcms/db-postgresstatus: needs-triagePossible bug which hasn't been reproduced yet

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions