FIX: extra-ddl can contribute to "drop-all" script, otherwise the drop all script is not appyable to h2:file (#1301)

This commit is contained in:
Roland Praml authored and Rob Bygrave committed 2018-03-02 11:48:35 +13:00
1 parent c1b022c123
commit 0c368ed7b3
6 files changed
+36 -7

No files matched your search

@@ -127,6 +127,14 @@ public class DdlGenerator {
protected void runDropSql() throws IOException {
if (!createOnly) {
String ignoreExtraDdl = System.getProperty("ebean.ignoreExtraDdl");
if (!"true".equalsIgnoreCase(ignoreExtraDdl) && jaxbPresent) {
String extraApply = ExtraDdlXmlReader.buildExtra(server.getDatabasePlatform().getName(), true);
if (extraApply != null) {
runScript(false, extraApply, "extra-dll");
}
}
if (dropAllContent == null) {
dropAllContent = readFile(getDropFileName());
}
@@ -142,7 +150,7 @@ public class DdlGenerator {
String ignoreExtraDdl = System.getProperty("ebean.ignoreExtraDdl");
if (!"true".equalsIgnoreCase(ignoreExtraDdl) && jaxbPresent) {
String extraApply = ExtraDdlXmlReader.buildExtra(server.getDatabasePlatform().getName());
String extraApply = ExtraDdlXmlReader.buildExtra(server.getDatabasePlatform().getName(), false);
if (extraApply != null) {
runScript(false, extraApply, "extra-dll");
}
@@ -268,7 +268,8 @@ public class DefaultDbMigration implements DbMigration {
if (extraDdl != null) {
List<DdlScript> ddlScript = extraDdl.getDdlScript();
for (DdlScript script : ddlScript) {
if (ExtraDdlXmlReader.matchPlatform(dbPlatform.getName(), script.getPlatforms())) {
if (script.isDrop() == false
&& ExtraDdlXmlReader.matchPlatform(dbPlatform.getName(), script.getPlatforms())) {
writeExtraDdl(migrationDir, script);
}
}
@@ -37,6 +37,8 @@ public class DdlScript {
protected String name;
@XmlAttribute(name = "platforms")
protected String platforms;
@XmlAttribute(name = "drop")
protected boolean drop;
/**
* Gets the value of the value property.
@@ -98,4 +100,18 @@ public class DdlScript {
this.platforms = value;
}
/**
* Return if this a drop script.
*/
public boolean isDrop() {
return drop;
}
/**
* Sets that this is a drop script.
*/
public void setDrop(boolean drop) {
this.drop = drop;
}
}
@@ -20,7 +20,7 @@ public class ExtraDdlXmlReader {
/**
* Return the combined extra DDL that should be run given the platform name.
*/
public static String buildExtra(String platformName) {
public static String buildExtra(String platformName, boolean drops) {
ExtraDdl read = ExtraDdlXmlReader.read("/extra-ddl.xml");
if (read == null) {
@@ -28,7 +28,8 @@ public class ExtraDdlXmlReader {
}
StringBuilder sb = new StringBuilder(300);
for (DdlScript script : read.getDdlScript()) {
if (matchPlatform(platformName, script.getPlatforms())) {
if (script.isDrop() == drops
&& matchPlatform(platformName, script.getPlatforms())) {
logger.debug("include script {}", script.getName());
String value = script.getValue();
sb.append(value);