Skip to content

Office Schema Management

Andy Theuninck edited this page Apr 6, 2015 · 1 revision

Tables and views are defined in Office using BasicModel subclasses (see Common Architecture).

Creating Tables

Table and view creation happens on the main installation and configuration page, fannie/install/InstallIndexPage.php. The class contains methods named create_op_dbs, create_trans_dbs, and create_archive_dbs for creating structures in the operational, transaction, and archive databases (respectively). Each contains an array of model classes. These structures will be created in the specified order. Tables are typically alphabetic for simplicity but views may need to be defined in a specific order. Creating a new table or view involves creating a model class and adding it to the appropriate array.

Plugins are responsible for creating their own structures (usually during the method call setting_change or plugin_enable). Since plugins are meant to be self-contained, they should not modify the install page.

Updating Tables

To update a table, change the structure of its model. The database update page will check models against existing structures for consistency and suggest ALTER queries.

While updates are simple in theory, in practice it is very important to avoid breaking other people's code. Anyone updating a table schema is responsible for ensuring existing code will cope with both the new and old structure. Deleting columns is almost never a good idea. Any decision to get rid of data permanently should be left to the end user.

Clone this wiki locally