Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class Migrations
- Object
- Migrations
Versioned schema migrations for the server’s database.
Put scripts named V<version>__<description>.sql in src/main/resources/db/migration.
The build compiles them into the server, and the server applies whatever has not run yet
before it opens the entity manager or accepts a request. A script for one engine only goes
in a sqlite, postgresql or mysql subdirectory.
Each script runs once, in version order, and is recorded with a checksum in the
flyway_schema_history table – the table, the file naming and the commands are Flyway’s,
so a schema already managed by Flyway carries straight over. Several server processes
starting at once against one database take a lock, so each migration still runs exactly
once.
The settings mirror Spring Boot’s spring.flyway.* under cn1.flyway.*; see Config.
This class is for the cases start-up does not cover: running a migration by hand, reading
the state of the schema, or migrating a database the server was not configured with.
MigrationInfo[] state = Migrations.of(pool).info();
Migrations.of(pool).repair();On MySQL and MariaDB a schema change commits as it runs and cannot be rolled back. A
script that fails there is recorded as failed and every later start refuses to migrate
until Migrator.repair() has been called.
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(DataSource pool) | A migrator for the application’s own set. |
public static Migrator of(DataSource pool, MigrationSet set) | A migrator for a specific set. |
public static Migrator of(Database db) | A migrator for the application’s own set over one connection the caller owns. |
public static Migrator of(Database db, MigrationSet set) | A migrator for a specific set over one connection the caller owns. |
public static Migrator configure(Migrator migrator, Config config)
throws IOException | Applies the settings a deployment configured to a migrator. |
public static int migrate(DataSource pool, Config config)
throws IOException | Applies every pending migration of every registered set, as start-up does: library sets first, the application’s own last, each configured from cn1.flyway.*. |
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
of
public static Migrator of(DataSource pool)Parameters
poolDataSource- the database
Returns
Throws
IllegalStateException- if the build found no migrations and none was registered
of
public static Migrator of(DataSource pool, MigrationSet set)Parameters
poolDataSource- the database
setMigrationSet- the migrations to run
Returns
of
public static Migrator of(Database db)Parameters
dbDatabase- the connection
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 connection
setMigrationSet- the migrations to run
Returns
configure
public static Migrator configure(Migrator migrator, Config config)
throws IOExceptioncn1.flyway.table names
the application’s own history table only: a library’s set keeps its own.Parameters
migratorMigrator- the migrator to configure
configConfig- the configuration to read
cn1.flyway.*from
Returns
Throws
IOException- if a setting cannot be read
migrate
public static int migrate(DataSource pool, Config config)
throws IOExceptioncn1.flyway.*.Parameters
poolDataSource- the database
configConfig- the configuration
Returns
Throws
com.codename1.migration.MigrationException- if a migration fails or the schema does not match this build
IOException- if the database fails