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
24.94k stars 1.59k forks source link

Max identifier length for table or enum is achieved to fast, it restricts nested schema creation #8501

Closed ivan-kardash closed 1 month ago

ivan-kardash commented 1 month ago

Link to reproduction

No response

Environment Info

Binaries:
  Node: 20.17.0
Relevant Packages:
  payload: 3.0.0-beta.100
  next: 15.0.0-canary.104
  @payloadcms/db-postgres: 3.0.0-beta.100
  @payloadcms/email-nodemailer: 3.0.0-beta.100
  @payloadcms/graphql: 3.0.0-beta.100
  @payloadcms/next/utilities: 3.0.0-beta.100
  @payloadcms/plugin-cloud: 3.0.0-beta.100
  @payloadcms/richtext-lexical: 3.0.0-beta.100
  @payloadcms/translations: 3.0.0-beta.100
  @payloadcms/ui/shared: 3.0.0-beta.100
  react: 19.0.0-rc-06d0b89e-20240801
  react-dom: 19.0.0-rc-06d0b89e-20240801

Describe the Bug

If the global has a schema like this:

export const mobileContactsConfig: GlobalConfig = {
  ...
  dbName: 'v2-mobile-config',
}

I enough added several nested fields to achieve db length name restriction and get error like this:

Error: Exceeded max identifier length for table or enum name of 63 characters. Invalid name: enum_v2_mobile_config_side_menu_mob_sid_men_items_playerstatus_long_name

I understand that the drizzle restricts it, and finally, it is restricted by PostgreSQL, in its turn. But it looks like a simple join of names to get tableName is not the best algorithm while we have a restriction of 63 characters.

Reproduction Steps

Create schema with total nested fields length of name more than 63 characters

Adapters and Plugins

db-postgres

r1tsuu commented 1 month ago

We won't change how enum / table names are generated in the DB, also I think it works fine. In cases like this to get around you can use enumName property for select / radio fields: https://payloadcms.com/docs/beta/fields/select#config-options For example:

 enumName: ({tableName}) => 'custom_enum_name',

For arrays / blocks / hasMany select you can use dbName instead.

github-actions[bot] commented 1 month ago

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