Skip to content

Commit 3488782

Browse files
committed
Update PowerSync core to 0.4.8
1 parent 1c904a8 commit 3488782

File tree

11 files changed

+110
-18
lines changed

11 files changed

+110
-18
lines changed

packages/powersync_core/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.7.0-dev
2+
3+
- Update PowerSync core extension to 0.4.8.
4+
- `disconnectAndClear()`: Add `soft` parameter to only delete public data, allowing it to be reconstructed quickly.
5+
- Raw tables: Add `clear` parameter to clear raw tables in `disconnectAndClear()`.
6+
17
## 1.6.1
28

39
- Web: Fix decoding sync streams on status.

packages/powersync_core/lib/src/database/core_version.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extension type const PowerSyncCoreVersion((int, int, int) _tuple) {
6363
// - scripts/download_core_binary_demos.dart
6464
// - packages/sqlite3_wasm_build/build.sh
6565
// - Android and Darwin (CocoaPods and SwiftPM) in powersync_flutter_libs
66-
static const minimum = PowerSyncCoreVersion((0, 4, 6));
66+
static const minimum = PowerSyncCoreVersion((0, 4, 8));
6767

6868
/// The first version of the core extensions that this version of the Dart
6969
/// SDK doesn't support.

packages/powersync_core/lib/src/database/powersync_db_mixin.dart

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,35 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
245245

246246
/// Disconnect and clear the database.
247247
///
248-
/// Use this when logging out.
248+
/// Clearing the database is useful when a user logs out, to ensure another
249+
/// user logging in later would not see previous data.
249250
///
250251
/// The database can still be queried after this is called, but the tables
251252
/// would be empty.
252253
///
253-
/// To preserve data in local-only tables, set [clearLocal] to false.
254-
Future<void> disconnectAndClear({bool clearLocal = true}) async {
254+
/// To preserve data in local-only tables, set [clearLocal] to `false`.
255+
///
256+
/// A [soft] clear deletes publicly visible data, but keeps internal copies of
257+
/// data synced in the database. This usually means that if the same user logs
258+
/// out and back in again, the first sync is very fast because all internal
259+
/// data is still available. WHen a different user logs in, no old data would
260+
/// be visible at any point.
261+
/// Using soft deletes is recommended where it's not a security issue that old
262+
/// data could be reconstructible from the database.
263+
Future<void> disconnectAndClear(
264+
{bool clearLocal = true, bool soft = false}) async {
255265
await disconnect();
256266

257267
await writeTransaction((tx) async {
258-
await tx.execute('select powersync_clear(?)', [clearLocal ? 1 : 0]);
268+
var flags = 0;
269+
if (clearLocal) {
270+
flags |= 1; // MASK_CLEAR_LOCAL
271+
}
272+
if (soft) {
273+
flags |= 2; // MASK_SOFT_CLEAR
274+
}
275+
276+
await tx.execute('select powersync_clear(?)', [flags]);
259277
});
260278
// The data has been deleted - reset these
261279
setStatus(SyncStatus(lastSyncedAt: null, hasSynced: false));

packages/powersync_core/lib/src/schema.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// @docImport 'database/powersync_db_mixin.dart';
2+
library;
3+
14
import 'crud.dart';
25
import 'schema_logic.dart';
36

@@ -368,16 +371,25 @@ final class RawTable {
368371
/// used here must all be [PendingStatementValue.id].
369372
final PendingStatement delete;
370373

374+
/// An optional SQL statement to run when a PowerSync database is cleared.
375+
///
376+
/// When this value is unset, clearing the database (via
377+
/// [PowerSyncDatabaseMixin.disconnectAndClear]) would not affect the raw
378+
/// table.
379+
final String? clear;
380+
371381
const RawTable({
372382
required this.name,
373383
required this.put,
374384
required this.delete,
385+
this.clear,
375386
});
376387

377388
Map<String, dynamic> toJson() => {
378389
'name': name,
379390
'put': put,
380391
'delete': delete,
392+
'clear': clear,
381393
};
382394
}
383395

packages/powersync_core/test/disconnect_test.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,61 @@ void main() {
6969
final changes = await changesFuture;
7070
expect(changes.first, equals(UpdateNotification({'customers'})));
7171
});
72+
73+
test('soft clear', () async {
74+
final db = await testUtils.setupPowerSync(path: path, schema: testSchema);
75+
addTearDown(db.close);
76+
77+
await db.execute(
78+
'INSERT INTO customers (id, name) VALUES(uuid(), ?)', ['testuser']);
79+
await db.execute(
80+
'INSERT INTO ps_buckets (name, last_applied_op) VALUES (?, ?)',
81+
['bkt', 10],
82+
);
83+
84+
// Doing a soft-clear should delete data but keep the bucket around.
85+
await db.disconnectAndClear(soft: true);
86+
expect(await db.getAll('SELECT * FROM ps_buckets'), hasLength(1));
87+
88+
// Doing a default clear also deletes buckets.
89+
await db.disconnectAndClear();
90+
expect(await db.getAll('SELECT * FROM ps_buckets'), isEmpty);
91+
});
92+
93+
test('clear raw tables', () async {
94+
final db = await testUtils.setupPowerSync(
95+
path: path,
96+
schema: Schema(
97+
rawTables: [
98+
RawTable(
99+
name: 'lists',
100+
put: PendingStatement(
101+
sql: 'INSERT OR REPLACE INTO lists (id, name) VALUES (?, ?)',
102+
params: [
103+
PendingStatementValue.id(),
104+
PendingStatementValue.column('name')
105+
],
106+
),
107+
delete: PendingStatement(
108+
sql: 'DELETE FROM lists WHERE id = ?',
109+
params: [PendingStatementValue.id()],
110+
),
111+
clear: 'DELETE FROM lists',
112+
),
113+
],
114+
[],
115+
),
116+
);
117+
addTearDown(db.close);
118+
119+
await db.execute(
120+
'CREATE TABLE lists (id TEXT NOT NULL PRIMARY KEY, name TEXT)');
121+
await db
122+
.execute('INSERT INTO lists (id, name) VALUES (uuid(), ?)', ['list']);
123+
124+
expect(await db.getAll('SELECT * FROM lists'), hasLength(1));
125+
await db.disconnectAndClear();
126+
expect(await db.getAll('SELECT * FROM lists'), isEmpty);
127+
});
72128
});
73129
}

packages/powersync_flutter_libs/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ android {
5050
}
5151

5252
dependencies {
53-
implementation 'com.powersync:powersync-sqlite-core:0.4.6'
53+
implementation 'com.powersync:powersync-sqlite-core:0.4.8'
5454
}

packages/powersync_flutter_libs/darwin/powersync_flutter_libs.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A new Flutter FFI plugin project.
2525
s.osx.deployment_target = '10.15'
2626

2727
# NOTE: Always update Package.swift as well when updating this!
28-
s.dependency "powersync-sqlite-core", "~> 0.4.6"
28+
s.dependency "powersync-sqlite-core", "~> 0.4.8"
2929

3030
# Flutter.framework does not contain a i386 slice.
3131
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }

packages/powersync_flutter_libs/linux/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ set(CORE_FILE_NAME "libpowersync.so")
2929

3030
set(POWERSYNC_ARCH ${CMAKE_SYSTEM_PROCESSOR})
3131
if (${POWERSYNC_ARCH} MATCHES "x86_64" OR ${POWERSYNC_ARCH} MATCHES "AMD64")
32-
set(CORE_FILE_NAME "libpowersync_x64.so")
32+
set(CORE_FILE_NAME "libpowersync_x64.linux.so")
3333
elseif (${POWERSYNC_ARCH} MATCHES "^arm64" OR ${POWERSYNC_ARCH} MATCHES "^armv8")
34-
set(CORE_FILE_NAME "libpowersync_aarch64.so")
34+
set(CORE_FILE_NAME "libpowersync_aarch64.linux.so")
3535
endif ()
3636

3737
set(POWERSYNC_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${CORE_FILE_NAME}")

packages/sqlite3_wasm_build/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33

44
SQLITE_VERSION="2.9.0"
5-
POWERSYNC_CORE_VERSION="0.4.6"
5+
POWERSYNC_CORE_VERSION="0.4.8"
66
SQLITE_PATH="sqlite3.dart"
77

88
if [ -d "$SQLITE_PATH" ]; then

scripts/download_core_binary_demos.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import 'dart:io';
44

55
final coreUrl =
6-
'https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v0.4.6';
6+
'https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v0.4.8';
77

88
void main() async {
99
final powersyncLibsLinuxPath = "packages/powersync_flutter_libs/linux";
1010
final powersyncLibsWindowsPath = "packages/powersync_flutter_libs/windows";
1111

12-
final linuxArm64FileName = "libpowersync_aarch64.so";
13-
final linuxX64FileName = "libpowersync_x64.so";
12+
final linuxArm64FileName = "libpowersync_aarch64.linux.so";
13+
final linuxX64FileName = "libpowersync_x64.linux.so";
1414
final windowsX64FileName = "powersync_x64.dll";
1515

1616
// Download dynamic library

0 commit comments

Comments
 (0)