Helpers to move between raw tables and ps_untyped#189
Open
simolus3 wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With the
_restcolumn pattern andpowersync_trigger_resync, we have pretty decent tools integrating PowerSync into migrations altering existing tables.However, steps to create and drop raw tables could still be simplified a bit:
ps_untypedinto the raw table. We forgot to mention that moved rows should also be removed fromps_untypedafterwards (Room integration: Pre-sync data not applied to new tables after upgrade powersync-kotlin#355).ps_untypedbefore dropping raw tables. We have no documentation on this at all.Both steps can be automated fairly easily: For 1, we can use the exact same logic we use in a
sync_localstep to parse the oplog JSON structure fromps_untypedthrough the (inferred or explicit)putstatement, which copies it into the raw table.For 2, we can use the existing logic we have to create crud triggers to JSON-ify table contents and write them back into
ps_untyped.Can't we do this implicitly?
Initially, I thought we could this in
powersync_init()/powersync_update_schema(), just like we auto-migrate views:Even 1 breaks in practice because depending on the SDK, users might first call
powersync_initwith the raw table already in the schema before usingexecute()APIs in SDKs to actually create the raw table.So, this PR adds an explicit function for this,
powersync_raw_table_migrate. It's supposed to be called like this:powersync_raw_table_migrate('create', 'name_of_raw_table_in_sync_streams')to move data fromps_untyped.ps_untyped).AI use disclaimer: Parts of the implementation and most tests were generated with Claude.