Class Migrator
java.lang.Object
com.codename1.migration.Migrator
Runs one MigrationSet against one database.
Obtain one from the runtime's Migrations class: com.codename1.db.Migrations.of(database)
in an application, com.codename1.backend.Migrations.of(dataSource) on a server. The
commands and settings are Flyway's, and the history table is Flyway's, so the same scripts
and the same history work under either.
MigrateResult result = Migrations.of(database).baselineOnMigrate(true).migrate();
A migrator holds no connection state between calls and is not thread safe.
-
Method Summary
Modifier and TypeMethodDescriptionvoidbaseline()Marks an existing database as already being at the baseline version.baselineDescription(String description) The description written on the baseline row.baselineOnMigrate(boolean value) Adopts a database that already has tables and no history, by recording a baseline before migrating instead of refusing.baselineVersion(String version) The version an adopted database is taken to be at; migrations at or below it never run.voidclean()Drops every table and view in the database, the history included.cleanDisabled(boolean value) Whetherclean()is refused.getSet()The set this migrator runs.ignoreFutureMigrations(boolean value) Whether a database migrated by a newer build is tolerated.info()Reports every migration, applied or pending, without changing anything.installedBy(String name) The name recorded in the history as having applied each migration.lockRetryCount(int attempts) How long to wait for another process that is migrating the same database, in roughly one-second attempts.migrate()Applies every migration that has not run yet, in version order, then every repeatable migration whose script changed.outOfOrder(boolean value) Whether a migration older than the newest applied one is applied instead of refused.voidrepair()Deletes the rows of failed migrations and rewrites recorded checksums to match the scripts in this build.Uses a history table other than the set's own.The highest version to apply.voidvalidate()Throws unless the database is exactly at this build's migrations: nothing pending, nothing edited, nothing missing.validateOnMigrate(boolean value) Whethermigrate()first checks that every applied migration is still present and unchanged.
-
Method Details
-
getSet
-
table
-
baselineOnMigrate
Adopts a database that already has tables and no history, by recording a baseline before migrating instead of refusing. Off by default: silently adopting a schema of unknown shape is how a migration runs against the wrong database.- Parameters:
value- true to baseline on the first migrate- Returns:
- this migrator
-
baselineVersion
-
baselineDescription
-
validateOnMigrate
-
outOfOrder
Whether a migration older than the newest applied one is applied instead of refused.- Parameters:
value- true to allow it- Returns:
- this migrator
-
cleanDisabled
-
target
-
ignoreFutureMigrations
Whether a database migrated by a newer build is tolerated. A server tolerates it, because a rolling deployment runs old and new builds against one database. An application refuses it by default, because the build on the device cannot know what a newer one did to its tables.- Parameters:
value- true to continue with a warning, false to throw- Returns:
- this migrator
-
installedBy
-
lockRetryCount
How long to wait for another process that is migrating the same database, in roughly one-second attempts.- Parameters:
attempts- the number of attempts, 50 by default- Returns:
- this migrator
-
migrate
Applies every migration that has not run yet, in version order, then every repeatable migration whose script changed.- Returns:
- what ran
- Throws:
MigrationException- if the history does not match, a script fails, or the database is not in a state to migrate; the code says whichIOException- if the database fails outside a migration
-
info
Reports every migration, applied or pending, without changing anything.- Returns:
- applied migrations in the order they ran, then the ones that have not
- Throws:
IOException- if the history cannot be read
-
validate
Throws unless the database is exactly at this build's migrations: nothing pending, nothing edited, nothing missing. A repeatable migration that has not run, or whose script changed since it last ran, is pending.- Throws:
MigrationException- on any differenceIOException- if the history cannot be read
-
baseline
Marks an existing database as already being at the baseline version.- Throws:
IOException- if the history already records migrations or cannot be written
-
repair
Deletes the rows of failed migrations and rewrites recorded checksums to match the scripts in this build. Run it after cleaning up what a failed migration left behind, or after deliberately editing an applied script.- Throws:
IOException- if the history cannot be written
-
clean
Drops every table and view in the database, the history included.- Throws:
MigrationException- unless clean was enabled withcleanDisabled(boolean)IOException- if the database refuses
-