Provide DB-UI-updater through Migrations. Where and when to check versions?


I want to provide a GUI-Installer (setting up and seeding the DB) and an Updater (update DB schema) with my CakePHP 3 based software.

The Installer was pretty straight forward. An early middleware checks that it’s a new installation and then takes over. The whole Migration system in Cake 3 makes the rest easy. :+1:

The Updater is a little bit more tricky. The easiest way would be to run $migrations->status(); but for performance reasons that’s not an option on each request.

So I wanted to store a “current” db_version string in the app-settings (DB) which the app has to read anyway. Then I check that against a required DB-version-string stored somewhere in the release src/ folder.

So the question is where to put this:

  • Have the CakePHP DB configuration initialized and load the settings-table
  • Intercept the request before anything else is able to hit the maybe outdated DB (settings-table is not going to change)
  • Run the updater or put the settings into Configure if the DB is up to date and continue the request

I tend to implement the Updater as a middleware too, but maybe there’s a better way/pattern to do it. Any thoughts?