Skip to content

Fix unecessary schema changes #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ inherits = "release"
inherits = "wasm"

[workspace.package]
version = "0.3.13"
version = "0.3.14"
edition = "2021"
authors = ["JourneyApps"]
keywords = ["sqlite", "powersync"]
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "co.powersync"
version = "0.3.13"
version = "0.3.14"
description = "PowerSync Core SQLite Extension"

repositories {
Expand Down
2 changes: 1 addition & 1 deletion android/src/prefab/prefab.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "powersync_sqlite_core",
"schema_version": 2,
"dependencies": [],
"version": "0.3.13"
"version": "0.3.14"
}
5 changes: 3 additions & 2 deletions crates/core/src/view_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn setup_internal_views(db: *mut sqlite::sqlite3) -> Result<(), ResultCode> {
AS SELECT
view.name name,
view.sql sql,
ifnull(trigger1.sql, '') delete_trigger_sql,
ifnull(group_concat(trigger1.sql, ';\n' ORDER BY trigger1.name DESC), '') delete_trigger_sql,
ifnull(trigger2.sql, '') insert_trigger_sql,
ifnull(trigger3.sql, '') update_trigger_sql
FROM sqlite_master view
Expand All @@ -223,7 +223,8 @@ fn setup_internal_views(db: *mut sqlite::sqlite3) -> Result<(), ResultCode> {
ON trigger2.tbl_name = view.name AND trigger2.type = 'trigger' AND trigger2.name GLOB 'ps_view_insert*'
LEFT JOIN sqlite_master trigger3
ON trigger3.tbl_name = view.name AND trigger3.type = 'trigger' AND trigger3.name GLOB 'ps_view_update*'
WHERE view.type = 'view' AND view.sql GLOB '*-- powersync-auto-generated';
WHERE view.type = 'view' AND view.sql GLOB '*-- powersync-auto-generated'
GROUP BY view.name;

CREATE TRIGGER IF NOT EXISTS powersync_views_insert
INSTEAD OF INSERT ON powersync_views
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,15 @@ DELETE FROM {internal_name} WHERE id = OLD.id;
INSERT INTO powersync_crud_(data) VALUES(json_object('op', 'DELETE', 'type', {type_string}, 'id', OLD.id{old_fragment}));
INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES({type_string}, OLD.id);
INSERT OR REPLACE INTO ps_buckets(name, last_op, target_op) VALUES('$local', 0, {MAX_OP_ID});
END;"
END"
);

// The DELETE statement can't include metadata for the delete operation, so we create
// another trigger to delete with a fake UPDATE syntax.
if table_info.flags.include_metadata() {
let trigger_name = quote_identifier_prefixed("ps_view_delete2_", view_name);
write!(&mut trigger, "\
;
CREATE TRIGGER {trigger_name}
INSTEAD OF UPDATE ON {quoted_name}
FOR EACH ROW
Expand All @@ -146,7 +147,7 @@ DELETE FROM {internal_name} WHERE id = NEW.id;
INSERT INTO powersync_crud_(data) VALUES(json_object('op', 'DELETE', 'type', {type_string}, 'id', NEW.id{old_fragment}, 'metadata', NEW._metadata));
INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES({type_string}, NEW.id);
INSERT OR REPLACE INTO ps_buckets(name, last_op, target_op) VALUES('$local', 0, {MAX_OP_ID});
END;"
END"
).expect("writing to string should be infallible");
}

Expand Down
Loading