mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-05 08:14:25 +01:00
- Disallow DROP COLUMN on columns referenced in triggers - Propagate RENAME COLUMN to trigger SQL definitions DROP COLUMN is not allowed when the column is mentioned in a trigger on the table the column is dropped from, eg: ``` turso> CREATE TABLE t(x,y); turso> CREATE TRIGGER foo BEFORE INSERT ON t BEGIN INSERT INTO t VALUES (NEW.x); END; turso> ALTER TABLE t DROP COLUMN x; × Parse error: cannot drop column "x": it is referenced in trigger foo ``` However, it is allowed if the trigger is on another table: ``` turso> CREATE TABLE t(x,y); turso> CREATE TABLE u(x,y); turso> CREATE TRIGGER bar BEFORE INSERT ON t BEGIN INSERT INTO u(y) VALUES (NEW.x); END; turso> ALTER TABLE u DROP COLUMN y; turso> INSERT INTO t VALUES (1,1); × Parse error: table u has no column named y ``` Nearly all of the code here is vibecoded. I first asked Cursor Composer to create an initial implementation. Then, I asked it to try to discover edge cases using the `turso` and `sqlite3` CLIs, and write tests+fixes for the edge cases found. The code is a bit slop, but this isn't a particularly performance-critical use case and it should solve most of the issues with RENAME and DROP COLUMN.