Doing that is simple and can potentially catch all sorts of bugs, including the bugs you didn't think of yet. His solution is complicated but only catches one very specific type of bug.
Doing that is simple and can potentially catch all sorts of bugs, including the bugs you didn't think of yet. His solution is complicated but only catches one very specific type of bug.
> Apart from parsing the SQL query, I also considered an alternative testing approach that I might implement in the future: go through each migration one by one, and insert some dummy data into the database before applying it, to make sure that we test each migration being applied on a non-empty database. The data would either have to be generated automatically based on the current database schema, or we could commit some example DB dataset together with each migration, to make sure that we have some representative data sample available.
Ideally both approaches would be used, with the general case being used to detect and inform more targeted tests.
Perform some arbitrary list of valid actions. (This alone is valuable)
Run the new migrations.
Perform some arbitrary list of valid actions.
Assert no crashes/errors.
I've found this great for testing APIs - just "perform some list of user actions and make sure things don't explode" can catch a lot.
The problem to solve is "given my database in an arbitrary but valid state, applying a migration should succeed and leave the database in a equally valid state". Not "how do I stop people adding NOT NULL columns into tables".
All tests substitute small collections of representative inputs for the generality of inputs.
I'd characterize it less as the cool solution and more as the quick & dirty solution that gets you a lot of value for little effort.