From 4e91fa1a33dda0ca9fb7dc1d479cd4604215394a Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Tue, 2 Sep 2025 09:16:34 +0200 Subject: [PATCH] Delete stream subscriptions on clear --- crates/core/src/view_admin.rs | 1 + dart/test/sync_stream_test.dart | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/crates/core/src/view_admin.rs b/crates/core/src/view_admin.rs index 43a688d6..e85c47d2 100644 --- a/crates/core/src/view_admin.rs +++ b/crates/core/src/view_admin.rs @@ -162,6 +162,7 @@ DELETE FROM ps_untyped; DELETE FROM ps_updated_rows; DELETE FROM ps_kv WHERE key != 'client_id'; DELETE FROM ps_sync_state; +DELETE FROM ps_stream_subscriptions; ", )?; diff --git a/dart/test/sync_stream_test.dart b/dart/test/sync_stream_test.dart index bd1cd440..cf1f5dca 100644 --- a/dart/test/sync_stream_test.dart +++ b/dart/test/sync_stream_test.dart @@ -648,4 +648,18 @@ void main() { } ])); }); + + syncTest('clearing database clears subscriptions', (_) { + control( + 'subscriptions', + json.encode({ + 'subscribe': { + 'stream': {'name': 'a'}, + } + }), + ); + expect(db.select('select * from ps_stream_subscriptions'), isNotEmpty); + db.execute('select powersync_clear(0);'); + expect(db.select('select * from ps_stream_subscriptions'), isEmpty); + }); }