mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#557 - DDL - DB Migration refactor - remove drop.ddl and use pendingDrops.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Created by rob on 11/02/16.
|
||||
*/
|
||||
public class FooTest {//
|
||||
|
||||
interface Colour {
|
||||
int RED = 1;
|
||||
}
|
||||
|
||||
static class SuperTest {
|
||||
int RED = 999;
|
||||
}
|
||||
|
||||
static class Test extends SuperTest implements Colour {
|
||||
|
||||
String RED = "RED";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Test().printV();
|
||||
}
|
||||
|
||||
void printV() {
|
||||
System.out.println(super.RED + " " + this.RED + " " + RED + " " + Colour.RED);
|
||||
}
|
||||
}
|
||||
|
||||
// static class Test3 {
|
||||
// public static void main(String[] args) {
|
||||
// new Test().printV();
|
||||
// }
|
||||
//
|
||||
// void printV2() {
|
||||
// System.out.println(Colour.order);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
@@ -33,9 +33,6 @@ public class H2HistoryDdlTest {
|
||||
h2Ddl.configure(ebeanServer.getServerConfig());
|
||||
h2Ddl.regenerateHistoryTriggers(write, update);
|
||||
|
||||
assertThat(write.dropHistory().isEmpty()).isFalse();
|
||||
assertThat(write.dropHistory().getBuffer()).contains("drop two");
|
||||
|
||||
assertThat(write.applyHistory().isEmpty()).isFalse();
|
||||
assertThat(write.applyHistory().getBuffer()).contains("add one");
|
||||
assertThat(write.applyHistory().getBuffer()).doesNotContain("two");
|
||||
|
||||
+2
-16
@@ -17,8 +17,6 @@ public class HistoryTableUpdateTest {
|
||||
assertThat(upd.getBaseTable()).isEqualTo("mytab");
|
||||
|
||||
upd.add(HistoryTableUpdate.Change.ADD, "two");
|
||||
assertThat(upd.hasApplyChanges()).isTrue();
|
||||
assertThat(upd.hasDropChanges()).isFalse();
|
||||
|
||||
List<String> current = current();
|
||||
upd.toRevertedColumns(current);
|
||||
@@ -30,8 +28,6 @@ public class HistoryTableUpdateTest {
|
||||
|
||||
HistoryTableUpdate upd = new HistoryTableUpdate("mytab");
|
||||
upd.add(HistoryTableUpdate.Change.INCLUDE, "two");
|
||||
assertThat(upd.hasApplyChanges()).isTrue();
|
||||
assertThat(upd.hasDropChanges()).isFalse();
|
||||
|
||||
List<String> current = current();
|
||||
upd.toRevertedColumns(current);
|
||||
@@ -43,8 +39,6 @@ public class HistoryTableUpdateTest {
|
||||
|
||||
HistoryTableUpdate upd = new HistoryTableUpdate("mytab");
|
||||
upd.add(HistoryTableUpdate.Change.DROP, "three");
|
||||
assertThat(upd.hasApplyChanges()).isFalse();
|
||||
assertThat(upd.hasDropChanges()).isTrue();
|
||||
|
||||
List<String> current = current();
|
||||
upd.toRevertedColumns(current);
|
||||
@@ -56,8 +50,6 @@ public class HistoryTableUpdateTest {
|
||||
|
||||
HistoryTableUpdate upd = new HistoryTableUpdate("mytab");
|
||||
upd.add(HistoryTableUpdate.Change.EXCLUDE, "four");
|
||||
assertThat(upd.hasApplyChanges()).isTrue();
|
||||
assertThat(upd.hasDropChanges()).isFalse();
|
||||
|
||||
List<String> current = current();
|
||||
upd.toRevertedColumns(current);
|
||||
@@ -71,11 +63,8 @@ public class HistoryTableUpdateTest {
|
||||
HistoryTableUpdate upd = new HistoryTableUpdate("mytab");
|
||||
upd.add(HistoryTableUpdate.Change.ADD, "two");
|
||||
upd.add(HistoryTableUpdate.Change.DROP, "four");
|
||||
assertThat(upd.hasApplyChanges()).isTrue();
|
||||
assertThat(upd.hasDropChanges()).isTrue();
|
||||
|
||||
assertThat(upd.descriptionForApply()).isEqualTo("add two");
|
||||
assertThat(upd.descriptionForDrop()).isEqualTo("drop four");
|
||||
assertThat(upd.description()).isEqualTo("add two");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,11 +75,8 @@ public class HistoryTableUpdateTest {
|
||||
upd.add(HistoryTableUpdate.Change.INCLUDE, "five");
|
||||
upd.add(HistoryTableUpdate.Change.EXCLUDE, "six");
|
||||
upd.add(HistoryTableUpdate.Change.DROP, "four");
|
||||
assertThat(upd.hasApplyChanges()).isTrue();
|
||||
assertThat(upd.hasDropChanges()).isTrue();
|
||||
|
||||
assertThat(upd.descriptionForApply()).isEqualTo("add two, include five, exclude six");
|
||||
assertThat(upd.descriptionForDrop()).isEqualTo("drop four");
|
||||
assertThat(upd.description()).isEqualTo("add two, include five, exclude six");
|
||||
}
|
||||
|
||||
List<String> current() {
|
||||
|
||||
@@ -57,11 +57,11 @@ public class MTableTest {
|
||||
public void test_allHistoryColumns() throws Exception {
|
||||
|
||||
MTable base = base();
|
||||
base.registerDroppedColumn("fullName",2);
|
||||
base.registerDroppedColumn("last",4);
|
||||
base.registerPendingDropColumn("fullName");
|
||||
base.registerPendingDropColumn("last");
|
||||
|
||||
assertThat(base.allHistoryColumns(false)).containsExactly("id","name","status");
|
||||
assertThat(base.allHistoryColumns(true)).containsExactly("id","name","fullName","status","last");
|
||||
assertThat(base.allHistoryColumns(true)).containsExactly("id","name","status","fullName","last");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -6,8 +6,47 @@ import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
|
||||
public class MigrationVersionTest {
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testParse() throws Exception {
|
||||
public void test_parse_getComment() throws Exception {
|
||||
|
||||
assertThat(MigrationVersion.parse("1.1.1_2__Foo").getComment()).isEqualTo("Foo");
|
||||
assertThat(MigrationVersion.parse("1.1.1.2__junk").getComment()).isEqualTo("junk");
|
||||
assertThat(MigrationVersion.parse("1.1_1.2_foo").getComment()).isEqualTo("");
|
||||
assertThat(MigrationVersion.parse("1.1_1.2_d").getComment()).isEqualTo("");
|
||||
assertThat(MigrationVersion.parse("1.1_1.2_").getComment()).isEqualTo("");
|
||||
assertThat(MigrationVersion.parse("1.1_1.2").getComment()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_nextVersion_expect_preserveUnderscores() {
|
||||
|
||||
assertThat(MigrationVersion.parse("2").nextVersion()).isEqualTo("3");
|
||||
assertThat(MigrationVersion.parse("1.0").nextVersion()).isEqualTo("1.1");
|
||||
assertThat(MigrationVersion.parse("2.0.b34").nextVersion()).isEqualTo("2.1");
|
||||
assertThat(MigrationVersion.parse("1.1.1_2__Foo").nextVersion()).isEqualTo("1.1.1_3");
|
||||
assertThat(MigrationVersion.parse("1.1.1.2_junk").nextVersion()).isEqualTo("1.1.1.3");
|
||||
assertThat(MigrationVersion.parse("1_2.3_4__Foo").nextVersion()).isEqualTo("1_2.3_5");
|
||||
assertThat(MigrationVersion.parse("1_2.3_4_").nextVersion()).isEqualTo("1_2.3_5");
|
||||
assertThat(MigrationVersion.parse("1_2_3_4__Foo").nextVersion()).isEqualTo("1_2_3_5");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_normalised_expect_periods() {
|
||||
|
||||
assertThat(MigrationVersion.parse("2").normalised()).isEqualTo("2");
|
||||
assertThat(MigrationVersion.parse("1.0").normalised()).isEqualTo("1.0");
|
||||
assertThat(MigrationVersion.parse("2.0.b34").normalised()).isEqualTo("2.0");
|
||||
assertThat(MigrationVersion.parse("1.1.1_2__Foo").normalised()).isEqualTo("1.1.1.2");
|
||||
assertThat(MigrationVersion.parse("1.1.1.2_junk").normalised()).isEqualTo("1.1.1.2");
|
||||
assertThat(MigrationVersion.parse("1_2.3_4__Foo").normalised()).isEqualTo("1.2.3.4");
|
||||
assertThat(MigrationVersion.parse("1_2.3_4_").normalised()).isEqualTo("1.2.3.4");
|
||||
assertThat(MigrationVersion.parse("1_2_3_4__Foo").normalised()).isEqualTo("1.2.3.4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_compareTo_isEqual() throws Exception {
|
||||
|
||||
MigrationVersion v0 = MigrationVersion.parse("1.1.1_2__Foo");
|
||||
MigrationVersion v1 = MigrationVersion.parse("1.1.1.2_junk");
|
||||
@@ -16,32 +55,21 @@ public class MigrationVersionTest {
|
||||
assertThat(v0.compareTo(v1)).isEqualTo(0);
|
||||
assertThat(v1.compareTo(v0)).isEqualTo(0);
|
||||
assertThat(v1.compareTo(v2)).isEqualTo(0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextVersion() {
|
||||
|
||||
assertThat(MigrationVersion.parse("2").nextVersion()).isEqualTo("3");
|
||||
assertThat(MigrationVersion.parse("1.0").nextVersion()).isEqualTo("1.1");
|
||||
assertThat(MigrationVersion.parse("2.0.b34").nextVersion()).isEqualTo("2.1");
|
||||
assertThat(MigrationVersion.parse("1.1.1_2__Foo").nextVersion()).isEqualTo("1.1.1.3");
|
||||
assertThat(MigrationVersion.parse("1.1.1.2_junk").nextVersion()).isEqualTo("1.1.1.3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTo() throws Exception {
|
||||
public void test_compareTo() throws Exception {
|
||||
|
||||
MigrationVersion v0 = MigrationVersion.parse("1.1.1.1_junk");
|
||||
MigrationVersion v1 = MigrationVersion.parse("1.1.1.2_junk");
|
||||
MigrationVersion v2 = MigrationVersion.parse("2.1_1.2_junk");
|
||||
MigrationVersion v2 = MigrationVersion.parse("1.1_1.3_junk");
|
||||
MigrationVersion v3 = MigrationVersion.parse("1.2_1.2_junk");
|
||||
MigrationVersion v4 = MigrationVersion.parse("1.1_1.3_junk");
|
||||
MigrationVersion v5 = MigrationVersion.parse("1.1.1.1_junk");
|
||||
MigrationVersion v4 = MigrationVersion.parse("2.1_1.2_junk");
|
||||
|
||||
assertThat(v1.compareTo(v0)).isEqualTo(1);
|
||||
|
||||
assertThat(v1.compareTo(v2)).isEqualTo(-1);
|
||||
assertThat(v1.compareTo(v3)).isEqualTo(-1);
|
||||
assertThat(v1.compareTo(v4)).isEqualTo(-1);
|
||||
|
||||
assertThat(v1.compareTo(v5)).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class ModelContainerApplyTest {
|
||||
assertThat(changeSetChildren.get(2)).isInstanceOf(DropColumn.class);
|
||||
|
||||
ModelContainer model = new ModelContainer();
|
||||
model.apply(migration);
|
||||
model.apply(migration, MigrationVersion.parse("1.1"));
|
||||
|
||||
MTable foo = model.getTable("foo");
|
||||
assertThat(foo.getComment()).isEqualTo("comment");
|
||||
|
||||
Reference in New Issue
Block a user