payloadcms / payload

The best way to build a modern backend + admin UI. No black magic, all TypeScript, and fully open-source, Payload is both an app framework and a headless CMS.
https://payloadcms.com
MIT License
21.1k stars 1.27k forks source link

feat(db-postgres): fields enhancements #6983

Open r1tsuu opened 4 days ago

r1tsuu commented 4 days ago

Description

The PR adds:

Field config - dbStore

dbStore field property - removes schema creation for a field. Currently using Virtual Fields with Postgres bloats the db with unused columns / tables, as well may join empty arrays / blocks that are meant to be "Virtual". Realted discussion - https://github.com/payloadcms/payload/discussions/6270

Field config - dbJsonColumn

dbJsonColumn field property - stores a field, that should create additional tables (hasMany Text / Number / Select, Array / Blocks, Polymorphic / hasMany relationships) as a simple jsonb column.

Advantages

Considerations:

My thoughts: I haven't ever query on a blocks field, so i don't see a point of adding so much complexity just because of this.

Passing defaultValue into a DB schema

Non undefined and non function defaultValue is passed into a column builder. This 100% syncs defaultValue with a database and resolves a problem when adding a required field into a collection with existing docs, currently you can't do that unless you: lose data / modify migration manually. Discussions: https://github.com/payloadcms/payload/discussions/6691 https://github.com/payloadcms/payload/discussions/6048

dbType for Number field

Accepts: 'integer' | 'bigint' | 'real' | 'numeric' Simply stores number field in a specified column, by default numeric.

According to Postgres documentation calculations on numeric values are very slow compared to the integer types, or to the floating-point types.

Adds default validation with Number.isInteger.

Checklist:

ryanleecode commented 4 days ago

Goat