Aspen:Automated Database Upgrades

From Aspen Documentation

Items documented on this page are used in the demo aspen application, but may change in future revisions. Please consider these features experimental and watch the revision compatibility notes.

Aspen has a system that will allow you to automate database upgrades of a distributed application.

First, your application must have a build number present in the config files called application_build. If this build is higher than the latest build number present in the upgrade_history table (automatically added with each upgrade) then Aspen tries to find if there are any SQL changes to apply.

Inside of the modules/Install/sql/upgrade.sql file, you may place a query into an array with the build revision that the query must be applied to.

For example:

 $sql['1022'][] = "DROP TABLE 'oldtable'";

If the latest build stored in the upgrade_history table is 1000 and the build number present in the latest code is 1040 the any queries with a build number (key in the array) between those number will be executed.

Upon success, the new build number will be stored in the database.

Note: This system works only for your application tables, and will not work properly if changing tables required for aspen to function. A new version of aspen that requires a specific field may not function without such a field, hence it will be unable to run the upgrade.