Here is a handy controller that I use with my CFWheels application deployments & for debugging my database migrations with Troy Murray’s invaluable CFWheels DBMigrate Plugin.
I use a git branching strategy that utilises feature branches, which can sometimes lead to database migration files being out of sequence based on their creation date.. So I needed a way to test that all current migration are in the correct order… Enter the magical DBMigrate.cfc controller.
To get this up and running, You’ll need to install the CFWheels DBMigrate Plugin, the
/models/DBMigrateVersion.cfc model file and the
/controllers/DBMigrate.cfc controller from https://github.com/chapmandu/cfwheels-dbmigrate-plugin-tools.
Once these files are in place, you can call the following URLs and see the JSON they return:
details: "create tables"
details: "insert lookup rows"
details: "add plain text password field to users table"
details: "create credit card number columns"
The main one I use for my automated tests is the big sexy
action=migrations packet. If any of the migrations are not in the correct sequence, the
isordered node in the JSON will have a value of
false Here is the RocketUnit test that I run to check if all migration are in the right order (and can be run automatically).
public void function test_db_checks_awaiting_migration_files_should_be_in_order()
loc.args.action = "migrations";
loc.response = getResponse(argumentCollection=loc.args);
loc.substring = '"isordered":true'
assert('loc.response contains loc.substring');
Disclaimer: Please be careful leaving this controller lying around in your production environment.. It doesn’t perform any database changes, but can give some basic information about your database migrations to anyone who may stumble upon your URL..
If you use the DBMigrate plugin, you may like this blog post… If you don’t use the plugin.. You really should.