Skip to content

Commit 1a9d97e

Browse files
committed
Adopt golden tests
1 parent f8f03b6 commit 1a9d97e

File tree

7 files changed

+398
-61
lines changed

7 files changed

+398
-61
lines changed

crates/core/src/migrations.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::error::{PSResult, SQLiteError};
1212
use crate::fix035::apply_v035_fix;
1313
use crate::sync::bucket_priority::BucketPriority;
1414

15-
pub const LATEST_VERSION: i32 = 9;
15+
pub const LATEST_VERSION: i32 = 10;
1616

1717
pub fn powersync_migrate(
1818
ctx: *mut sqlite::context,
@@ -370,5 +370,22 @@ json_object('sql', 'DELETE FROM ps_migration WHERE id >= 9')
370370
local_db.exec_safe(stmt).into_db_result(local_db)?;
371371
}
372372

373+
if current_version < 10 && target_version >= 10 {
374+
let stmt = "\
375+
PRAGMA writable_schema = ON;
376+
UPDATE sqlite_schema SET sql = replace(sql, 'data TEXT', 'data ANY') WHERE name = 'ps_oplog';
377+
PRAGMA writable_schema = RESET;
378+
379+
INSERT INTO ps_migration(id, down_migrations) VALUES(10, json_array(
380+
json_object('sql', 'PRAGMA writable_schema = ON'),
381+
json_object('sql', 'UPDATE sqlite_schema SET sql = replace(sql, ''data ANY'', ''data TEXT'') WHERE name = ''ps_oplog'''),
382+
json_object('sql', 'PRAGMA writable_schema = RESET'),
383+
json_object('sql', 'DELETE FROM ps_migration WHERE id >= 10')
384+
));
385+
";
386+
387+
local_db.exec_safe(stmt).into_db_result(local_db)?;
388+
}
389+
373390
Ok(())
374391
}

crates/core/src/sync/line.rs

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ pub struct OplogEntry<'a> {
100100
pub object_type: Option<&'a str>,
101101
#[serde(default, borrow)]
102102
pub subkey: Option<&'a str>,
103-
// TODO: BSON?
104103
#[serde(default, borrow)]
105104
pub data: Option<OplogData<'a>>,
106105
}

dart/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ packages:
210210
source: hosted
211211
version: "0.12.17"
212212
meta:
213-
dependency: transitive
213+
dependency: "direct dev"
214214
description:
215215
name: meta
216216
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c

dart/pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ dev_dependencies:
1313
sqlite3_test: ^0.1.1
1414
fake_async: ^1.3.3
1515
convert: ^3.1.2
16+
meta: ^1.16.0
+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
[
2+
{
3+
"operation": "start",
4+
"data": null,
5+
"output": [
6+
{
7+
"UpdateSyncStatus": {
8+
"status": {
9+
"connected": false,
10+
"connecting": true,
11+
"priority_status": [],
12+
"downloading": null
13+
}
14+
}
15+
},
16+
{
17+
"EstablishSyncStream": {
18+
"request": {
19+
"buckets": [],
20+
"include_checksum": true,
21+
"raw_data": true,
22+
"client_id": "test-test-test-test",
23+
"parameters": null
24+
}
25+
}
26+
}
27+
]
28+
},
29+
{
30+
"operation": "line_text",
31+
"data": {
32+
"checkpoint": {
33+
"last_op_id": "1",
34+
"write_checkpoint": null,
35+
"buckets": [
36+
{
37+
"bucket": "a",
38+
"checksum": 0,
39+
"priority": 3,
40+
"count": 1
41+
}
42+
]
43+
}
44+
},
45+
"output": [
46+
{
47+
"UpdateSyncStatus": {
48+
"status": {
49+
"connected": true,
50+
"connecting": false,
51+
"priority_status": [],
52+
"downloading": {
53+
"buckets": {
54+
"a": {
55+
"priority": 3,
56+
"at_last": 0,
57+
"since_last": 0,
58+
"target_count": 1
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
]
66+
},
67+
{
68+
"operation": "line_text",
69+
"data": {
70+
"data": {
71+
"bucket": "a",
72+
"has_more": false,
73+
"after": null,
74+
"next_after": null,
75+
"data": [
76+
{
77+
"op_id": "1",
78+
"op": "PUT",
79+
"object_type": "items",
80+
"object_id": "1",
81+
"checksum": 0,
82+
"data": {
83+
"col": "hi"
84+
}
85+
}
86+
]
87+
}
88+
},
89+
"output": [
90+
{
91+
"UpdateSyncStatus": {
92+
"status": {
93+
"connected": true,
94+
"connecting": false,
95+
"priority_status": [],
96+
"downloading": {
97+
"buckets": {
98+
"a": {
99+
"priority": 3,
100+
"at_last": 0,
101+
"since_last": 1,
102+
"target_count": 1
103+
}
104+
}
105+
}
106+
}
107+
}
108+
}
109+
]
110+
},
111+
{
112+
"operation": "line_text",
113+
"data": {
114+
"checkpoint_complete": {
115+
"last_op_id": "1"
116+
}
117+
},
118+
"output": [
119+
{
120+
"LogLine": {
121+
"severity": "DEBUG",
122+
"line": "Validated checkpoint"
123+
}
124+
},
125+
{
126+
"UpdateSyncStatus": {
127+
"status": {
128+
"connected": true,
129+
"connecting": false,
130+
"priority_status": [
131+
{
132+
"priority": 3,
133+
"last_synced_at": 1740819600,
134+
"has_synced": true
135+
}
136+
],
137+
"downloading": null
138+
}
139+
}
140+
}
141+
]
142+
}
143+
]
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[
2+
{
3+
"operation": "start",
4+
"data": null,
5+
"output": [
6+
{
7+
"UpdateSyncStatus": {
8+
"status": {
9+
"connected": false,
10+
"connecting": true,
11+
"priority_status": [],
12+
"downloading": null
13+
}
14+
}
15+
},
16+
{
17+
"EstablishSyncStream": {
18+
"request": {
19+
"buckets": [],
20+
"include_checksum": true,
21+
"raw_data": true,
22+
"client_id": "test-test-test-test",
23+
"parameters": null
24+
}
25+
}
26+
}
27+
]
28+
}
29+
]

0 commit comments

Comments
 (0)