Detect and reject breaking changes to DB Schema

109 Views Asked by At

Is there a way to detect changes in a DB schema as "breaking changes"?

Imagine I create a migration which adds a column to a table. This is a non-breaking change, and should be allowed. However, removing a column might break some API or system or whatever and should be rejected (or at least warned about) as a breaking change.

I imagine this has to be a solved problem, but am unable to find tools or features of postgres that auto-detect potentially breaking changes.

Apart from the obivous human code review which could note the change as potentially breaking, I thought of two hacky ways to achieve this:

Create a "test" entry for every table in my DB. On a schema change, try to insert that "test" entry in the altered table. If that does not work (e.g because a column is missing), mark the schema change as breaking. This solution would basically be a test collection with one test per DB table.

Inspect the migration itself, marking the change as breaking if I find words like "DELETE", "ALTER", "DROP" and so on.

Are there more sophisticated approaches to this? Tools/Services that offer this, a postgres feature I dont know about, etc?

0

There are 0 best solutions below