BoxLang 🚀 A New JVM Dynamic Language Learn More...
This is an extension for PresideCMS that allows you to create a database upgrade script in preparation for a deployment to another environment.
box install preside-ext-dbupgradescriptgenerator
While the system does its best to avoid problems, always proceed with caution when upgrading production databases. Large datasets and change conflicts can cause database upgrade issues that the software cannot resolve by itself.
For production databases, take a backup and restore it so that the script can be generated from and tested against the backup. Should you encounter upgrade issues, fix them with database scripts and add those scripts to your saved migration script.
The extension provides two approaches to generating DB upgrade SQL scripts.
You can navigate to the wizard in the admin via the System menu (top right), System -> DB Script Generator.
By default, only the system user can access the script generator wizard. To allow other admin roles to be able to access the wizard, add the following line to your application's Config.cfc
file:
settings.adminRoles.sysadmin.append( "dbUpgradeScriptGenerator.*" );
In this example, we are allowing the "sysadmin" user role to access the generator functionality. See the CMS Permissioning documentation for more details.
You may only wish the feature to be enabled in local or development environments. To do so, edit your application's Config.cfc
file by toggling the settings.features.dbUpgradeScriptGenerator.enabled
flag. For example:
component extends="preside.system.config.Config" {
public void function configure() {
// ...
// feature turned off by default
settings.features.dbUpgradeScriptGenerator.enabled = false;
// ...
}
public void function local() {
// ...
// setting turned on for 'local' environment
settings.features.dbUpgradeScriptGenerator.enabled = true;
// ...
}
}
As of v2.0.0
of this extension, you can set an env variable GENERATE_DB_UPGRADE_SCRIPT_ONLY=true
to force the extension to always stop the application from loading and, instead, output the schema upgrade SQL for the running application.
This could be useful as a build tool helper to allow you to start the application with the datasource set to the target database and to then capture the output of an http request to the application to use as the SQL upgrade script.
For instance, you may do something like:
echo "\
GENERATE_DB_UPGRADE_SCRIPT_ONLY=true\
datasource.host=my.db.server\
datasource.database_name=my_db\
datasource.user=my_db_user\
datasource.type=MySQL\
datasource.password=123\
" > .env
box install [email protected]
box preside start name=sqlgen port=4444 trayEnable=false openbrowser=false
wget -O ./upgrade.sql http://localhost:4444/
box preside stop sqlgen
You are then guaranteed an upgrade.sql
file that you can use to run against your target DB (or send to DBA to evaluate and run, or whatever).
$
box install preside-ext-dbupgradescriptgenerator