philbooth · GitHub

While I was pootling around in this repo just now I realised we never got this implemented, so here's my stab at it. It just checks the current patch level matches what it should be before proceeding with the rest of the migration.

I had to wrap that check in a temporary stored procedure because MySQL complains if I try to do IF outside of one. The preceding DROP is so that we clean up in the presence of repeated failures. I've named the procedure specifically to the current patch level to make it hopefully more self-documenting.

If you want to test it out, create a fresh migration using the script and then manually change the patch level to a different value. When you run node bin/db_patcher it should fail like so:

~/c/fxa-auth-db-mysql (pb/detect-missing-migrations) $ node bin/db_patcher
{"Timestamp":1530029634691000000,"Logger":"fxa-auth-db-server","Type":"bin.db_patcher.patch-error","Severity":2,"Pid":43591,"EnvVersion":"2.0","Fields":{"err":"Error: ER_SIGNAL_NOT_FOUND: Missing migration detected"}}

Read the original on github.com ↗