Skip to content

Commit 0d51ce6

Browse files
committed
Merge branch 'update-options-update' into skip-empty-updates
2 parents 515602b + 72da6d7 commit 0d51ce6

28 files changed

+477
-29
lines changed

.github/workflows/android.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
on:
22
push:
3+
pull_request:
34
name: "android"
45
jobs:
56
build:
67
name: Building Android
8+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
79
runs-on: ubuntu-latest
810
steps:
911
- uses: actions/checkout@v3
@@ -16,7 +18,7 @@ jobs:
1618
java-version: "17"
1719

1820
- name: Validate Gradle wrapper
19-
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
21+
uses: gradle/actions/wrapper-validation@v4
2022

2123
- name: Setup
2224
run: |

.github/workflows/ios.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
on:
22
push:
3+
pull_request:
34
name: "ios"
45
jobs:
56
build:
67
name: Building iOS
8+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
79
runs-on: macos-latest
810
steps:
911
- uses: actions/checkout@v3

.github/workflows/linux.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
on:
22
push:
3+
pull_request:
34
name: "linux"
45
jobs:
56
build_x86_64:
67
name: Building Linux x86_64
8+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
79
runs-on: ubuntu-latest
810
steps:
911
- uses: actions/checkout@v3
@@ -21,6 +23,7 @@ jobs:
2123

2224
build_aarch64:
2325
name: Building Linux aarch64
26+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
2427
runs-on: ubuntu-arm64
2528
steps:
2629
- uses: actions/checkout@v3

.github/workflows/macos.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
on:
22
push:
3+
pull_request:
34
name: "macos"
45
jobs:
56
build_macOS_aarch64:
67
name: Building macOS aarch64
8+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
79
runs-on: macos-latest
810
steps:
911
- uses: actions/checkout@v3
@@ -21,6 +23,7 @@ jobs:
2123

2224
build_macOS_x64:
2325
name: Building macOS x64
26+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
2427
runs-on: macos-14
2528
steps:
2629
- uses: actions/checkout@v3

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
- name: setup-cocoapods
9797
uses: maxim-lobanov/setup-cocoapods@v1
9898
with:
99-
version: 1.12.1
99+
version: 1.16.2
100100

101101
- name: Build iOS & macOS xcframework
102102
run: |

.github/workflows/tests.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
on:
22
push:
3+
pull_request:
34
name: "tests"
45
jobs:
56
build:
67
name: Testing on ${{ matrix.os }}
8+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
79
runs-on: ${{ matrix.os }}
810
strategy:
911
fail-fast: false

.github/workflows/valgrind.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66
build:
77
name: Testing with Valgrind on ${{ matrix.os }}
88
runs-on: ${{ matrix.os }}
9+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
910
strategy:
1011
matrix:
1112
include:

.github/workflows/wasm.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
on:
22
push:
3+
pull_request:
34
name: "wasm"
45
jobs:
56
build_wasm:
67
name: Basic WASM build
8+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
79
runs-on: ubuntu-latest
810
steps:
911
- uses: actions/checkout@v3

.github/workflows/windows.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
on:
22
push:
3+
pull_request:
34
name: "windows"
45
jobs:
56
build_windows:
67
name: Building Windows
8+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
79
runs-on: windows-latest
810
steps:
911
- uses: actions/checkout@v3

Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ inherits = "release"
2929
inherits = "wasm"
3030

3131
[workspace.package]
32-
version = "0.3.9"
32+
version = "0.3.13"
3333
edition = "2021"
3434
authors = ["JourneyApps"]
3535
keywords = ["sqlite", "powersync"]

android/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "co.powersync"
9-
version = "0.3.9"
9+
version = "0.3.13"
1010
description = "PowerSync Core SQLite Extension"
1111

1212
repositories {

android/src/prefab/prefab.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"name": "powersync_sqlite_core",
33
"schema_version": 2,
44
"dependencies": [],
5-
"version": "0.3.9"
5+
"version": "0.3.13"
66
}

crates/core/src/migrations.rs

+37
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use crate::bucket_priority::BucketPriority;
1212
use crate::error::{PSResult, SQLiteError};
1313
use crate::fix035::apply_v035_fix;
1414

15+
pub const LATEST_VERSION: i32 = 9;
16+
1517
pub fn powersync_migrate(
1618
ctx: *mut sqlite::context,
1719
target_version: i32,
@@ -333,5 +335,40 @@ json_object('sql', 'DELETE FROM ps_migration WHERE id >= 7')
333335
local_db.exec_safe(&stmt).into_db_result(local_db)?;
334336
}
335337

338+
if current_version < 8 && target_version >= 8 {
339+
let stmt = "\
340+
ALTER TABLE ps_sync_state RENAME TO ps_sync_state_old;
341+
CREATE TABLE ps_sync_state (
342+
priority INTEGER NOT NULL PRIMARY KEY,
343+
last_synced_at TEXT NOT NULL
344+
) STRICT;
345+
INSERT INTO ps_sync_state (priority, last_synced_at)
346+
SELECT priority, MAX(last_synced_at) FROM ps_sync_state_old GROUP BY priority;
347+
DROP TABLE ps_sync_state_old;
348+
INSERT INTO ps_migration(id, down_migrations) VALUES(8, json_array(
349+
json_object('sql', 'ALTER TABLE ps_sync_state RENAME TO ps_sync_state_new'),
350+
json_object('sql', 'CREATE TABLE ps_sync_state (\n priority INTEGER NOT NULL,\n last_synced_at TEXT NOT NULL\n) STRICT'),
351+
json_object('sql', 'INSERT INTO ps_sync_state SELECT * FROM ps_sync_state_new'),
352+
json_object('sql', 'DROP TABLE ps_sync_state_new'),
353+
json_object('sql', 'DELETE FROM ps_migration WHERE id >= 8')
354+
));
355+
";
356+
local_db.exec_safe(&stmt).into_db_result(local_db)?;
357+
}
358+
359+
if current_version < 9 && target_version >= 9 {
360+
let stmt = "\
361+
ALTER TABLE ps_buckets ADD COLUMN count_at_last INTEGER NOT NULL DEFAULT 0;
362+
ALTER TABLE ps_buckets ADD COLUMN count_since_last INTEGER NOT NULL DEFAULT 0;
363+
INSERT INTO ps_migration(id, down_migrations) VALUES(9, json_array(
364+
json_object('sql', 'ALTER TABLE ps_buckets DROP COLUMN count_at_last'),
365+
json_object('sql', 'ALTER TABLE ps_buckets DROP COLUMN count_since_last'),
366+
json_object('sql', 'DELETE FROM ps_migration WHERE id >= 9')
367+
));
368+
";
369+
370+
local_db.exec_safe(stmt).into_db_result(local_db)?;
371+
}
372+
336373
Ok(())
337374
}

crates/core/src/operations.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES(?1, ?2)",
103103
let mut last_op: Option<i64> = None;
104104
let mut add_checksum: i32 = 0;
105105
let mut op_checksum: i32 = 0;
106+
let mut added_ops: i32 = 0;
106107

107108
while iterate_statement.step()? == ResultCode::ROW {
108109
let op_id = iterate_statement.column_int64(0);
@@ -113,6 +114,7 @@ INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES(?1, ?2)",
113114
let op_data = iterate_statement.column_text(5);
114115

115116
last_op = Some(op_id);
117+
added_ops += 1;
116118

117119
if op == "PUT" || op == "REMOVE" {
118120
let key: String;
@@ -236,13 +238,15 @@ WHERE bucket = ?1",
236238
"UPDATE ps_buckets
237239
SET last_op = ?2,
238240
add_checksum = (add_checksum + ?3) & 0xffffffff,
239-
op_checksum = (op_checksum + ?4) & 0xffffffff
241+
op_checksum = (op_checksum + ?4) & 0xffffffff,
242+
count_since_last = count_since_last + ?5
240243
WHERE id = ?1",
241244
)?;
242245
statement.bind_int64(1, bucket_id)?;
243246
statement.bind_int64(2, *last_op)?;
244247
statement.bind_int(3, add_checksum)?;
245248
statement.bind_int(4, op_checksum)?;
249+
statement.bind_int(5, added_ops)?;
246250

247251
statement.exec()?;
248252
}

crates/core/src/sync_local.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'a> SyncOperation<'a> {
6363

6464
fn can_apply_sync_changes(&self) -> Result<bool, SQLiteError> {
6565
// Don't publish downloaded data until the upload queue is empty (except for downloaded data
66-
//in priority 0, which is published earlier).
66+
// in priority 0, which is published earlier).
6767

6868
let needs_check = match &self.partial {
6969
Some(p) => !p.priority.may_publish_with_outstanding_uploads(),

crates/core/src/view_admin.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use sqlite_nostd as sqlite;
1010
use sqlite_nostd::{Connection, Context};
1111

1212
use crate::error::SQLiteError;
13-
use crate::migrations::powersync_migrate;
13+
use crate::migrations::{powersync_migrate, LATEST_VERSION};
1414
use crate::util::quote_identifier;
1515
use crate::{create_auto_tx_function, create_sqlite_text_fn};
1616

@@ -119,7 +119,7 @@ fn powersync_init_impl(
119119

120120
setup_internal_views(local_db)?;
121121

122-
powersync_migrate(ctx, 7)?;
122+
powersync_migrate(ctx, LATEST_VERSION)?;
123123

124124
Ok(String::from(""))
125125
}
@@ -161,6 +161,7 @@ DELETE FROM ps_buckets;
161161
DELETE FROM ps_untyped;
162162
DELETE FROM ps_updated_rows;
163163
DELETE FROM ps_kv WHERE key != 'client_id';
164+
DELETE FROM ps_sync_state;
164165
",
165166
)?;
166167

crates/core/src/views.rs

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ fn powersync_trigger_insert_sql_impl(
215215
SELECT CASE
216216
WHEN (NEW.id IS NULL)
217217
THEN RAISE (FAIL, 'id is required')
218+
WHEN (typeof(NEW.id) != 'text')
219+
THEN RAISE (FAIL, 'id should be text')
218220
END;
219221
INSERT INTO {internal_name}
220222
SELECT NEW.id, {json_fragment};

dart/pubspec.lock

+25-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ packages:
4949
url: "https://pub.dev"
5050
source: hosted
5151
version: "0.2.0"
52+
clock:
53+
dependency: transitive
54+
description:
55+
name: clock
56+
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
57+
url: "https://pub.dev"
58+
source: hosted
59+
version: "1.1.2"
5260
collection:
5361
dependency: transitive
5462
description:
@@ -81,6 +89,14 @@ packages:
8189
url: "https://pub.dev"
8290
source: hosted
8391
version: "3.0.6"
92+
fake_async:
93+
dependency: "direct dev"
94+
description:
95+
name: fake_async
96+
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
97+
url: "https://pub.dev"
98+
source: hosted
99+
version: "1.3.3"
84100
ffi:
85101
dependency: transitive
86102
description:
@@ -90,7 +106,7 @@ packages:
90106
source: hosted
91107
version: "2.1.4"
92108
file:
93-
dependency: transitive
109+
dependency: "direct dev"
94110
description:
95111
name: file
96112
sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4
@@ -281,6 +297,14 @@ packages:
281297
url: "https://pub.dev"
282298
source: hosted
283299
version: "2.7.5"
300+
sqlite3_test:
301+
dependency: "direct dev"
302+
description:
303+
name: sqlite3_test
304+
sha256: "0b6f76541385cbe0cebf9454854f78dc9aa18b8cb512d8e597e63385e61d4f45"
305+
url: "https://pub.dev"
306+
source: hosted
307+
version: "0.1.1"
284308
stack_trace:
285309
dependency: transitive
286310
description:

dart/pubspec.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ dependencies:
88
sqlite3: ^2.4.5
99
dev_dependencies:
1010
test: ^1.25.0
11+
file: ^7.0.1
12+
sqlite3_test: ^0.1.1
13+
fake_async: ^1.3.3

0 commit comments

Comments
 (0)