Skip to content

Add helper function to fix JS subkey encoding #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025
Merged

Conversation

simolus3
Copy link
Contributor

When forwarding data lines to the core extension, our JS SDK would encode subkey values as JSON (before encoding the rest of the message as JSON too).

This means that ps_oplog.key entries created by the JS SDK look like foo/bar/"baz", while all other SDKs are using foo/bar/baz directly. To prepare the adoption of the Rust sync client in the JS SDK (and for consistency with our other SDKs), we have to migrate ps_oplog entries.
The migration will happen in the JS SDK since it's the only SDK affected by this. However, the logic to strip the JSON encoding is not really expressible with builtin SQL functions alone, so this adds a powersync_remote_duplicate_key_encoding that detects improper " keys to remove them.

The idea is that the JS SDK would use an entry in ps_kv to detect whether a migration has ran and, if it hasn't, run UPDATE ps_oplog SET key = powersync_remote_duplicate_key_encoding(key); when opening the database.

@simolus3 simolus3 requested a review from rkistner May 19, 2025 11:46
@simolus3 simolus3 merged commit 087b0cb into main May 20, 2025
21 checks passed
@simolus3 simolus3 deleted the fix-key-encoding branch May 20, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants