forked from ebean-orm/ebean
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR ebean-orm#3152 - NEW: DefaultDbMigration is configurable from prop…
…erties
- Loading branch information
Showing
8 changed files
with
195 additions
and
80 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DbMigrationPlugin.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.ebeaninternal.dbmigration; | ||
|
||
import java.io.IOException; | ||
|
||
import io.ebean.plugin.Plugin; | ||
import io.ebean.plugin.SpiServer; | ||
|
||
/** | ||
* Plugin to generate db-migration scripts automatically. | ||
* @author Roland Praml, FOCONIS AG | ||
*/ | ||
public class DbMigrationPlugin implements Plugin { | ||
|
||
private DefaultDbMigration dbMigration; | ||
|
||
private static String lastMigration; | ||
private static String lastInit; | ||
|
||
@Override | ||
public void configure(SpiServer server) { | ||
dbMigration = new DefaultDbMigration(); | ||
dbMigration.setServer(server); | ||
} | ||
|
||
@Override | ||
public void online(boolean online) { | ||
try { | ||
lastInit = null; | ||
lastMigration = null; | ||
if (dbMigration.generate) { | ||
String tmp = lastMigration = dbMigration.generateMigration(); | ||
if (tmp == null) { | ||
return; | ||
} | ||
} | ||
if (dbMigration.generateInit) { | ||
lastInit = dbMigration.generateInitMigration(); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error while generating migration", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
dbMigration = null; | ||
} | ||
|
||
public static String getLastInit() { | ||
return lastInit; | ||
} | ||
|
||
public static String getLastMigration() { | ||
return lastMigration; | ||
} | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
ebean-ddl-generator/src/main/resources/META-INF/services/io.ebean.plugin.Plugin
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.ebeaninternal.dbmigration.DbMigrationPlugin |
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
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
Oops, something went wrong.