mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2600 - Pending drops migration with the same version of the target migration cause trouble
This commit is contained in:
+20
-18
@@ -1,17 +1,5 @@
|
||||
package io.ebeaninternal.dbmigration;
|
||||
|
||||
import static io.ebeaninternal.api.PlatformMatch.matchPlatform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.annotation.Platform;
|
||||
@@ -50,15 +38,21 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlOptions;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
|
||||
import io.ebeaninternal.dbmigration.migration.Migration;
|
||||
import io.ebeaninternal.dbmigration.migrationreader.MigrationXmlWriter;
|
||||
import io.ebeaninternal.dbmigration.model.CurrentModel;
|
||||
import io.ebeaninternal.dbmigration.model.MConfiguration;
|
||||
import io.ebeaninternal.dbmigration.model.MigrationModel;
|
||||
import io.ebeaninternal.dbmigration.model.ModelContainer;
|
||||
import io.ebeaninternal.dbmigration.model.ModelDiff;
|
||||
import io.ebeaninternal.dbmigration.model.PlatformDdlWriter;
|
||||
import io.ebeaninternal.dbmigration.model.*;
|
||||
import io.ebeaninternal.extraddl.model.DdlScript;
|
||||
import io.ebeaninternal.extraddl.model.ExtraDdl;
|
||||
import io.ebeaninternal.extraddl.model.ExtraDdlXmlReader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import static io.ebeaninternal.api.PlatformMatch.matchPlatform;
|
||||
|
||||
/**
|
||||
* Generates DB Migration xml and sql scripts.
|
||||
@@ -611,6 +605,7 @@ public class DefaultDbMigration implements DbMigration {
|
||||
if (version == null) {
|
||||
version = (nextVersion != null) ? nextVersion : initialVersion;
|
||||
}
|
||||
checkDropVersion(version, dropsFor);
|
||||
|
||||
String fullVersion = applyPrefix + version;
|
||||
String name = name();
|
||||
@@ -626,6 +621,13 @@ public class DefaultDbMigration implements DbMigration {
|
||||
return fullVersion;
|
||||
}
|
||||
|
||||
void checkDropVersion(String version, String dropsFor) {
|
||||
if (dropsFor != null && dropsFor.equals(version)) {
|
||||
throw new IllegalArgumentException("The next migration version must not be the same as the pending drops version of " +
|
||||
dropsFor + ". Please make the next migration version higher than " + dropsFor + ".");
|
||||
}
|
||||
}
|
||||
|
||||
String trimDropsFor(String dropsFor) {
|
||||
if (dropsFor.startsWith("V") || dropsFor.startsWith("v")) {
|
||||
dropsFor = dropsFor.substring(1);
|
||||
|
||||
+15
-2
@@ -3,13 +3,14 @@ package io.ebeaninternal.dbmigration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class DefaultDbMigrationTest {
|
||||
class DefaultDbMigrationTest {
|
||||
|
||||
private final DefaultDbMigration migration = new DefaultDbMigration();
|
||||
|
||||
@Test
|
||||
public void trimDropsFor() {
|
||||
void trimDropsFor() {
|
||||
assertEquals("1.2", migration.trimDropsFor("V1.2__hello"));
|
||||
assertEquals("1.2", migration.trimDropsFor("v1.2__hello"));
|
||||
assertEquals("1.2", migration.trimDropsFor("v1.2"));
|
||||
@@ -17,4 +18,16 @@ public class DefaultDbMigrationTest {
|
||||
assertEquals("junk1.2", migration.trimDropsFor("junk1.2__"));
|
||||
assertEquals("junk1.2", migration.trimDropsFor("junk1.2__more"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkDropVersion_when_matches_throwsIAE() {
|
||||
assertThrows(IllegalArgumentException.class, () -> migration.checkDropVersion("1.0", "1.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkDropVersion_ok() {
|
||||
migration.checkDropVersion("1.0", null);
|
||||
migration.checkDropVersion("1.0", "1.0.0");
|
||||
migration.checkDropVersion("1.0", "1.1");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user