Skip to content

feat: Support lossless JSON <-> JSONB column type migration - #4989

Merged
marcelomendoncasoares merged 7 commits into
serverpod:mainfrom
developerjamiu:feat/json-jsonb-migration
Apr 24, 2026
Merged

marcelomendoncasoares merged 7 commits into
serverpod:mainfrom
developerjamiu:feat/json-jsonb-migration

Conversation

@developerjamiu

@developerjamiu developerjamiu commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Adds lossless JSON ↔ JSONB column type migration support. When a developer changes a serializable field between json and jsonb, the migration engine now emits cast-based SQL instead of dropping and recreating the table.

Split from PR #4960 per reviewer suggestion. Refs #3919.

PostgreSQL:

ALTER TABLE "my_table" ALTER COLUMN "data"
  SET DATA TYPE jsonb USING "data"::jsonb;

SQLite (during table rebuild):

INSERT INTO "new_my_table" (..., data)
  SELECT ..., jsonb("data") FROM "my_table";

Behavior:

  • No --force required - the migration is lossless
  • No warnings emitted - json and jsonb are safely castable in both directions
  • Data is fully preserved through the migration
  • GIN indexes are automatically dropped/recreated as part of the table definition diff

Closes #4985

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.

@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.

Nice work, @developerjamiu! Changes are in the right places and the feature is well covered. Have just some small comments for improvement, mainly on the tests.

@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.

Only two more small improvements to the tests and we're good to go!

@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.

LGTM! Great work with this feature, @developerjamiu!! 🚀

@developerjamiu

Copy link
Copy Markdown
Contributor Author

LGTM! Great work with this feature, @developerjamiu!! 🚀

Thank you 🙌

@developerjamiu
developerjamiu force-pushed the feat/json-jsonb-migration branch from 82d4135 to 2df6bf4 Compare April 24, 2026 03:40
@marcelomendoncasoares
marcelomendoncasoares merged commit e90c71e into serverpod:main Apr 24, 2026
79 of 81 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 24, 2026
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 lossless JSON <-> JSONB column type migration

2 participants