Merge 'Triggers: fix issues with ALTER TABLE' from Jussi Saurio

Still in draft, because there's a ton of stupid AI slop
## Fixes
Closes #3983
Closes #3984
- Disallow DROP COLUMN on columns referenced in triggers
- Propagate RENAME COLUMN to trigger SQL definitions
## Drop Column details
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
```
## AI Disclosure
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 and there is a LOT of it because the AST
traversal to rewrite column references is all mostly from scratch, but
this isn't a particularly performance-critical use case and it should
solve most of the issues with RENAME and DROP COLUMN.

Closes #3986
This commit is contained in:
Jussi Saurio
2025-11-19 15:00:07 +02:00
committed by GitHub
2 changed files with 2838 additions and 15 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff