Skip to content
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

powersync_client_id() / powersync_last_synced_at() / powersync_clear() #21

Merged
merged 7 commits into from
Aug 21, 2024

Conversation

rkistner
Copy link
Contributor

@rkistner rkistner commented Aug 20, 2024

Add support for:

powersync_client_id()

This returns an unique uuid per client. This is configured once when initializing the powersync tables.

This allows us to:

  1. Identify individual syncing clients, instead of just users. This will make it easier to notice issues such as multiple concurrent connections for the same client.
  2. Track write checkpoints per client instead of per user.

A new optional parameter will be added to the protocol for this.

powersync_last_synced_at()

This returns a persisted timestamp of the last synced at time. This should replace the SELECT 1 FROM ps_buckets WHERE last_applied_op > 0 LIMIT 1 query currently used in clients, and will work even when no data was synced.

powersync_clear()

This clears the database. select powersync_clear(1) to delete everything, select powersync_clear(0) to preserve local tables.

For the new ps_kv table, this clears last_synced_at, but not client_id.

This contains a workaround to trigger one update notification for each table, while still using the sqlite truncate optimization for the majority of rows.

This should replace the delete logic that is currently implemented in each client separately.

Internals

This now implements down migrations, which allows a developer to downgrade the SDK to older versions.

powersync_client_id and powersync_last_synced_at are both stored in a new ps_kv table.

Tests for the new functionality are implemented here: powersync-ja/powersync.dart#148

This PR removes lots of unused (incomplete) code, and fixes some lint issues.

@rkistner rkistner requested a review from mugikhan August 20, 2024 14:19
@rkistner rkistner self-assigned this Aug 20, 2024
Copy link
Contributor

@mugikhan mugikhan left a comment

Choose a reason for hiding this comment

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

Looks good!

@rkistner rkistner merged commit 2e6a43e into main Aug 21, 2024
11 checks passed
@rkistner rkistner deleted the client-id branch August 21, 2024 07:09
This was referenced Aug 21, 2024
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