Skip to content

Commit 45a6b2b

Browse files
committed
Fix delete triggers to revert rejected deletes.
1 parent 53223d6 commit 45a6b2b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/core/src/views.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,16 @@ FOR EACH ROW
8484
BEGIN
8585
DELETE FROM {:} WHERE id = OLD.id;
8686
INSERT INTO powersync_crud_(data) VALUES(json_object('op', 'DELETE', 'type', {:}, 'id', OLD.id));
87-
END", trigger_name, quoted_name, internal_name, type_string);
87+
INSERT INTO ps_oplog(bucket, op_id, op, row_type, row_id, hash, superseded)
88+
SELECT '$local',
89+
1,
90+
'REMOVE',
91+
{:},
92+
OLD.id,
93+
0,
94+
0;
95+
INSERT OR REPLACE INTO ps_buckets(name, pending_delete, last_op, target_op) VALUES('$local', 1, 0, {:});
96+
END", trigger_name, quoted_name, internal_name, type_string, type_string, MAX_OP_ID);
8897
Ok(trigger)
8998
} else if local_only {
9099
let trigger = format!("\

0 commit comments

Comments
 (0)