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 boolean |
online
Set to true if DbMigration run with online EbeanServer instance.
|
protected String |
pathToResources |
protected List<DbMigration.Pair> |
platforms |
protected com.avaje.ebeaninternal.api.SpiEbeanServer |
server |
protected ServerConfig |
serverConfig |
Constructor and Description |
---|
DbMigration()
Create for offline migration generation.
|
DbMigration(EbeanServer server)
Create using online EbeanServer.
|
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 File |
getMigrationDirectory()
Return the file path to write the xml and sql to.
|
protected File |
getModelDirectory(File migrationDirectory)
Return the model directory (relative to the migration directory).
|
protected DatabasePlatform |
getPlatform(DbPlatformName platform)
Return the DatabasePlatform given the platform key.
|
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(String fullVersion,
com.avaje.ebean.dbmigration.model.CurrentModel currentModel,
com.avaje.ebean.dbmigration.migration.Migration dbMigration,
File writePath)
Write any extra platform ddl.
|
protected boolean |
writeMigrationXml(com.avaje.ebean.dbmigration.migration.Migration dbMigration,
File resourcePath,
String fullVersion)
Write the migration xml.
|
protected static final org.slf4j.Logger logger
protected final boolean online
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 DbMigration(EbeanServer server)
public void setPathToResources(String pathToResources)
This defaults to maven style 'src/main/resources'.
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();
IOException
protected void writeExtraPlatformDdl(String fullVersion, com.avaje.ebean.dbmigration.model.CurrentModel currentModel, com.avaje.ebean.dbmigration.migration.Migration dbMigration, File writePath) throws IOException
IOException
protected boolean writeMigrationXml(com.avaje.ebean.dbmigration.migration.Migration dbMigration, File resourcePath, String fullVersion)
protected void setDefaults()
protected File getMigrationDirectory()
protected File getModelDirectory(File migrationDirectory)
protected DatabasePlatform getPlatform(DbPlatformName platform)
Copyright © 2016. All rights reserved.