Table of Contents
New Developers Working Group
Add Fields to Existing Table
This example came from a need that PINES had for annual reports purposes. It adds two new fields to the Organizational Unit table in order to store federal library codes for each location and make those codes available to the reports engine.
1. Update the fieldmapper
File location: Open-ILS\examples\fm_IDL.xml
Add the fields in the "class id="aou"" section:
<field reporter:label="Hours of Operation" name="hours_of_operation" oils_persist:virtual="true" reporter:datatype="link"/>
<field name="fscskey" reporter:label="FSCSKEY" reporter:datatype="text"/>
<field name="fscs_seq" reporter:label="FSCS_SEQ" reporter:datatype="text"/>
The field name must match the column name that you add to the database table. The 'reporter:label' text is what will appear in the list when you are building report templates.
2. Update the schema
New installations of Evergreen will use the code in the Pg folder when the database tables are created. If you are creating a new table for a brand new feature, you'll most likely need to create a new schema file, but in this case we are updating an existing table in the actor schema.
File location: Open-ILS\src\sql\Pg\005.schema.actors.sql
Add the fields to the field list in the "CREATE TABLE actor.org_unit" section of SQL:
3. Edit seed data and create an upgrade script
Updates to the seed data files as well as upgrade scripts are required for any changes to the schema or seed data. (The seed data files are used for fresh installs and the upgrade scripts are used by existing installations that are upgrading.)
File location: Open-ILS\src\sql\Pg\upgrade\XXXX.federal_codes.sql
ALTER TABLE actor.org unit ADD COLUMN fscskey TEXT, ADD COLUMN fscs_seq TEXT;
If you are developing an upgrade script to submit to the Evergreen community, the new upgrade script you create will likely be more complicated. See other examples in the upgrade folder. The "XXXX" in the file name is a placeholder - when the core committers add it to master, they will assign it a number.