-
-
Notifications
You must be signed in to change notification settings - Fork 339
#1429 sync_schema does not sync triggers #1432
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
Conversation
When creating triggers, they are not first dropped if they exist, and then recreated. This way, if a trigger is changed, these changes will also be applied when running sync_schema.
787edb6
to
b4322a6
Compare
hi @HansH . Thanks for creating this PR. I got one concern about it: if we are going to drop trigger anyway in |
If this is not how sync is intended to work, can you expand on how it is intended to work? Note that it immediately recreates the triggers that it drops. So in effect nothing is dropped, only changed, which I would expect to be the intended behavior of sync. |
it has to compare real triggers from db with ones specified in
I see. But it does drops even when no difference found. Table sync works differently.
It is ok for you personally and your project. But it may be not ok for everyone who uses |
Thanks for your response. I'm just trying to understand your reasoning, so I can see if I can change this PR to deal with your concerns. I'm still not entirely convinced that dropping the trigger would pose any problems, exactly because of the reason you mention: they don't contain data that will be lost. But for our use case it is not important. I was just hoping to make a contribution that may be valuable to other users of this project. But if you think this is not a good approach, that is fine with me too. There is also another change in this pull request: adding the For us the latter would me much more useful than the dropping and recreation of triggers. Than we can just drop all triggers before calling |
Imagine the code dropped trigger but before creating exception occurred not matter the reason. So we got to the case when do did not have any reason to delete/recreate triggers but we did it and now DB doesn't have the trigger. It is not right. If there is no reason to delete anything we don't have to delete anything.
Yes it is a good addition. Let's make this or another PR with only this feature and we'll review it. Thanks |
I got an idea how to sync triggers. It is not ideal but it may work and doesn't produce unused deletions of triggers: we extract trigger's SQL string from |
The serialized version of the trigger in sqlite_schema is the single source of truth (in absence of any other type-based master table), so I agree that this is definitely a good approach. |
@HansH please fix formatting and merge conflicts |
With #1434, this issue has been sufficiently solved for me. I don't think it's worthwhile to continue with this pull request. I do see you have ideas for solving the original problem. But that is a whole different approach, and I don't think it makes sense to do that as part of this pull request. |
In order to deal with #1429, I made two changes:
CREATE TRIGGER IF NOT EXISTS...
, it now usesDROP TRIGGER IF EXISTS <triggername>;CREATE TRIGGER <triggername>....
. This ensures that the trigger is recreated as specified in themake_storage
call.trigger_names
, similar to the methodtable_names
. This can be used to see which triggers actually exist in the database, so you can decide e.g. to usedrop_trigger()
to delete any triggers that you do not want.I also added tests to test these changes.