mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Moved DbMigrationTest/DbMigrationGenerateTest to ebean-test
This commit is contained in:
@@ -8,20 +8,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class LastMigrationTest {
|
||||
|
||||
@Test
|
||||
public void lastVersion() {
|
||||
File d = new File("src/test/resources/dbmigration/migrationtest/h2");
|
||||
assertThat(LastMigration.lastVersion(d, null)).isEqualTo("1.4");
|
||||
assertThat(LastMigration.nextVersion(d, null, false)).isEqualTo("1.5");
|
||||
assertThat(LastMigration.nextVersion(d, null, true)).isEqualTo("1.4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastVersion_no_v_Prefix() {
|
||||
File d = new File("src/test/resources/dbmigration/migrationtest-history");
|
||||
assertThat(LastMigration.lastVersion(d, null)).isEqualTo("1.2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastVersion_test() {
|
||||
File d = new File("src/test/resources/test-dbmigration");
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.sql.Types;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(PlatformCondition.class)
|
||||
public abstract class BaseTestCase {
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(BaseTestCase.class);
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package io.localtest;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.localtest.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PlatformCondition implements ExecutionCondition {
|
||||
|
||||
private static final ConditionEvaluationResult ENABLED = ConditionEvaluationResult.enabled("ForPlatform is not present");
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
|
||||
Optional<AnnotatedElement> element = context.getElement();
|
||||
if (element.isPresent()) {
|
||||
final ForPlatform annotation = element.get().getAnnotation(ForPlatform.class);
|
||||
if (annotation != null && !platformMath(annotation.value())) {
|
||||
return ConditionEvaluationResult.disabled("@ForPlatform");
|
||||
}
|
||||
}
|
||||
return ENABLED;
|
||||
}
|
||||
|
||||
private boolean platformMath(Platform[] platforms) {
|
||||
Platform basePlatform = DB.getDefault().platform().base();
|
||||
for (Platform platform : platforms) {
|
||||
if (platform.equals(basePlatform)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package io.localtest.annotation;
|
||||
|
||||
import io.ebean.annotation.Platform;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation to run a test for a certain platform.
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*/
|
||||
@Target(ElementType.METHOD )
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ForPlatform {
|
||||
Platform[] value();
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package io.localtest.annotation;
|
||||
|
||||
import io.ebean.annotation.Platform;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation to ignore a test for a certain platform.
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*/
|
||||
@Target(ElementType.METHOD )
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface IgnorePlatform {
|
||||
Platform[] value();
|
||||
}
|
||||
@@ -15,36 +15,4 @@ datasource.pg.username=sa
|
||||
datasource.pg.password=
|
||||
datasource.pg.url=jdbc:h2:mem:h2AutoTune
|
||||
|
||||
# parameters for migration test
|
||||
datasource.migrationtest.username=SA
|
||||
datasource.migrationtest.password=SA
|
||||
datasource.migrationtest.url=jdbc:h2:mem:migration;NON_KEYWORDS=KEY,VALUE
|
||||
ebean.migrationtest.applyPrefix=V
|
||||
ebean.migrationtest.ddl.generate=false
|
||||
ebean.migrationtest.ddl.run=false
|
||||
ebean.migrationtest.ddl.header=-- Migrationscripts for ebean unittest
|
||||
ebean.migrationtest.migration.appName=migrationtest
|
||||
ebean.migrationtest.migration.migrationPath=dbmigration/migrationtest
|
||||
ebean.migrationtest.migration.strict=true
|
||||
ebean.migrationtest.migration.generate=true
|
||||
ebean.migrationtest.migration.run=true
|
||||
ebean.migrationtest.migration.includeIndex=true
|
||||
ebean.migrationtest.migration.generateInit=true
|
||||
ebean.migrationtest.migration.generatePendingDrop=auto
|
||||
ebean.migrationtest.migration.platforms=db2luw=db2,h2,hsqldb,mysql,mysql55=mysql55,postgres,oracle,sqlite,sqlserver17=sqlserver17,hana
|
||||
|
||||
# need to generate unique statements to prevent them from being filtered out as duplicates by the DdlRunner
|
||||
ebean.hana.generateUniqueDdl=true
|
||||
|
||||
|
||||
# parameters for migration test
|
||||
datasource.migrationtest-history.username=SA
|
||||
datasource.migrationtest-history.password=SA
|
||||
datasource.migrationtest-history.url=jdbc:h2:mem:migration
|
||||
ebean.migrationtest-history.applyPrefix=V
|
||||
ebean.migrationtest-history.ddl.generate=false
|
||||
ebean.migrationtest-history.ddl.run=false
|
||||
ebean.migrationtest-history.ddl.header=-- Migrationscripts for ebean unittest DbMigrationDropHistoryTest
|
||||
ebean.migrationtest-history.migration.appName=migrationtest-history
|
||||
ebean.migrationtest-history.migration.migrationPath=dbmigration/migrationtest-history
|
||||
ebean.migrationtest-history.migration.strict=true
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.dbmigration;
|
||||
|
||||
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -26,7 +27,7 @@ public class DbMigrationGenerateTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DbMigrationGenerateTest.class);
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
run("ebean-ddl-generator/src/test/resources");
|
||||
run("ebean-test/src/test/resources");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,7 +47,7 @@ public class DbMigrationGenerateTest {
|
||||
config.setPackages(Arrays.asList("misc.migration.v1_0"));
|
||||
|
||||
// First, we clean up the output-directory
|
||||
Files.walk(Paths.get(pathToResources, "dbmigration","migrationtest"))
|
||||
Files.walk(Paths.get(pathToResources, "migrationtest"))
|
||||
.filter(Files::isRegularFile).map(Path::toFile).forEach(File::delete);
|
||||
|
||||
DatabaseFactory.create(config).shutdown();
|
||||
+34
-19
@@ -1,30 +1,46 @@
|
||||
package io.ebeaninternal.dbmigration;
|
||||
|
||||
import io.localtest.BaseTestCase;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.SqlUpdate;
|
||||
import io.localtest.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.Helper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DbMigrationTest extends BaseTestCase {
|
||||
|
||||
private void runScript(boolean expectErrors, String scriptName) throws IOException {
|
||||
String ddl = Helper.asText(this, "/dbmigration/migrationtest/" + server().platform().name().toLowerCase() + "/" + scriptName);
|
||||
runScript(expectErrors, ddl, scriptName);
|
||||
private void runScript(String scriptName) throws IOException {
|
||||
URL url = getClass().getResource("/migrationtest/dbmigration/" + server().platform().name().toLowerCase() + "/" + scriptName);
|
||||
assert url != null : scriptName + " not found";
|
||||
server().script().run(url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastVersion() {
|
||||
File d = new File("src/test/resources/migrationtest/dbmigration/h2");
|
||||
assertThat(LastMigration.lastVersion(d, null)).isEqualTo("1.4");
|
||||
assertThat(LastMigration.nextVersion(d, null, false)).isEqualTo("1.5");
|
||||
assertThat(LastMigration.nextVersion(d, null, true)).isEqualTo("1.4");
|
||||
}
|
||||
|
||||
private void runScript(boolean useAutoCommit, String content, String scriptName) {
|
||||
server().script().runScript(scriptName, content, useAutoCommit);
|
||||
@Test
|
||||
public void lastVersion_no_v_Prefix() {
|
||||
File d = new File("src/test/resources/migrationtest-history/dbmigration");
|
||||
assertThat(LastMigration.lastVersion(d, null)).isEqualTo("1.2");
|
||||
}
|
||||
|
||||
@IgnorePlatform({Platform.ORACLE, Platform.NUODB, Platform.MARIADB})
|
||||
|
||||
@IgnorePlatform({Platform.ORACLE, Platform.NUODB})
|
||||
// Note: This test is currently only executed against H2.
|
||||
// it should be moved to ebean-tests, so that it takes advantage of the docker tests
|
||||
@Test
|
||||
public void testRunMigration() throws IOException {
|
||||
// first clean up previously created objects
|
||||
@@ -57,10 +73,10 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
"migtest_oto_master");
|
||||
|
||||
if (isSqlServer()) { // || isMySql()
|
||||
runScript(false, "I__create_procs.sql");
|
||||
runScript("I__create_procs.sql");
|
||||
}
|
||||
|
||||
runScript(false, "1.0__initial.sql");
|
||||
runScript("1.0__initial.sql");
|
||||
|
||||
if (isOracle() || isHana()) {
|
||||
SqlUpdate update = server().sqlUpdate("insert into migtest_e_basic (id, old_boolean, user_id) values (1, :false, 1)");
|
||||
@@ -81,7 +97,7 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
createHistoryEntities();
|
||||
|
||||
// Run migration
|
||||
runScript(false, "1.1.sql");
|
||||
runScript("1.1.sql");
|
||||
List<SqlRow> result = server().sqlQuery("select * from migtest_e_basic order by id").findList();
|
||||
assertThat(result).hasSize(2);
|
||||
|
||||
@@ -105,11 +121,11 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
assertThat(row.getBoolean("new_boolean_field2")).isTrue();
|
||||
//assertThat(row.getTimestamp("some_date")).isCloseTo(new Date(), 60_000); // allow 1 minute delta
|
||||
|
||||
runScript(false, "1.2__dropsFor_1.1.sql");
|
||||
runScript("1.2__dropsFor_1.1.sql");
|
||||
|
||||
// Oracle caches the statement and does not detect schema change. It fails with
|
||||
// an ORA-01007
|
||||
if (isOracle() || isDB2()) {
|
||||
if (isOracle() || isDb2()) {
|
||||
result = server().sqlQuery("select * from migtest_e_basic order by id,id").findList();
|
||||
} else {
|
||||
result = server().sqlQuery("select * from migtest_e_basic order by id").findList();
|
||||
@@ -118,8 +134,8 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
row = result.get(0);
|
||||
assertThat(row.keySet()).doesNotContain("old_boolean", "old_boolean2");
|
||||
|
||||
runScript(false, "1.3.sql");
|
||||
runScript(false, "1.4__dropsFor_1.3.sql");
|
||||
runScript("1.3.sql");
|
||||
runScript("1.4__dropsFor_1.3.sql");
|
||||
|
||||
// now DB structure shoud be the same as v1_0
|
||||
result = server().sqlQuery("select * from migtest_e_basic order by id").findList();
|
||||
@@ -185,8 +201,7 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
sb.append("drop view ").append(table).append("_with_history;\n");
|
||||
sb.append("drop sequence ").append(table).append("_seq;\n");
|
||||
}
|
||||
System.err.println(sb);
|
||||
runScript(true, sb.toString(), "cleanup");
|
||||
runScript(true, sb.toString(), "cleanup");
|
||||
server().script().runScript("cleanup", sb.toString(), true);
|
||||
server().script().runScript("cleanup", sb.toString(), true);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -36,12 +36,12 @@ public class MysqlGenerateMigrationTest {
|
||||
config.setRunMigration(false);
|
||||
config.getProperties().put("ebean.migrationtest.migration.pathToResources", pathToResources);
|
||||
config.getProperties().put("ebean.migrationtest.migration.platforms", "mysql");
|
||||
config.getProperties().put("ebean.migrationtest.migration.migrationPath", "dbmigration/migrationtest-procedures/");
|
||||
config.getProperties().put("ebean.migrationtest.migration.migrationInitPath", "dbinit/migrationtest-procedures/");
|
||||
config.getProperties().put("ebean.migrationtest.migration.migrationPath", "migrationtest-procedures/dbmigration");
|
||||
config.getProperties().put("ebean.migrationtest.migration.migrationInitPath", "migrationtest-procedures/dbinit");
|
||||
config.setPackages(Arrays.asList("misc.migration.mysql_v1_0"));
|
||||
|
||||
// First, we clean up the output-directory
|
||||
Path path = Paths.get(pathToResources , "dbmigration","migrationtest-procedures");
|
||||
Path path = Paths.get(pathToResources , "migrationtest-procedures");
|
||||
Files.walk(path)
|
||||
.filter(Files::isRegularFile).map(Path::toFile).forEach(File::delete);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class MysqlGenerateMigrationTest {
|
||||
assertThat(DbMigrationPlugin.getLastMigration()).isEqualTo("1.1,1.2__dropsFor_1.1");
|
||||
assertThat(DbMigrationPlugin.getLastInit()).isEqualTo("1.2");
|
||||
|
||||
final Path sqlFile = path.resolve("mysql/1.2__dropsFor_1.1.sql");
|
||||
final Path sqlFile = path.resolve("dbmigration/mysql/1.2__dropsFor_1.1.sql");
|
||||
|
||||
assertThat(sqlFile).isNotEmptyFile();
|
||||
assertThat(Files.readAllLines(sqlFile, StandardCharsets.UTF_8))
|
||||
@@ -0,0 +1,89 @@
|
||||
package misc.migration.mysql_v1_0;
|
||||
|
||||
import io.ebean.annotation.DbDefault;
|
||||
import io.ebean.annotation.EnumValue;
|
||||
import io.ebean.annotation.NotNull;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_basic")
|
||||
public class EBasic {
|
||||
|
||||
public enum Status {
|
||||
@EnumValue("N")
|
||||
NEW,
|
||||
|
||||
@EnumValue("A")
|
||||
ACTIVE,
|
||||
|
||||
@EnumValue("I")
|
||||
INACTIVE,
|
||||
}
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
Status status;
|
||||
|
||||
@DbDefault("N")
|
||||
@NotNull
|
||||
Status status2;
|
||||
|
||||
@Size(max=127)
|
||||
String name;
|
||||
|
||||
@Size(max=127)
|
||||
String description;
|
||||
|
||||
public EBasic() {
|
||||
|
||||
}
|
||||
|
||||
public EBasic(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Status getStatus2() {
|
||||
return status2;
|
||||
}
|
||||
|
||||
public void setStatus2(final Status status2) {
|
||||
this.status2 = status2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package misc.migration.mysql_v1_1;
|
||||
|
||||
import io.ebean.annotation.EnumValue;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_basic")
|
||||
public class EBasic {
|
||||
|
||||
public enum Status {
|
||||
@EnumValue("N")
|
||||
NEW,
|
||||
|
||||
@EnumValue("A")
|
||||
ACTIVE,
|
||||
|
||||
@EnumValue("I")
|
||||
INACTIVE,
|
||||
}
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
Status status;
|
||||
|
||||
@Size(max=127)
|
||||
String name;
|
||||
|
||||
public EBasic() {
|
||||
|
||||
}
|
||||
|
||||
public EBasic(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -51,10 +51,11 @@ public class EBasic {
|
||||
@Size(max=127)
|
||||
String name;
|
||||
|
||||
|
||||
@DbMigration(preAlter = { "-- db2 does not support parial null indices :( - so we have to clean",
|
||||
"update ${table} set status = 'N' where id = 1" }, platforms = Platform.DB2)
|
||||
@DbMigration(preAlter = "-- rename all collisions")
|
||||
@Column(unique = true)
|
||||
@Size(max=127)
|
||||
@Size(max = 127)
|
||||
String description;
|
||||
|
||||
//@NotNull
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package misc.migration.v1_1;
|
||||
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
@@ -18,6 +19,9 @@ public class MtmMaster {
|
||||
@ManyToMany
|
||||
List<MtmChild> children;
|
||||
|
||||
@ElementCollection
|
||||
List<String> phoneNumbers;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -195,18 +195,30 @@ datasource.hana.username=EBEAN_TEST
|
||||
datasource.hana.password=Eb3an_test
|
||||
datasource.hana.url=jdbc:sap://hxehost:39013/?databaseName=HXE
|
||||
#datasource.hana.driver=com.sap.db.jdbc.Driver
|
||||
#
|
||||
|
||||
# parameters for migration test
|
||||
datasource.migrationtest.username=SA
|
||||
datasource.migrationtest.password=SA
|
||||
datasource.migrationtest.url=jdbc:h2:mem:migration
|
||||
datasource.migrationtest.url=jdbc:h2:mem:migration;NON_KEYWORDS=KEY,VALUE
|
||||
ebean.migrationtest.applyPrefix=V
|
||||
ebean.migrationtest.ddl.generate=false
|
||||
ebean.migrationtest.ddl.run=false
|
||||
ebean.migrationtest.ddl.header=-- Migrationscripts for ebean unittest
|
||||
ebean.migrationtest.migration.appName=migrationtest
|
||||
ebean.migrationtest.migration.migrationPath=dbmigration/migrationtest
|
||||
ebean.migrationtest.migration.migrationPath=migrationtest/dbmigration
|
||||
ebean.migrationtest.migration.migrationInitPath=migrationtest/dbinit
|
||||
ebean.migrationtest.migration.strict=true
|
||||
ebean.migrationtest.migration.generate=true
|
||||
ebean.migrationtest.migration.run=true
|
||||
ebean.migrationtest.migration.includeIndex=true
|
||||
ebean.migrationtest.migration.generateInit=true
|
||||
ebean.migrationtest.migration.generatePendingDrop=auto
|
||||
ebean.migrationtest.migration.platforms=db2luw=db2,h2,hsqldb,mysql,mysql55=mysql55,postgres,oracle,sqlite,sqlserver17=sqlserver17,hana
|
||||
|
||||
# need to generate unique statements to prevent them from being filtered out as duplicates by the DdlRunner
|
||||
ebean.hana.generateUniqueDdl=true
|
||||
|
||||
|
||||
# parameters for migration test
|
||||
datasource.migrationtest-history.username=SA
|
||||
@@ -217,5 +229,6 @@ ebean.migrationtest-history.ddl.generate=false
|
||||
ebean.migrationtest-history.ddl.run=false
|
||||
ebean.migrationtest-history.ddl.header=-- Migrationscripts for ebean unittest DbMigrationDropHistoryTest
|
||||
ebean.migrationtest-history.migration.appName=migrationtest-history
|
||||
ebean.migrationtest-history.migration.migrationPath=dbmigration/migrationtest-history
|
||||
ebean.migrationtest-history.migration.strict=true
|
||||
ebean.migrationtest-history.migration.migrationPath=migrationtest-history/dbmigration
|
||||
ebean.migrationtest-history.migration.migrationInitPath=migrationtest-history/dbinit
|
||||
ebean.migrationtest-history.migration.strict=true
|
||||
Reference in New Issue
Block a user