Tool to ease/automate database migration tasks.
sqlmigrate has three main tasks (and one "aggregated" task):
-
status: checks if database has needed control table and tests if there are pending migrations (no changes are performed in the database).
-
setup: inits the control table (
SQLMIGRATE_HISTORYby default) and optionally populates the existing migrations (only the controle table may be created/updated by this task). -
migrate: run migrations (changes are performed in the database and the control table is updated accordingly).
-
setup_and_migrate: runs both setup and migrate tasks.
Variables like the control table's name and migrations directory are usually defined in a properties file. An exemple file with the avaiable properties can be seen at doc/sqlmigrate.template.properties.
There are two types of migrations: versioned and repeatable. Versioned migrations will be executed in (version-)ascending ordeer. Repeatable migrations will be executed when its contents have changed (checksum mismatch) in filename-ascending order. Repeatable migrations are always executed after versioned migrations.
As shown in doc/sqlmigrate.template.properties, all properties are preceded by sqlmigrate..
migration-table- name of the migration control table (SQLMIGRATE_HISTORYby default)schema-name- name of the migration's control table schema (if needed)migrations-dir- directory containing the versioned migrationsrepeatable-migrations-dir- directory containing the repeatable migrationsdry-run- executes/simulates a task without performing any change in the databasescripts-charset- charset of the scripts
A script version is a sequence of integers separated by dots (.) or hyphens (-). A versioned script file must have the syntax:
<version>_<script-name>.<sql|properties>
A repeatable migration file must have the following syntax:
<script-name>.<sql|properties>
A .sql migration file will be splitted and executed on the database. A .properties file will be processed as an sqlrun-importer (for importing .csvs & .xlss files)
This task checks the 'migration-table' to see if it has the needed columns. If the migration-table is ok, the task will show the avaiable/pending migrations to execute.
This task checks the 'migration-table' to see if it has the needed columns. If not, it will issue DDL comands (create table, add column, ...) to conform the migration table to the desired specification. Optionally, this task may populate (baseline) the control table with the avaiable migrations.
Baseline properties:
baseline(trueorfalse- default isfalse) - executes (or not) the baselinebaseline-version- version to baselinebaseline-repeatables(allornone, default is neither) - baselineall(inserts all),none(removes all) or does nothing (default)
This task represents the main purpose of this tool. First if checks if the migration table has the needed columns. If not, the process halts (setup task needed). After that, pending migrations are executed.
Runs the setup task and the migrate task - in this order.
sqlmigrate <action/task> [-propfile=<path-to-properties-file>] [-Dproperty-name=property-value]...