sqldelight icon indicating copy to clipboard operation
sqldelight copied to clipboard

Fail migration validation if view depends on deleted table

Open mattprecious opened this issue 3 years ago • 0 comments

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;

mattprecious avatar Jul 13 '20 22:07 mattprecious