Class DefaultDbMigration
- All Implemented Interfaces:
DbMigration
Reads the prior migrations and compares with the current model of the EbeanServer and generates a migration 'diff' in the form of xml document with the logical schema changes and a series of sql scripts to apply, rollback the applied changes if necessary and drop objects (drop tables, drop columns).
This does not run the migration or ddl scripts but just generates them.
DbMigration migration = DbMigration.create();
migration.setPathToResources("src/main/resources");
migration.setPlatform(Platform.POSTGRES);
migration.generateMigration();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDatabasePlatform(io.ebean.config.dbplatform.DatabasePlatform databasePlatform, String prefix) Add a databasePlatform to write the migration DDL.voidaddPlatform(io.ebean.annotation.Platform platform) Add a platform to write the migration DDL.voidaddPlatform(io.ebean.annotation.Platform platform, String prefix) Add a platform to write with a given prefix.Generate an "init" migration which has all changes.Generate the next migration xml file and associated apply and rollback sql scripts.Return the versions containing pending drops.Return the main migration directory.voidsetAddForeignKeySkipCheck(boolean addForeignKeySkipCheck) Set to true if ALTER TABLE ADD FOREIGN KEY should be generated with an option to skip validation.voidsetApplyPrefix(String applyPrefix) Set the prefix for the version.voidsetGeneratePendingDrop(String generatePendingDrop) Generate a migration for the version specified that contains pending drops.voidSet the header that is included in the generated DDL script.voidsetIncludeBuiltInPartitioning(boolean includeBuiltInPartitioning) Set this to false to exclude the builtin support for table partitioning (with @DbPartition).voidsetIncludeGeneratedFileComment(boolean includeGeneratedFileComment) Set to true to include a generated header comment in the DDL script.voidsetIncludeIndex(boolean includeIndex) Set to include generation of the index migration file.voidsetLockTimeout(int seconds) Set the lock timeout to be included with the DDL generation.voidsetLogToSystemOut(boolean logToSystemOut) Set logging to System out (defaults to true).voidsetMigrationPath(String migrationPath) Set the path where migrations are generated to (which defaults to "dbmigration").voidSet the name of the migration to be generated.voidsetPathToResources(String pathToResources) Set the path from the current working directory to the application resources.voidsetPlatform(io.ebean.annotation.Platform platform) Set the specific platform to generate DDL for.voidsetPlatform(io.ebean.config.dbplatform.DatabasePlatform databasePlatform) Set the specific platform to generate DDL for.voidsetServer(io.ebean.Database database) Set the server to use to determine the current model.voidsetServerConfig(io.ebean.config.DatabaseConfig config) Set the DatabaseConfig to use.voidsetStrictMode(boolean strictMode) Set to false in order to turn off strict mode.voidsetVersion(String version) Set the version of the migration to be generated.
-
Constructor Details
-
DefaultDbMigration
public DefaultDbMigration()Create for offline migration generation.
-
-
Method Details
-
setPathToResources
Description copied from interface:DbMigrationSet the path from the current working directory to the application resources.This defaults to maven style 'src/main/resources'.
- Specified by:
setPathToResourcesin interfaceDbMigration
-
setMigrationPath
Description copied from interface:DbMigrationSet the path where migrations are generated to (which defaults to "dbmigration").Normally we only use this when we use Ebean to generate the database migrations and then use some other tool like FlywayDB to run the migrations.
Example: with
setMigrationPath("db/migration")... the migrations are generated intosrc/resources/db/migration.Note that if Ebean migration runner is used we should not use this method but instead set the migrationPath via a property such that both the migration generator and migration runner both use the same path.
- Specified by:
setMigrationPathin interfaceDbMigration- Parameters:
migrationPath- The path that migrations are generated into.
-
setServer
Description copied from interface:DbMigrationSet the server to use to determine the current model. Usually this is not called explicitly.- Specified by:
setServerin interfaceDbMigration
-
setServerConfig
Description copied from interface:DbMigrationSet the DatabaseConfig to use. Usually this is not called explicitly.- Specified by:
setServerConfigin interfaceDbMigration
-
setStrictMode
Description copied from interface:DbMigrationSet to false in order to turn off strict mode.Strict mode checks that a column changed to non-null on an existing table via DB migration has a default value specified. Set this to false if that isn't the case but it is known that all the existing rows have a value specified (there are no existing null values for the column).
- Specified by:
setStrictModein interfaceDbMigration
-
setApplyPrefix
Description copied from interface:DbMigrationSet the prefix for the version. Set this to "V" for use with Flyway.- Specified by:
setApplyPrefixin interfaceDbMigration
-
setVersion
Description copied from interface:DbMigrationSet the version of the migration to be generated.- Specified by:
setVersionin interfaceDbMigration
-
setName
Description copied from interface:DbMigrationSet the name of the migration to be generated.- Specified by:
setNamein interfaceDbMigration
-
setAddForeignKeySkipCheck
Description copied from interface:DbMigrationSet to true if ALTER TABLE ADD FOREIGN KEY should be generated with an option to skip validation.Currently this is only useful for Postgres DDL adding the
NOT VALIDoption.- Specified by:
setAddForeignKeySkipCheckin interfaceDbMigration
-
setLockTimeout
Description copied from interface:DbMigrationSet the lock timeout to be included with the DDL generation.Currently this is only useful for Postgres migrations adding a
set lock_timeoutstatement to the generated database migration.- Specified by:
setLockTimeoutin interfaceDbMigration
-
setGeneratePendingDrop
Description copied from interface:DbMigrationGenerate a migration for the version specified that contains pending drops.- Specified by:
setGeneratePendingDropin interfaceDbMigration- Parameters:
generatePendingDrop- The version of a prior migration that holds pending drops.
-
setIncludeIndex
Description copied from interface:DbMigrationSet to include generation of the index migration file.When true this generates a
idx_<platform>.migrationsfile. This can be used by the migration runner to improve performance of running migrations, especially when no migration changes have occurred.- Specified by:
setIncludeIndexin interfaceDbMigration
-
setIncludeGeneratedFileComment
Description copied from interface:DbMigrationSet to true to include a generated header comment in the DDL script.- Specified by:
setIncludeGeneratedFileCommentin interfaceDbMigration
-
setIncludeBuiltInPartitioning
Description copied from interface:DbMigrationSet this to false to exclude the builtin support for table partitioning (with @DbPartition).- Specified by:
setIncludeBuiltInPartitioningin interfaceDbMigration
-
setHeader
Description copied from interface:DbMigrationSet the header that is included in the generated DDL script.- Specified by:
setHeaderin interfaceDbMigration
-
setPlatform
Set the specific platform to generate DDL for.If not set this defaults to the platform of the default server.
- Specified by:
setPlatformin interfaceDbMigration
-
setPlatform
Set the specific platform to generate DDL for.If not set this defaults to the platform of the default server.
- Specified by:
setPlatformin interfaceDbMigration
-
addPlatform
Description copied from interface:DbMigrationAdd a platform to write the migration DDL.Use this when you want to generate sql scripts for multiple database platforms from the migration (e.g. generate migration sql for MySql, Postgres and Oracle).
- Specified by:
addPlatformin interfaceDbMigration
-
addPlatform
Description copied from interface:DbMigrationAdd a platform to write with a given prefix.- Specified by:
addPlatformin interfaceDbMigration
-
addDatabasePlatform
public void addDatabasePlatform(io.ebean.config.dbplatform.DatabasePlatform databasePlatform, String prefix) Description copied from interface:DbMigrationAdd a databasePlatform to write the migration DDL.Use this when you want to add preconfigured database platforms.
- Specified by:
addDatabasePlatformin interfaceDbMigration
-
generateMigration
Generate the next migration xml file and associated apply and rollback sql scripts.This does not run the migration or ddl scripts but just generates them.
Example: Run for a single specific platform
DbMigration migration = DbMigration.create(); migration.setPathToResources("src/main/resources"); migration.setPlatform(Platform.ORACLE); migration.generateMigration();Example: Run migration generating DDL for multiple platforms
DbMigration migration = DbMigration.create(); migration.setPathToResources("src/main/resources"); migration.addPlatform(Platform.POSTGRES); migration.addPlatform(Platform.MYSQL); migration.addPlatform(Platform.ORACLE); migration.generateMigration();- Specified by:
generateMigrationin interfaceDbMigration- Returns:
- the generated migration or null
- Throws:
IOException
-
generateInitMigration
Description copied from interface:DbMigrationGenerate an "init" migration which has all changes.An "init" migration can only be executed and used on a database that has had no prior migrations run on it.
- Specified by:
generateInitMigrationin interfaceDbMigration- Returns:
- the version of the generated migration
- Throws:
IOException
-
getPendingDrops
Return the versions containing pending drops.- Specified by:
getPendingDropsin interfaceDbMigration
-
setLogToSystemOut
Description copied from interface:DbMigrationSet logging to System out (defaults to true).- Specified by:
setLogToSystemOutin interfaceDbMigration
-
migrationDirectory
Description copied from interface:DbMigrationReturn the main migration directory.- Specified by:
migrationDirectoryin interfaceDbMigration
-