Conversation
rkistner
left a comment
There was a problem hiding this comment.
One edge case that this changes is a table that has both local_only: true and insert_only: true. As far as I can see, the previous logic just treated this as local_only, while the new logic treats this as a weird combination of the two, mostly behaving like insert_only.
Ideally we should just disallow specifying both flags, but that could be a breaking change (a user could easily have specified both accidentally before, and it would have kinda worked as a local-only table).
I'd suggest just modifying TableInfoFlags to consider insert_only as false in that case, and adding additional tests to check that case. Then we can consider that case as an error in the next major release.
The insert trigger is the only one where it's a combination. For updates and deletes, we'd just skip the trigger for insert-only tables (so that branch would take precedence over the local-only check, which is a change).
Done 👍 |
This refactors how
CREATE VIEW,CREATE TRIGGERandCREATE INDEXstatements are constructed inpowersync_replace_schema.The main motivation here is that we want to be able to generate triggers for raw tables as well. At the moment,
CREATE TRIGGERstatements are built from a string template specialized for the type of trigger and table. To be able to re-use some of that logic for raw tables in the future, this adds theSqlBufferutility. It contains several methods to write identifiers, string literals and common fragments into aStringbuffer. In particular, writing intopowersync_crudand defining the "header" ofCREATE TRIGGERstatements has been refactored into common method calls instead of being a large string literal.This PR doesn't change the statements generated by the core extension (apart from whitespace). It drastically reduces the amount of intermediate
Stringallocations, but I don't expect that to have a meaningful impact on performance.This also updates Rust to 1.93, to be able to use the standardized
fmt::from_fn, allowing us to provide a callback responsible describing how to format a fragment.