public interface DbMigration
Typically this is run as a main method in src/test once a developer is happy with the next set of changes to the model.
// optionally specify the version and name
//System.setProperty("ddl.migration.version", "1.1");
//System.setProperty("ddl.migration.name", "add bars");
// generate a migration using drops from a prior version
//System.setProperty("ddl.migration.pendingDropsFor", "1.2");
DbMigration migration = DbMigration.create();
migration.setPlatform(Platform.POSTGRES);
migration.generateMigration();
Modifier and Type | Method and Description |
---|---|
void |
addDatabasePlatform(DatabasePlatform databasePlatform,
String prefix)
Add an additional databasePlatform to write the migration DDL.
|
void |
addPlatform(io.ebean.annotation.Platform platform,
String prefix)
Add an additional platform to write the migration DDL.
|
static DbMigration |
create()
Create a DbMigration implementation to use.
|
String |
generateInitMigration()
Generate an "init" migration which has all changes.
|
String |
generateMigration()
Generate the next migration sql script and associated model xml.
|
List<String> |
getPendingDrops()
Return the list of versions that contain pending drops.
|
void |
setApplyPrefix(String applyPrefix)
Set the prefix for the version.
|
void |
setGeneratePendingDrop(String generatePendingDrop)
Generate a migration for the version specified that contains pending drops.
|
void |
setHeader(String header)
Set the header that is included in the generated DDL script.
|
void |
setIncludeBuiltInPartitioning(boolean includeBuiltInPartitioning)
Set this to false to exclude the builtin support for table partitioning (with @DbPartition).
|
void |
setIncludeGeneratedFileComment(boolean includeGeneratedFileComment)
Set to true to include a generated header comment in the DDL script.
|
void |
setLogToSystemOut(boolean logToSystemOut)
Set to false to suppress logging to System out.
|
void |
setName(String name)
Set the name of the migration to be generated.
|
void |
setPathToResources(String pathToResources)
Set the path from the current working directory to the application resources.
|
void |
setPlatform(DatabasePlatform databasePlatform)
Set the specific platform to generate DDL for.
|
void |
setPlatform(io.ebean.annotation.Platform platform)
Set the specific platform to generate DDL for.
|
void |
setServer(EbeanServer ebeanServer)
Set the server to use to determine the current model.
|
void |
setServerConfig(ServerConfig config)
Set the serverConfig to use.
|
void |
setStrictMode(boolean strictMode)
Set to false to turn off strict mode.
|
void |
setVersion(String version)
Set the version of the migration to be generated.
|
static DbMigration create()
void setLogToSystemOut(boolean logToSystemOut)
void setPathToResources(String pathToResources)
This defaults to maven style 'src/main/resources'.
void setServer(EbeanServer ebeanServer)
void setServerConfig(ServerConfig config)
void setPlatform(io.ebean.annotation.Platform platform)
If not set this defaults to the platform of the default server.
void setPlatform(DatabasePlatform databasePlatform)
If not set this defaults to the platform of the default server.
void setStrictMode(boolean strictMode)
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).
void setIncludeGeneratedFileComment(boolean includeGeneratedFileComment)
void setIncludeBuiltInPartitioning(boolean includeBuiltInPartitioning)
void setHeader(String header)
void setApplyPrefix(String applyPrefix)
void setVersion(String version)
void setGeneratePendingDrop(String generatePendingDrop)
generatePendingDrop
- The version of a prior migration that holds pending drops.void addPlatform(io.ebean.annotation.Platform platform, String prefix)
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).
void addDatabasePlatform(DatabasePlatform databasePlatform, String prefix)
Use this when you want to add preconfigured database platforms.
List<String> getPendingDrops()
String generateMigration() throws IOException
This does not run the migration or ddl scripts but just generates them.
DbMigration migration = DbMigration.create();
migration.setPlatform(Platform.POSTGRES);
migration.generateMigration();
DbMigration migration = DbMigration.create();
migration.setPathToResources("src/main/resources");
migration.addPlatform(Platform.POSTGRES, "pg");
migration.addPlatform(Platform.MYSQL, "mysql");
migration.addPlatform(Platform.ORACLE, "oracle");
migration.generateMigration();
IOException
String generateInitMigration() throws IOException
An "init" migration can only be executed and used on a database that has had no prior migrations run on it.
IOException
Copyright © 2019. All rights reserved.