Skip to content

Commit f915d6b

Browse files
committed
Fix tests
1 parent a93c2e5 commit f915d6b

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

crates/core/src/migrations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ CREATE TABLE ps_stream_subscriptions (
400400
) STRICT;
401401
402402
INSERT INTO ps_migration(id, down_migrations) VALUES(11, json_array(
403-
json_object('sql', 'todo down migration'),
403+
json_object('sql', 'DROP TABLE ps_stream_subscriptions'),
404404
json_object('sql', 'DELETE FROM ps_migration WHERE id >= 11')
405405
));
406406
";

dart/test/goldens/simple_iteration.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"connecting": true,
1111
"priority_status": [],
1212
"downloading": null,
13-
"streams": []
13+
"streams": null
1414
}
1515
}
1616
},

dart/test/goldens/starting_stream.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"connecting": true,
1515
"priority_status": [],
1616
"downloading": null,
17-
"streams": []
17+
"streams": null
1818
}
1919
}
2020
},

dart/test/utils/migration_fixtures.dart

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// The current database version
2-
const databaseVersion = 10;
2+
const databaseVersion = 11;
33

44
/// This is the base database state that we expect at various schema versions.
55
/// Generated by loading the specific library version, and exporting the schema.
@@ -354,6 +354,66 @@ const expectedState = <int, String>{
354354
;INSERT INTO ps_migration(id, down_migrations) VALUES(8, '[{"sql":"ALTER TABLE ps_sync_state RENAME TO ps_sync_state_new"},{"sql":"CREATE TABLE ps_sync_state (\n priority INTEGER NOT NULL,\n last_synced_at TEXT NOT NULL\n) STRICT"},{"sql":"INSERT INTO ps_sync_state SELECT * FROM ps_sync_state_new"},{"sql":"DROP TABLE ps_sync_state_new"},{"sql":"DELETE FROM ps_migration WHERE id >= 8"}]')
355355
;INSERT INTO ps_migration(id, down_migrations) VALUES(9, '[{"sql":"ALTER TABLE ps_buckets DROP COLUMN count_at_last"},{"sql":"ALTER TABLE ps_buckets DROP COLUMN count_since_last"},{"sql":"DELETE FROM ps_migration WHERE id >= 9"}]')
356356
;INSERT INTO ps_migration(id, down_migrations) VALUES(10, '[{"sql":"SELECT powersync_drop_view(view.name)\n FROM sqlite_master view\n WHERE view.type = ''view''\n AND view.sql GLOB ''*-- powersync-auto-generated''"},{"sql":"DELETE FROM ps_migration WHERE id >= 10"}]')
357+
''',
358+
11: r'''
359+
;CREATE TABLE ps_buckets(
360+
id INTEGER PRIMARY KEY,
361+
name TEXT NOT NULL,
362+
last_applied_op INTEGER NOT NULL DEFAULT 0,
363+
last_op INTEGER NOT NULL DEFAULT 0,
364+
target_op INTEGER NOT NULL DEFAULT 0,
365+
add_checksum INTEGER NOT NULL DEFAULT 0,
366+
op_checksum INTEGER NOT NULL DEFAULT 0,
367+
pending_delete INTEGER NOT NULL DEFAULT 0
368+
, count_at_last INTEGER NOT NULL DEFAULT 0, count_since_last INTEGER NOT NULL DEFAULT 0) STRICT
369+
;CREATE TABLE ps_crud (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT, tx_id INTEGER)
370+
;CREATE TABLE ps_kv(key TEXT PRIMARY KEY NOT NULL, value BLOB)
371+
;CREATE TABLE ps_migration(id INTEGER PRIMARY KEY, down_migrations TEXT)
372+
;CREATE TABLE ps_oplog(
373+
bucket INTEGER NOT NULL,
374+
op_id INTEGER NOT NULL,
375+
row_type TEXT,
376+
row_id TEXT,
377+
key TEXT,
378+
data TEXT,
379+
hash INTEGER NOT NULL) STRICT
380+
;CREATE TABLE ps_stream_subscriptions (
381+
id INTEGER NOT NULL PRIMARY KEY,
382+
stream_name TEXT NOT NULL,
383+
active INTEGER NOT NULL DEFAULT FALSE,
384+
is_default INTEGER NOT NULL DEFAULT FALSE,
385+
local_priority INTEGER,
386+
local_params TEXT NOT NULL DEFAULT 'null',
387+
ttl INTEGER,
388+
expires_at INTEGER,
389+
last_synced_at INTEGER,
390+
UNIQUE (stream_name, local_params)
391+
) STRICT
392+
;CREATE TABLE ps_sync_state (
393+
priority INTEGER NOT NULL PRIMARY KEY,
394+
last_synced_at TEXT NOT NULL
395+
) STRICT
396+
;CREATE TABLE ps_tx(id INTEGER PRIMARY KEY NOT NULL, current_tx INTEGER, next_tx INTEGER)
397+
;CREATE TABLE ps_untyped(type TEXT NOT NULL, id TEXT NOT NULL, data TEXT, PRIMARY KEY (type, id))
398+
;CREATE TABLE ps_updated_rows(
399+
row_type TEXT,
400+
row_id TEXT,
401+
PRIMARY KEY(row_type, row_id)) STRICT, WITHOUT ROWID
402+
;CREATE UNIQUE INDEX ps_buckets_name ON ps_buckets (name)
403+
;CREATE INDEX ps_oplog_key ON ps_oplog (bucket, key)
404+
;CREATE INDEX ps_oplog_opid ON ps_oplog (bucket, op_id)
405+
;CREATE INDEX ps_oplog_row ON ps_oplog (row_type, row_id)
406+
;INSERT INTO ps_migration(id, down_migrations) VALUES(1, null)
407+
;INSERT INTO ps_migration(id, down_migrations) VALUES(2, '[{"sql":"DELETE FROM ps_migration WHERE id >= 2","params":[]},{"sql":"DROP TABLE ps_tx","params":[]},{"sql":"ALTER TABLE ps_crud DROP COLUMN tx_id","params":[]}]')
408+
;INSERT INTO ps_migration(id, down_migrations) VALUES(3, '[{"sql":"DELETE FROM ps_migration WHERE id >= 3"},{"sql":"DROP TABLE ps_kv"}]')
409+
;INSERT INTO ps_migration(id, down_migrations) VALUES(4, '[{"sql":"DELETE FROM ps_migration WHERE id >= 4"},{"sql":"ALTER TABLE ps_buckets DROP COLUMN op_checksum"},{"sql":"ALTER TABLE ps_buckets DROP COLUMN remove_operations"}]')
410+
;INSERT INTO ps_migration(id, down_migrations) VALUES(5, '[{"sql":"SELECT powersync_drop_view(view.name)\n FROM sqlite_master view\n WHERE view.type = ''view''\n AND view.sql GLOB ''*-- powersync-auto-generated''"},{"sql":"ALTER TABLE ps_buckets RENAME TO ps_buckets_5"},{"sql":"ALTER TABLE ps_oplog RENAME TO ps_oplog_5"},{"sql":"CREATE TABLE ps_buckets(\n name TEXT PRIMARY KEY,\n last_applied_op INTEGER NOT NULL DEFAULT 0,\n last_op INTEGER NOT NULL DEFAULT 0,\n target_op INTEGER NOT NULL DEFAULT 0,\n add_checksum INTEGER NOT NULL DEFAULT 0,\n pending_delete INTEGER NOT NULL DEFAULT 0\n, op_checksum INTEGER NOT NULL DEFAULT 0, remove_operations INTEGER NOT NULL DEFAULT 0)"},{"sql":"INSERT INTO ps_buckets(name, last_applied_op, last_op, target_op, add_checksum, op_checksum, pending_delete)\n SELECT name, last_applied_op, last_op, target_op, add_checksum, op_checksum, pending_delete FROM ps_buckets_5"},{"sql":"CREATE TABLE ps_oplog(\n bucket TEXT NOT NULL,\n op_id INTEGER NOT NULL,\n op INTEGER NOT NULL,\n row_type TEXT,\n row_id TEXT,\n key TEXT,\n data TEXT,\n hash INTEGER NOT NULL,\n superseded INTEGER NOT NULL)"},{"sql":"CREATE INDEX ps_oplog_by_row ON ps_oplog (row_type, row_id) WHERE superseded = 0"},{"sql":"CREATE INDEX ps_oplog_by_opid ON ps_oplog (bucket, op_id)"},{"sql":"CREATE INDEX ps_oplog_by_key ON ps_oplog (bucket, key) WHERE superseded = 0"},{"sql":"INSERT INTO ps_oplog(bucket, op_id, op, row_type, row_id, key, data, hash, superseded)\n SELECT ps_buckets_5.name, oplog.op_id, 3, oplog.row_type, oplog.row_id, oplog.key, oplog.data, oplog.hash, 0\n FROM ps_oplog_5 oplog\n JOIN ps_buckets_5\n ON ps_buckets_5.id = oplog.bucket"},{"sql":"DROP TABLE ps_oplog_5"},{"sql":"DROP TABLE ps_buckets_5"},{"sql":"INSERT INTO ps_oplog(bucket, op_id, op, row_type, row_id, hash, superseded)\n SELECT ''$local'', 1, 4, r.row_type, r.row_id, 0, 0\n FROM ps_updated_rows r"},{"sql":"INSERT OR REPLACE INTO ps_buckets(name, pending_delete, last_op, target_op) VALUES(''$local'', 1, 0, 9223372036854775807)"},{"sql":"DROP TABLE ps_updated_rows"},{"sql":"DELETE FROM ps_migration WHERE id >= 5"}]')
411+
;INSERT INTO ps_migration(id, down_migrations) VALUES(6, '[{"sql":"DELETE FROM ps_migration WHERE id >= 6"}]')
412+
;INSERT INTO ps_migration(id, down_migrations) VALUES(7, '[{"sql":"INSERT OR REPLACE INTO ps_kv(key, value) SELECT ''last_synced_at'', last_synced_at FROM ps_sync_state WHERE priority = 2147483647"},{"sql":"DROP TABLE ps_sync_state"},{"sql":"DELETE FROM ps_migration WHERE id >= 7"}]')
413+
;INSERT INTO ps_migration(id, down_migrations) VALUES(8, '[{"sql":"ALTER TABLE ps_sync_state RENAME TO ps_sync_state_new"},{"sql":"CREATE TABLE ps_sync_state (\n priority INTEGER NOT NULL,\n last_synced_at TEXT NOT NULL\n) STRICT"},{"sql":"INSERT INTO ps_sync_state SELECT * FROM ps_sync_state_new"},{"sql":"DROP TABLE ps_sync_state_new"},{"sql":"DELETE FROM ps_migration WHERE id >= 8"}]')
414+
;INSERT INTO ps_migration(id, down_migrations) VALUES(9, '[{"sql":"ALTER TABLE ps_buckets DROP COLUMN count_at_last"},{"sql":"ALTER TABLE ps_buckets DROP COLUMN count_since_last"},{"sql":"DELETE FROM ps_migration WHERE id >= 9"}]')
415+
;INSERT INTO ps_migration(id, down_migrations) VALUES(10, '[{"sql":"SELECT powersync_drop_view(view.name)\n FROM sqlite_master view\n WHERE view.type = ''view''\n AND view.sql GLOB ''*-- powersync-auto-generated''"},{"sql":"DELETE FROM ps_migration WHERE id >= 10"}]')
416+
;INSERT INTO ps_migration(id, down_migrations) VALUES(11, '[{"sql":"DROP TABLE ps_stream_subscriptions"},{"sql":"DELETE FROM ps_migration WHERE id >= 11"}]')
357417
''',
358418
};
359419

@@ -456,6 +516,17 @@ const data1 = <int, String>{
456516
(2, 3, 'lists', 'l1', '', '{}', 3)
457517
;INSERT INTO ps_updated_rows(row_type, row_id) VALUES
458518
('lists', 'l2')
519+
''',
520+
11: r'''
521+
;INSERT INTO ps_buckets(id, name, last_applied_op, last_op, target_op, add_checksum, op_checksum, pending_delete, count_at_last, count_since_last) VALUES
522+
(1, 'b1', 0, 0, 0, 0, 120, 0, 0, 0),
523+
(2, 'b2', 0, 0, 0, 1005, 3, 0, 0, 0)
524+
;INSERT INTO ps_oplog(bucket, op_id, row_type, row_id, key, data, hash) VALUES
525+
(1, 1, 'todos', 't1', '', '{}', 100),
526+
(1, 2, 'todos', 't2', '', '{}', 20),
527+
(2, 3, 'lists', 'l1', '', '{}', 3)
528+
;INSERT INTO ps_updated_rows(row_type, row_id) VALUES
529+
('lists', 'l2')
459530
'''
460531
};
461532

@@ -501,6 +572,7 @@ final dataDown1 = <int, String>{
501572
7: data1[5]!,
502573
8: data1[5]!,
503574
9: data1[9]!,
575+
10: data1[9]!,
504576
};
505577

506578
final finalData1 = data1[databaseVersion]!;

dart/test/utils/test_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Object bucketDescription(
4343
'checksum': checksum,
4444
'priority': priority,
4545
'count': count,
46-
'subscriptions': subscriptions,
46+
if (subscriptions != null) 'subscriptions': subscriptions,
4747
};
4848
}
4949

0 commit comments

Comments
 (0)