diff --git a/src/main/java/io/ebean/config/DbMigrationConfig.java b/src/main/java/io/ebean/config/DbMigrationConfig.java index d09f3430a..cdbb3a416 100644 --- a/src/main/java/io/ebean/config/DbMigrationConfig.java +++ b/src/main/java/io/ebean/config/DbMigrationConfig.java @@ -28,34 +28,6 @@ public class DbMigrationConfig { */ protected Platform platform; - /** - * Set to true if the DB migration should be generated on server start. - */ - protected boolean generate; - - /** - * The migration version name (typically FlywayDb compatible). - *
- * Example: 1.1.1_2 - *
- * The version is expected to be the combination of the current pom version plus - * a 'feature' id. The combined version must be unique and ordered to work with - * FlywayDb so each developer sets a unique version so that the migration script - * generated is unique (typically just prior to being submitted as a merge request). - */ - protected String version; - - /** - * Description text that can be appended to the version to become the ddl script file name. - *
- * So if the name is "a foo table" then the ddl script file could be: - * "1.1.1_2__a-foo-table.sql" - *
- * When the DB migration relates to a git feature (merge request) then this description text - * is a short description of the feature. - */ - protected String name; - /** * Resource path for the migration xml and sql. */ @@ -75,13 +47,6 @@ public class DbMigrationConfig { protected String modelSuffix = ".model.xml"; - protected boolean includeGeneratedFileComment; - - /** - * The version of a pending drop that should be generated as the next migration. - */ - protected String generatePendingDrop; - /** * For running migration the DB table that holds migration execution status. */ @@ -228,52 +193,6 @@ public class DbMigrationConfig { this.applyPrefix = applyPrefix; } - /** - * Return true if the generated file comment should be included. - */ - public boolean isIncludeGeneratedFileComment() { - return includeGeneratedFileComment; - } - - /** - * Set to true if the generated file comment should be included. - */ - public void setIncludeGeneratedFileComment(boolean includeGeneratedFileComment) { - this.includeGeneratedFileComment = includeGeneratedFileComment; - } - - /** - * Return the migration version (or "next") to generate pending drops for. - */ - public String getGeneratePendingDrop() { - return generatePendingDrop; - } - - /** - * Set the migration version (or "next") to generate pending drops for. - */ - public void setGeneratePendingDrop(String generatePendingDrop) { - this.generatePendingDrop = generatePendingDrop; - } - - /** - * Set the migration version. - *
- * Note that version set via System property or environment variable ddl.migration.version takes precedence.
- */
- public void setVersion(String version) {
- this.version = version;
- }
-
- /**
- * Set the migration name.
- *
- * Note that name set via System property or environment variable ddl.migration.name takes precedence.
- */
- public void setName(String name) {
- this.name = name;
- }
-
/**
* Return the table name that holds the migration run details
* (used by DB Migration runner only).
@@ -504,14 +423,8 @@ public class DbMigrationConfig {
applyPrefix = properties.get("migration.applyPrefix", applyPrefix);
applySuffix = properties.get("migration.applySuffix", applySuffix);
modelSuffix = properties.get("migration.modelSuffix", modelSuffix);
- includeGeneratedFileComment = properties.getBoolean("migration.includeGeneratedFileComment", includeGeneratedFileComment);
- generatePendingDrop = properties.get("migration.generatePendingDrop", generatePendingDrop);
platform = properties.getEnum(Platform.class, "migration.platform", platform);
-
- generate = properties.getBoolean("migration.generate", generate);
- version = properties.get("migration.version", version);
- name = properties.get("migration.name", name);
patchInsertOn = properties.get("migration.patchInsertOn", patchInsertOn);
patchResetChecksumOn = properties.get("migration.patchResetChecksumOn", patchResetChecksumOn);
@@ -532,44 +445,6 @@ public class DbMigrationConfig {
ddlHeader = properties.get("ddl.header", ddlHeader);
}
- /**
- * Return the migration version (typically FlywayDb compatible).
- *
- * Example: 1.1.1_2 - *
- * The version is expected to be the combination of the current pom version plus - * a 'feature' id. The combined version must be unique and ordered to work with - * FlywayDb so each developer sets a unique version so that the migration script - * generated is unique (typically just prior to being submitted as a merge request). - */ - public String getVersion() { - String envVersion = readEnvironment("ddl.migration.version"); - if (!isEmpty(envVersion)) { - return envVersion.trim(); - } - return version; - } - - /** - * Return the migration name which is short description text that can be appended to - * the migration version to become the ddl script file name. - *
- * So if the name is "a foo table" then the ddl script file could be: - * "1.1.1_2__a-foo-table.sql" - *
- *- * When the DB migration relates to a git feature (merge request) then this description text - * is a short description of the feature. - *
- */ - public String getName() { - String envName = readEnvironment("ddl.migration.name"); - if (!isEmpty(envName)) { - return envName.trim(); - } - return name; - } - /** * Return the system or environment property. */ diff --git a/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java b/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java index 5ae428a10..2eced70a2 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java +++ b/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java @@ -58,7 +58,7 @@ import java.util.List; * * DbMigration migration = DbMigration.create(); * migration.setPathToResources("src/main/resources"); - * migration.setPlatform(DbPlatformName.ORACLE); + * migration.setPlatform(Platform.POSTGRES); * * migration.generateMigration(); * @@ -513,10 +513,7 @@ public class DefaultDbMigration implements DbMigration { if (nextDrop != null) { return nextDrop; } - if (generatePendingDrop != null) { - return generatePendingDrop; - } - return migrationConfig.getGeneratePendingDrop(); + return generatePendingDrop; } /** @@ -526,14 +523,15 @@ public class DefaultDbMigration implements DbMigration { */ private String getFullVersion(MigrationModel migrationModel, String dropsFor) { - String version = migrationConfig.getVersion(); + String version = getVersion(); if (version == null) { version = migrationModel.getNextVersion(initialVersion); } String fullVersion = migrationConfig.getApplyPrefix() + version; - if (migrationConfig.getName() != null) { - fullVersion += "__" + toUnderScore(migrationConfig.getName()); + String name = getName(); + if (name != null) { + fullVersion += "__" + toUnderScore(name); } else if (dropsFor != null) { fullVersion += "__" + toUnderScore("dropsFor_" + MigrationVersion.trim(dropsFor)); @@ -580,7 +578,7 @@ public class DefaultDbMigration implements DbMigration { if (file.exists()) { return false; } - String comment = migrationConfig.isIncludeGeneratedFileComment() ? GENERATED_COMMENT : null; + String comment = Boolean.TRUE.equals(includeGeneratedFileComment) ? GENERATED_COMMENT : null; MigrationXmlWriter xmlWriter = new MigrationXmlWriter(comment); xmlWriter.write(dbMigration, file); return true; @@ -608,18 +606,66 @@ public class DefaultDbMigration implements DbMigration { if (header != null) { migrationConfig.setDdlHeader(header); } - if (includeGeneratedFileComment != null) { - migrationConfig.setIncludeGeneratedFileComment(includeGeneratedFileComment); - } - if (version != null) { - migrationConfig.setVersion(version); - } - if (name != null) { - migrationConfig.setName(name); - } } } + /** + * Return the migration version (typically FlywayDb compatible). + *+ * Example: 1.1.1_2 + *
+ * The version is expected to be the combination of the current pom version plus + * a 'feature' id. The combined version must be unique and ordered to work with + * FlywayDb so each developer sets a unique version so that the migration script + * generated is unique (typically just prior to being submitted as a merge request). + */ + private String getVersion() { + String envVersion = readEnvironment("ddl.migration.version"); + if (!isEmpty(envVersion)) { + return envVersion.trim(); + } + return version; + } + + /** + * Return the migration name which is short description text that can be appended to + * the migration version to become the ddl script file name. + *
+ * So if the name is "a foo table" then the ddl script file could be: + * "1.1.1_2__a-foo-table.sql" + *
+ *+ * When the DB migration relates to a git feature (merge request) then this description text + * is a short description of the feature. + *
+ */ + private String getName() { + String envName = readEnvironment("ddl.migration.name"); + if (!isEmpty(envName)) { + return envName.trim(); + } + return name; + } + + /** + * Return true if the string is null or empty. + */ + private boolean isEmpty(String val) { + return val == null || val.trim().isEmpty(); + } + + /** + * Return the system or environment property. + */ + private String readEnvironment(String key) { + + String val = System.getProperty(key); + if (val == null) { + val = System.getenv(key); + } + return val; + } + /** * Return the file path to write the xml and sql to. */