Package Installation Migration

Every package has one main migration that is executed during installation / removal, and is located within the /etc/PACKAGE/ directory. It consists of several files as listed in the below table.

Filename Description
migrate.php The PHP class for the migration as explained in more detail below.
install.sql Contains all SQL code that will be executed during package installation.
remove.sql Contains all SQL code that will be executed upon package removal.
reset.sql Contains all SQL code that will be executed upon package reset.

The migrate.php file contains four different methods as explained in the below table:

Method Description
install Executed during package installation. By default, contains only one line that executes all SQL code within the install.sql file.
remove Executed during package removal. By default, contains only one line that executes all SQL code within the remove.sql file.
reset Executed when package is reset to state just after initial installation. By default, contains only one line that executes all SQL code within the reset.sql file.
resetRedis Executed when the "apex sys reset-redis" CLI command is run which regenerates all keys within the redis database as necessary. If this package utilizes redis, this should recreate any necessary redis data from the SQL database.

Unless you have custom PHP code that needs to be executed during package installation / removal, in essence you should never have to even touch the migrate.php file. Instead, simply place the necessary SQL code within the install.sql and remove.sql files to create and drop the necessary database tables.