Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class Migrations
- Object
- Migrations
Versioned schema migrations for the application’s SQLite database.
Put scripts named V<version>__<description>.sql in the project’s src/main/db/migration
directory. The build compiles them into the application, and one call brings whatever
database the device holds up to the version this build expects:
Database db = Display.getInstance().openOrCreate("notes.db");
Migrations.migrate(db);
Each script runs once, in version order, inside a transaction, and is recorded in the
flyway_schema_history table with a checksum. A script that has run is never edited: a
change to the schema is a new script with a higher version.
Call this on the thread that owns the database, before anything else uses it, and not on
the event dispatch thread if the scripts are large. A database that a newer build of the
application already migrated is refused with
MigrationException.FUTURE_SCHEMA before anything is changed, so an
older build installed over newer data fails loudly instead of misreading its tables.
The same engine, scripts and history table are used by the Codename One backend.
Methods
public static void register(MigrationSet set) | Registers a migration set. |
public static boolean isRegistered() | Whether any migration set is registered. |
public static Migrator of(Database db) | A migrator for the application’s own set. |
public static Migrator of(Database db, MigrationSet set) | A migrator for a specific set. |
public static MigrateResult migrate(Database db)
throws IOException | Applies every pending migration of every registered set: library sets first, the application’s own last. |
Inherited methods
Method details
register
public static void register(MigrationSet set)Parameters
setMigrationSet- the set to register, replacing one of the same name
isRegistered
public static boolean isRegistered()Returns
migrate(Database) has something to runof
public static Migrator of(Database db)Parameters
dbDatabase- the database, owned by the caller and used from the calling thread
Returns
Throws
IllegalStateException- if the build found no migrations and none was registered
of
public static Migrator of(Database db, MigrationSet set)Parameters
dbDatabase- the database, owned by the caller and used from the calling thread
setMigrationSet- the migrations to run
Returns
migrate
public static MigrateResult migrate(Database db)
throws IOExceptionParameters
dbDatabase- the database, owned by the caller and used from the calling thread
Returns
Throws
com.codename1.migration.MigrationException- if a migration fails or the database does not match this build
IOException- if the database fails