Skip to content

Migrator

migrateTo()

migrateTo() — returns string

Available in: migrator Category: General Functions

Migrates database to a specified version. Whilst you can use this in your application, the recommended usage is via either the CLI or the provided GUI interface

NameTypeRequiredDefaultDescription
versionstringno—The Database schema version to migrate to
missingMigFlagbooleannofalseFlag for any available missing migrations
// 1. Migrate up to a specific version
result = application.wheels.migrator.migrateTo("20240315120000");
// result -> "Migrating from 20231201000000 up to 20240315120000.
// -------- 20240315120000_add_status_to_orders --------------------
// "

// 2. Migrate down to an earlier version (rolls back newer migrations)
result = application.wheels.migrator.migrateTo("20230601000000");
// result -> "Migrating from 20240315120000 down to 20230601000000.
// ------- 20240315120000_add_status_to_orders ---------------------
// "

// 3. Migrate to version 0 (rolls back all migrations)
result = application.wheels.migrator.migrateTo("0");
// result -> "Migrating from 20240315120000 down to 0.
// ..."

// 4. Check the result string for errors before proceeding
result = application.wheels.migrator.migrateTo("20240315120000");
if (FindNoCase("Error", result)) {
    writeOutput("Migration failed: " & result);
} else {
    writeOutput("Migration result: " & result);
}

// 5. Apply a missing (out-of-order gap) migration using missingMigFlag
// Use this when a migration with a timestamp earlier than the current version
// was never applied in your environment.
result = application.wheels.migrator.migrateTo(
    version = "20231205083000",
    missingMigFlag = true
);
writeOutput(result);