feat(db-postgres): optionally allow to store blocks as JSON and add support for "in" operator within richText #6245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds option to store blocks as JSON column in Postgres with
storeBlocksAsJSON
property for the adapter.While i like that you guys choose a hard, traditional way in implementing blocks with SQL, i think this may be not for everyone.
I like the strict approach to a schema when we talk about things like Users, Products, Orders etc.
But when it comes to a sites content it's different, not only that we can have too much things here (resulting into long table / constraints names, many joins on
SELECT
), it could also be changed frequently and you need to deal with a big migrations.With Lexical blocks feature - they are stored in the same way, so i guess it's fine to allow that here too?
This PR also adds support for querying with
in
operator onrichText
and as wellblocks
when it's JSON.This was done in order to pass as many tests as i can with
storeBlocksAsJSON
. And here's the result for "fields -> blocks"Yes, not great here with querying on richtext, which is nested to already json blocks.
If this is something that will block this PR to merge, i have an idea on how we can improve overall our JSON queries, it could work for any nested structure. And JSON blocks, blocks in Lexical will work too.
This in theory could be achieved with this query:
Why? we don't know in runtime, is current key object or array, because we don't know the structure when dealing with JSON field type. But with this Postgres JSON query way we can determine that.
In any way whatever separated PR or here i want to try implement this, because for now JSON / RichText querying isn't great in Payload.
p.s wrong base branch caused first commit, i reverted it.
Type of change
Checklist:
storeBlocksAsJSON: true
3 tests are failing.