simonw / sqlite-utils

Python CLI utility and library for manipulating SQLite databases
https://sqlite-utils.datasette.io
Apache License 2.0
1.58k stars 106 forks source link

`.transform()` effect on triggers and indices #611

Open vkz opened 6 months ago

vkz commented 6 months ago

Could you clarify and expand what the upgrade verb in the following statement from Custom transformations with .transform_sql means, please?

The .transform() method can handle most cases, but it does not automatically upgrade indexes, views or triggers associated with the table that is being transformed.

I make heavy use of triggers and consider using sqlite-utils for migrations, so understanding exactly what happens to my triggers is kind of important. Are we talking about cases where, say I rename a column which a trigger relied upon? E.g. in the following example:

CREATE TRIGGER IF NOT EXISTS insert_lang_on_thread_subject AFTER UPDATE OF subject ON thread
WHEN NEW.subject IN (6, 7)
BEGIN
   ...
END

any changes to the thread table, like, say renaming subject field won't be reflected in this trigger? Is this what the won't upgrade above mean?

IIUC the proposed remedy is to grab the sql code for changes from .transfor_sql() and for this particular example, I guess, add a statement that drops the trigger and creates a new one with correct references to tables and columns?

Thank you