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.
|
Constructor and Description |
---|
DbMigration()
Create for offline migration generation.
|
DbMigration(EbeanServer server)
Create using online EbeanServer.
|
Modifier and Type | Method and Description |
---|---|
void |
addPlatform(io.ebean.Platform 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.
|
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.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.
|
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(io.ebean.Platform 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(io.ebean.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).
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
Copyright © 2017. All rights reserved.