Created
July 18, 2014 13:16
-
-
Save pavei/ec30ef8a10b7c7773bdc to your computer and use it in GitHub Desktop.
Schema DDL Generator with PlayFramework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Populate test database with sample data. | |
* | |
* @throws IOException | |
*/ | |
public static void setUpDb() throws IOException { | |
server = Ebean.getServer("default"); | |
ServerConfig config = new ServerConfig(); | |
config.setDdlGenerate(true); | |
config.setDdlRun(true); | |
H2Platform plata = new H2Platform(); | |
plata.getDbDdlSyntax().setMaxConstraintNameLength(10); | |
ddl = new DdlGenerator(); | |
ddl.setup((SpiEbeanServer) server, plata, config); | |
File beforeRun = Play.current().getFile("test/ddl/HSQL_BEFORE_TEST.sql"); | |
String sqlBefore = StringUtils.trim(FileUtils.readFileToString(beforeRun, "UTF-8")); | |
Ebean.execute(Ebean.createCallableSql(sqlBefore)); | |
// create | |
Logger.debug("generating create ddl"); | |
String createScript = ddl.generateCreateDdl(); | |
System.out.println( createScript); | |
Ebean.execute(Ebean.createCallableSql(createScript)); | |
// Load and execute script file in test/ddl/HSQL_INSERT.sql | |
File insertScript = Play.current().getFile("test/ddl/HSQL_INSERT.sql"); | |
String sql = StringUtils.trim(FileUtils.readFileToString(insertScript, "UTF-8")); | |
// Execute insert instructions | |
Ebean.execute(Ebean.createSqlUpdate(sql)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment