You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
INSERT INTO ps_oplog(bucket, op_id, op, row_type, row_id, hash, superseded)
198
-
SELECT '$local', 1, 4, r.row_type, r.row_id, 0, 0
199
-
FROM ps_updated_rows r;
200
-
INSERT OR REPLACE INTO ps_buckets(name, pending_delete, last_op, target_op) VALUES('$local', 1, 0, 9223372036854775807);
201
-
202
-
DROP TABLE ps_updated_rows
203
-
"
204
-
.to_string(),
205
-
);
206
-
}
207
-
208
149
for sql in down_sql {
209
150
let rs = local_db.exec_safe(&sql);
210
151
ifletErr(code) = rs {
@@ -328,11 +269,17 @@ INSERT INTO ps_migration(id, down_migrations)
328
269
}
329
270
330
271
if current_version < 5 && target_version >= 5{
272
+
// Start by dropping all existing views and triggers (but not tables).
273
+
// This is because the triggers are restructured in this version, and
274
+
// need to be re-created from scratch. Not dropping them can make it
275
+
// refer to tables or columns not existing anymore, which can case
276
+
// issues later on.
277
+
// The same applies for the down migration.
278
+
331
279
// language=SQLite
332
280
local_db
333
281
.exec_safe(
334
282
"\
335
-
-- Drop all existing views (and triggers)
336
283
SELECT powersync_drop_view(view.name)
337
284
FROM sqlite_master view
338
285
WHERE view.type = 'view'
@@ -410,6 +357,24 @@ DROP TABLE ps_oplog_old;
410
357
INSERT INTO ps_migration(id, down_migrations)
411
358
VALUES(5,
412
359
json_array(
360
+
-- Drop existing views and triggers if any
361
+
json_object('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'''),
362
+
363
+
json_object('sql', 'ALTER TABLE ps_buckets RENAME TO ps_buckets_5'),
364
+
json_object('sql', 'ALTER TABLE ps_oplog RENAME TO ps_oplog_5'),
365
+
json_object('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)'),
366
+
json_object('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'),
367
+
json_object('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)'),
368
+
json_object('sql', 'CREATE INDEX ps_oplog_by_row ON ps_oplog (row_type, row_id) WHERE superseded = 0'),
369
+
json_object('sql', 'CREATE INDEX ps_oplog_by_opid ON ps_oplog (bucket, op_id)'),
370
+
json_object('sql', 'CREATE INDEX ps_oplog_by_key ON ps_oplog (bucket, key) WHERE superseded = 0'),
0 commit comments