payload icon indicating copy to clipboard operation
payload copied to clipboard

Postgres Index Name too long

Open javve opened this issue 1 year ago • 1 comments

Link to reproduction

No response

Describe the Bug

Payload asked me this question, and even if I accepted, I still got the message the next time I restarted the server.

You're about to add pages_blocks_highlight_list_block_locales_locale_parent_id_unique 
unique constraint to the table, which contains 4 items. 
If this statement fails, you will receive an error from the database. 
Do you want to truncate pages_blocks_highlight_list_block_locales table?

It turns out that Postgres index name is a maximum of 63 characters long. https://til.hashrocket.com/posts/8f87c65a0a-postgresqls-max-identifier-length-is-63-bytes https://www.postgresql.org/message-id/[email protected]

So, in this case, an index named pages_blocks_highlight_list_block_locales_locale_parent_id_uni (note the missing chars) was created, but Payload did not realise this, so it continued to ask me the same question over and over.

To Reproduce

I think it should be enough to add a block in a table with a name longer than 63 characters.

Payload Version

2.12.1

Adapters and Plugins

db-postgres

javve avatar Apr 23 '24 16:04 javve

Thanks, this helped me figure out a workaround by shorten the field names.

madaxen86 avatar May 10 '24 17:05 madaxen86

This was addressed by allowing you to customize the dbName of tables/fields where necessary. This has been introduced in both 2.x and 3.0 beta a while back. https://payloadcms.com/docs/configuration/collections#options:~:text=g.%20for%20plugins)-,dbName,-Custom%20table%20or

We also did a refactor for index names which should avoid this problem for a great many cases where it was an issue before.

Closing as this is the best workaround for now. Thanks!

DanRibbens avatar Jul 24 '24 18:07 DanRibbens

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

github-actions[bot] avatar Sep 07 '24 00:09 github-actions[bot]