Skip to content

feat: Add jsonb column support and GIN index operator classes - #4960

Merged
marcelomendoncasoares merged 65 commits into
serverpod:mainfrom
developerjamiu:feat/jsonb-support
Apr 22, 2026
Merged

marcelomendoncasoares merged 65 commits into
serverpod:mainfrom
developerjamiu:feat/jsonb-support

Conversation

@developerjamiu

@developerjamiu developerjamiu commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Adds JSONB column support for serializable fields, configurable at project/class/field level, with GIN indexes and operator class support.

Carries forward @borutjures's original PR #3934 (32 commits preserved) and resolves all 7 review items from the Sep 23 review. Based on alignment call with @marcelomendoncasoares on 2026-04-08.

Main architectural change: refactored serialization config resolution from top-down to bottom-up three-pass (field → class → project), each pass isolated to its own level. Also adds SQLite dialect support (merged after original PR stalled), GIN-on-non-jsonb validation, and a copyWithPrefix bug fix that was silently dropping operator classes on inherited indexes.

Usage:

# model - field-level
class: Product
table: product
fields:
  tags: List<String>, serializationDataType=jsonb
indexes:
  tags_gin:
    fields: tags
    type: gin # optional - defaults to gin for jsonb-only indexes
    operatorClass: jsonbPathOps # optional - defaults to jsonbOps

# model - class-level (applies to all serializable fields)
class: Product
table: product
serializationDataType: jsonb
fields:
  tags: List<String>
  metadata: Map<String, String>

# project-level (config/generator.yaml - applies to all models)
serialize_as_jsonb_by_default: true

Known limitation: migrating an existing json column to jsonb triggers a destructive warning and requires --force or a manual ALTER COLUMN TYPE. Matches existing integer ↔ bigint precedent; auto-generating the ALTER is a reasonable follow-up.

Closes #3919, Closes #3934

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else.
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

Breaking changes

None.

…ve serializeAsJsonbAsDefault from experimental feature to CLI config; merge _buildModelTableCustomSerializedFieldTypeReference() into _buildModelTableGeneralFieldExpression()
# Conflicts:
#	packages/serverpod/lib/src/database/adapters/postgres/database_connection.dart
#	tests/serverpod_test_client/lib/src/protocol/client.dart
#	tests/serverpod_test_client/lib/src/protocol/protocol.dart
#	tests/serverpod_test_server/lib/src/generated/endpoints.dart
#	tests/serverpod_test_server/lib/src/generated/protocol.dart
#	tests/serverpod_test_server/test_integration/test_tools/serverpod_test_tools.dart
#	tools/serverpod_cli/lib/src/analyzer/models/yaml_definitions/class_yaml_definition.dart
…keyword; add class-level ValidateNode for the serializationDataType keyword
@developerjamiu

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

# Conflicts:
#	tools/serverpod_cli/lib/src/config/config.dart
#	tools/serverpod_cli/lib/src/config/experimental_feature.dart
@developerjamiu
developerjamiu marked this pull request as ready for review April 15, 2026 16:07

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work with the PR, @developerjamiu!! All comments from the other PR were correctly addressed. Besides comments for improvement on the implementation and tests, there are two main points that are still not completely addressed:

  • Proper support for JSONB as BLOB on SQLite (with integration tests).
  • Migration support between JSON <-> JSONB (with migration e2e tests).

There is also one small change in the direction of the original implementation that I put for discussion below to create a new ColumnStructured instead of storing a serializationDataType field on the ColumnSerializable.

About the migration support, although it must be in for the feature to be complete, if you're ok with it, I'd suggest we create an issue and split the work to a follow-up PR to avoid bloating this one too much.

@developerjamiu

Copy link
Copy Markdown
Contributor Author

Great work with the PR, @developerjamiu!! All comments from the other PR were correctly addressed. Besides comments for improvement on the implementation and tests, there are two main points that are still not completely addressed:

  • Proper support for JSONB as BLOB on SQLite (with integration tests).
  • Migration support between JSON <-> JSONB (with migration e2e tests).

There is also one small change in the direction of the original implementation that I put for discussion below to create a new ColumnStructured instead of storing a serializationDataType field on the ColumnSerializable.

About the migration support, although it must be in for the feature to be complete, if you're ok with it, I'd suggest we create an issue and split the work to a follow-up PR to avoid bloating this one too much.

Thanks for the thorough review! Agreed on all three main points:

For the remaining comments: I'll push changes and resolve each conversation as addressed.

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job with the changes, @developerjamiu! A few more comments and we should be ready to merge.

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work with this PR, @developerjamiu! LGTM 🚀

I have only one nit comment about the placement of the default resolution to get even closer to the fields resolution, but feel free to address or merge directly.

@marcelomendoncasoares
marcelomendoncasoares merged commit 09e82d9 into serverpod:main Apr 22, 2026
80 of 82 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 22, 2026
@developerjamiu
developerjamiu deleted the feat/jsonb-support branch April 22, 2026 15:55
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 this pull request may close these issues.

Support for jsonb indexable columns

3 participants