Skip to content

Sync streams #112

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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
087bad1
Start adding support for sync streams
simolus3 Jun 19, 2025
7960a6d
Add protocol changes
simolus3 Jul 1, 2025
2d30b48
Use serde_with
simolus3 Jul 1, 2025
1a1e973
Start with subscription logic
simolus3 Jul 2, 2025
e3c834f
Start tracking subscriptions
simolus3 Jul 3, 2025
de660b1
Track subscriptions
simolus3 Jul 4, 2025
c9ddc78
Test handling default streams
simolus3 Jul 9, 2025
12a16d5
Update last_synced_at for subscriptions
simolus3 Jul 9, 2025
8dd0267
Allow subscribing to streams
simolus3 Jul 10, 2025
45b8364
Expire subscriptions after TTL
simolus3 Jul 14, 2025
3a9821b
Support unsubscribing
simolus3 Jul 14, 2025
3bb34a6
Delete outdated subscriptions
simolus3 Jul 14, 2025
1c15125
Include default ttl
simolus3 Jul 14, 2025
3e22712
New protocol format
simolus3 Jul 15, 2025
4fd3d80
Fix tests
simolus3 Jul 22, 2025
57394c0
More stream management tests
simolus3 Jul 22, 2025
0aa973a
Remove immediate parameter when unsubscribing
simolus3 Jul 22, 2025
4d229c8
Increase expires_at only when subscribing again
simolus3 Jul 22, 2025
cb07da4
Implement new protocol format
simolus3 Aug 7, 2025
0e2b14d
Report errors
simolus3 Aug 7, 2025
0c63d69
Update TTL behavior
simolus3 Aug 12, 2025
8ca9bfc
Refresh on keepalive
simolus3 Aug 12, 2025
bcb3c1b
Instruction to update expiry
simolus3 Aug 13, 2025
b33dd61
Add correct offline state
simolus3 Aug 13, 2025
72f88ba
Add offline sync state helper function
simolus3 Aug 13, 2025
c16edad
Simplify error reporting
simolus3 Aug 13, 2025
bb21028
Improve comment
simolus3 Aug 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const_format = "0.2.34"
futures-lite = { version = "2.6.0", default-features = false, features = ["alloc"] }
rustc-hash = { version = "2.1", default-features = false }
thiserror = { version = "2", default-features = false }
serde_with = { version = "3.14.0", default-features = false, features = ["alloc", "macros"] }

[dependencies.uuid]
version = "1.4.1"
Expand Down
25 changes: 24 additions & 1 deletion crates/core/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::error::{PSResult, PowerSyncError};
use crate::fix_data::apply_v035_fix;
use crate::sync::BucketPriority;

pub const LATEST_VERSION: i32 = 10;
pub const LATEST_VERSION: i32 = 11;

pub fn powersync_migrate(
ctx: *mut sqlite::context,
Expand Down Expand Up @@ -384,5 +384,28 @@ INSERT INTO ps_migration(id, down_migrations) VALUES (10, json_array(
.into_db_result(local_db)?;
}

if current_version < 11 && target_version >= 11 {
let stmt = "\
CREATE TABLE ps_stream_subscriptions (
id INTEGER NOT NULL PRIMARY KEY,
stream_name TEXT NOT NULL,
active INTEGER NOT NULL DEFAULT FALSE,
is_default INTEGER NOT NULL DEFAULT FALSE,
local_priority INTEGER,
local_params TEXT NOT NULL DEFAULT 'null',
ttl INTEGER,
expires_at INTEGER,
last_synced_at INTEGER,
UNIQUE (stream_name, local_params)
) STRICT;

INSERT INTO ps_migration(id, down_migrations) VALUES(11, json_array(
json_object('sql', 'DROP TABLE ps_stream_subscriptions'),
json_object('sql', 'DELETE FROM ps_migration WHERE id >= 11')
));
";
local_db.exec_safe(stmt).into_db_result(local_db)?;
}

Ok(())
}
7 changes: 5 additions & 2 deletions crates/core/src/sync/checkpoint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use alloc::{string::String, vec::Vec};
use alloc::{rc::Rc, string::String, vec::Vec};
use num_traits::Zero;

use crate::sync::{BucketPriority, Checksum, line::BucketChecksum};
use crate::sync::line::{BucketChecksum, BucketSubscriptionReason};
use crate::sync::{BucketPriority, Checksum};
use sqlite_nostd::{self as sqlite, Connection, ResultCode};

/// A structure cloned from [BucketChecksum]s with an owned bucket name instead of one borrowed from
Expand All @@ -12,6 +13,7 @@ pub struct OwnedBucketChecksum {
pub checksum: Checksum,
pub priority: BucketPriority,
pub count: Option<i64>,
pub subscriptions: Rc<Vec<BucketSubscriptionReason>>,
}

impl OwnedBucketChecksum {
Expand All @@ -30,6 +32,7 @@ impl From<&'_ BucketChecksum<'_>> for OwnedBucketChecksum {
checksum: value.checksum,
priority: value.priority.unwrap_or(BucketPriority::FALLBACK),
count: value.count,
subscriptions: value.subscriptions.clone(),
}
}
}
Expand Down
Loading
Loading