Skip to content
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

Database migration from Mongo to Postgres throwing type error in existing files. #9565

Closed
robinnicholasraja opened this issue Nov 27, 2024 · 2 comments · Fixed by #9568
Closed

Comments

@robinnicholasraja
Copy link

Describe the Bug

I'm working on a multi-tenancy project by following this example here.
and it works fine.

Then later I shifted the database from Mongo to Postgres and got a lot of type errors and bugs. I think it will be better to have a proper type check even if we switch the database

Sample screenshots:

Throwing type error while getting the TenantAccessIDs (Unable to login as tenant-admin)

Image

Throws undefined in the getTenantAccessIDs function

Image

Select tenant dropdown value is not updating properly.

Image

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/tree/main/examples/multi-tenant

Reproduction Steps

Follow the readme from this example - https://github.com/payloadcms/payload/tree/main/examples/multi-tenant

Try switching the database from MongoDB to Postgres

Note: I even got some errors in seeding. Then this is what I did, remove ensureUniqueUsername from this path(examples/multi-tenant/src/collections/Users/index.ts) then delete the multi-admin creation from seed.ts then migrate:create followed by migrate:fresh

Which area(s) are affected? (Select all that apply)

db-postgres

Environment Info

payload:
    specifier: latest
    version: 3.1.1(graphql@16.9.0)(monaco-editor@0.52.0)(react-dom@19.0.0-rc-65a56d0e-20241020)(react@19.0.0-rc-65a56d0e-20241020)(typescript@5.6.3),

next: 15.0.0,

pnpm: 9.14.2
@robinnicholasraja robinnicholasraja added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Nov 27, 2024
jacobsfletch pushed a commit that referenced this issue Nov 27, 2024
Fixes #9565 multi-tenant
compatibility with Postgres (and custom IDs)

Adds a useful `extractID` utility:
```ts
import { Config } from '@/payload-types'
import type { CollectionSlug } from 'payload'

export const extractID = <T extends Config['collections'][CollectionSlug]>(
  objectOrID: T | T['id'],
): T['id'] => {
  if (objectOrID && typeof objectOrID === 'object') return objectOrID.id

  return objectOrID
}
```
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Nov 27, 2024
Copy link
Contributor

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 29, 2024
Copy link
Contributor

🚀 This is included in version v3.2.2

@github-actions github-actions bot unlocked this conversation Nov 29, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 2024
kendelljoseph pushed a commit that referenced this issue Feb 21, 2025
Fixes #9565 multi-tenant
compatibility with Postgres (and custom IDs)

Adds a useful `extractID` utility:
```ts
import { Config } from '@/payload-types'
import type { CollectionSlug } from 'payload'

export const extractID = <T extends Config['collections'][CollectionSlug]>(
  objectOrID: T | T['id'],
): T['id'] => {
  if (objectOrID && typeof objectOrID === 'object') return objectOrID.id

  return objectOrID
}
```
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant