sqldelight
sqldelight copied to clipboard
Fail migration validation if view depends on deleted table
CREATE TABLE table (
text TEXT
);
CREATE VIEW view AS
SELECT text
FROM table
Migration:
DROP TABLE IF EXISTS table;
CREATE TABLE table (
text TEXT
);
In this example, the above migration will probably consistently fail at runtime.
However, given a different schema, the failure could be inconsistent. If the view references the table through a join, the failure depends on the presence of data that causes the join to execute. Since it's inconsistent, I think that makes it even more important to try to catch this in the validator since there's a higher chance of this error not being discovered with local testing.
The correct migration would be:
DROP VIEW IF EXISTS view;
DROP TABLE IF EXISTS table;
CREATE TABLE table (
text TEXT
);
CREATE VIEW view AS
SELECT text
FROM table;