What potential non-obvious data loss can be caused by DROP VIEW xy CASCADE
?
I am using database migrations and as a feature I can have "repeatable migrations" - files containing SQL that get re-run every time after at least one new migration was applied. In my case they usually contain this:
DROP VIEW IF EXISTS x_y;
CREATE VIEW x_y AS ...
(I use this approach to define common views because otherwise I would usually have to find the latest version of the view among older migrations and then repeat it almost verbatim, just with one or two extra columns, and this quickly becomes very verbose and error prone).
Lately I have been getting more and more dependency issues where I have to manually drop views that will get created in later repeatable migrations (otherwise I get the Cannot drop view XY because other objects depend on it
error). I don't want to use ALTER VIEW
since it doesn't allow me to remove or reorder columns so it's become tempting to simply use DROP VIEW xy IF EXISTS CASCADE
but I am worried about hidden data loss. Thinking about what could get dropped:
Other views: If other views are dropped it wouldn't be so bad because application integration tests & code gen would catch this (my database objects get generated into type-safe code so a missing view wouldn't get past the compiler as soon as it is used anywhere in the application code).
Triggers: this would be potentially bad because a trigger not generated in repeatable migrations could get deleted and not re-created thus cause information loss, although if triggers are covered by integration tests this is manageable
Anything else? Could table data be lost (althought again, application code and unit tests would probably catch this before it gets anywhere near production)? Is there a way data could get wiped during migrations and not noticed in unit & integration tests (as these usually test for functionality, but not pre-existing data)?