public class DbMigration extends Object
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 = new DbMigration();
migration.setPathToResources("src/main/resources");
migration.setPlatform(DbPlatformName.ORACLE);
migration.generateMigration();
| Modifier and Type | Class and Description |
|---|---|
static class |
DbMigration.Pair
Holds a platform and prefix.
|
| Modifier and Type | Field and Description |
|---|---|
protected DbConstraintNaming |
constraintNaming |
protected DatabasePlatform |
databasePlatform |
protected static org.slf4j.Logger |
logger |
protected DbMigrationConfig |
migrationConfig |
protected String |
pathToResources |
protected List<DbMigration.Pair> |
platforms |
protected com.avaje.ebeaninternal.api.SpiEbeanServer |
server |
protected ServerConfig |
serverConfig |
| Constructor and Description |
|---|
DbMigration() |
| Modifier and Type | Method and Description |
|---|---|
void |
addPlatform(DbPlatformName platform,
String prefix)
Add an additional platform to write the migration DDL.
|
void |
generateMigration()
Generate the next migration xml file and associated apply and rollback sql scripts.
|
protected DatabasePlatform |
getPlatform(DbPlatformName platform)
Return the DatabasePlatform given the platform key.
|
protected File |
getWritePath()
Return the file path to write the xml and sql to.
|
protected void |
setDefaults()
Set default server and platform if necessary.
|
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(DbPlatformName 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.
|
protected void |
writeExtraPlatformDdl(int nextMajorVersion,
com.avaje.ebean.dbmigration.model.CurrentModel currentModel,
com.avaje.ebean.dbmigration.migration.Migration dbMigration,
File writePath)
Write any extra platform ddl.
|
protected void |
writeMigrationXml(com.avaje.ebean.dbmigration.migration.Migration dbMigration,
File resourcePath,
int migrationVersion)
Write the migration xml.
|
protected static final org.slf4j.Logger logger
protected com.avaje.ebeaninternal.api.SpiEbeanServer server
protected DbMigrationConfig migrationConfig
protected String pathToResources
protected DatabasePlatform databasePlatform
protected List<DbMigration.Pair> platforms
protected ServerConfig serverConfig
protected DbConstraintNaming constraintNaming
public DbMigration()
public void setPathToResources(String pathToResources)
public void setServer(EbeanServer ebeanServer)
public void setServerConfig(ServerConfig config)
public void setPlatform(DbPlatformName platform)
If not set this defaults to the platform of the default server.
public void setPlatform(DatabasePlatform databasePlatform)
If not set this defaults to the platform of the default server.
public void addPlatform(DbPlatformName 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).
public void generateMigration() throws IOException
This does not run the migration or ddl scripts but just generates them.
DbMigration migration = new DbMigration();
migration.setPathToResources("src/main/resources");
migration.setPlatform(DbPlatformName.ORACLE);
migration.generateMigration();
DbMigration migration = new DbMigration();
migration.setPathToResources("src/main/resources");
migration.addPlatform(DbPlatformName.POSTGRES, "pg");
migration.addPlatform(DbPlatformName.MYSQL, "mysql");
migration.addPlatform(DbPlatformName.ORACLE, "mysql");
migration.generateMigration();
IOExceptionprotected void writeExtraPlatformDdl(int nextMajorVersion, com.avaje.ebean.dbmigration.model.CurrentModel currentModel, com.avaje.ebean.dbmigration.migration.Migration dbMigration, File writePath) throws IOException
IOExceptionprotected void writeMigrationXml(com.avaje.ebean.dbmigration.migration.Migration dbMigration, File resourcePath, int migrationVersion)
protected void setDefaults()
protected File getWritePath()
protected DatabasePlatform getPlatform(DbPlatformName platform)
Copyright © 2015. All rights reserved.