Database Structure - misterhaan/abe GitHub Wiki

Abe’s database structure is defined in /etc/db/tables/ and /etc/db/routines/. Each file is named the table or routine name with the sql extension, and contains exactly one create table / function / procedure query. Do not include a semicolon at the end, especially for routines.

The setup script’s InstallDatabase function runs the queries in these files in the order defined by the $tables and $routines arrays. When adding a new table or routine be sure to add it in the appropriate place (alphabetically or after its last dependency).

Adding or changing tables or routines means existing installations will need to upgrade. Abe determines whether it needs to upgrade itself on each page load, and it does so by checking if the structureVersion and dataVersion values in the config table are behind the values in abeVersion.php. These three steps are required to trigger and perform an upgrade:

  1. Add the next value as a named constant in the abeStructureVersion class in abeVersion.php.
  2. Change abeVersion::Structure in abeVersion.php to the new abeStructureVersion constant.
  3. Add code to UpgradeDatabaseStructure() in setup.php that will apply your changes to the previous version(s) of the database structure. This could be running a new table create script or adding new columns to an existing table. If different SQL is needed for the upgrade vs an install it can be placed either in setup.php or in a separate sql file that will probably be organized under /etc/db/tables/upgrades/ or /etc/db/routines/upgrades/.