Releasing Upgrades
We'll do our best to keep this quick while teaching you about both, migrations and upgrades. Within terminal, run the following migration create CLI command:
apex migration create disaster volunteer-adding-agency-column
This will create a new directory at something similar to /etc/Disaster/Migrations/m20230913_140929_volunteer_adding_agency_column, which will include three files. Within the install.sql file for the directory, replace it with the following:
ALTER TABLE disaster_volunteers ADD COLUMN agency VARCHAR(100) NOT NULL DEFAULT 'no-affiliation' AFTER profession;
Next, open the remove.sql file within the same migrations directory and change the contents to:
ALTER TABLE disaster_volunteers DROP COLUMN agency;
Apex has full support for rollbacks via the package rollback rollbakc CLI command, hence the need to populate the remove.sql file with the SQL statement that drops the newly added column.
Run Migrations
You may now run the migration by running the following apex migration migrate command:
apex migration migrate
Apex will automatically detect a new database migration exists and will execute it against the database. This ensures that the database schema is always up to date across all installations of your package throughout the internet.
Publish Upgrade
With the upgrade complete, let's go ahead and publish with by running the following package commit command within terminal:
apex commit disaster -m "Added 'agency' column into 'disaster_volunteers' table"
Once complete, create another release on the package so it's detected and installed during any future releases with the following release create CLI command:
apex release create disaster
Simply hit enter when it requests a version number. This will mark the current state of the code repository as a new upgrade so when someone installs the package it will install with the latest code base.