The Maintain updater
Database and codebase version constants
The Maintain core has an installer and update script to take care of initially installing and subsequently updating its database information.
To determine if the database status is different from the codebase version, there is a constant in the code tree as well as in the database.
The code constant can be found in /constants.inc and is called MAINTAIN_DB_VERSION. In the database, it is a row with index db_version stored in the table called update_info.
How to implement a maintain core database upgrade
If your modifications to the codebase require a database change, you will have to tell the upgrader to handle this change so that users as well as fellow developers get upgraded databases, too.
- First, you need to increment the build number in the constants.inc file. So, if there is "300115" in there, you have to change it to "300116". Keep in mind, the format of the number is:
- Afterwards, you will have to create a standard SQL file in the install/sql folder, representing the changes you made to your database (alter, input, update statements). Give it a meaningful name. Look at the other files in there to see how they should look like inside.
- To prevent a new instance of Maintain from immediately upgrading the first time it is used, also represent these changes in the install/sql/maintain.sql file, so that new installations of Maintain immediately start off with the appropriate changes. You do not have to change any version numbers in here: The installer will set the correct number itself on installation time.
- Now represent your changes in the class/update.php class. In the run_update method, in the "new update cases go here" section, you add another case for your update. The basic layout will be like this:
Where the "case" is the old version number, migrate2_4-3.sql is the name of the update sql file you created, and the number in the _upgrade_sql line is the new version number to be set on success (most of the time, this is the "case" number plus 1). Make sure not to break; out of the case statement if the upgrade step was successful. Otherwise subsequent upgrades won't be applied automatically.
Testing
Always make sure to test if the upgrade script works as intended: Revert your changes in the database and have Maintain do the upgrade for you. Otherwise you will not know if you can actually log into your version of Maintain again after the automatic upgrade. Messing this up wouldn't be a small but a breaking bug, meaning every Maintain user will want to slap you 