Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	ebean-bom/pom.xml
This commit is contained in:
Noemi Praml
2022-05-24 10:06:50 +02:00
23 changed files with 130 additions and 49 deletions
+2 -2
View File
@@ -62,8 +62,8 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test-docker</artifactId>
<version>${ebean-test-docker.version}</version>
<artifactId>ebean-test-containers</artifactId>
<version>${ebean-test-containers.version}</version>
</dependency>
<!-- modules -->
@@ -28,7 +28,7 @@ public class MTable {
private static final Logger logger = LoggerFactory.getLogger(MTable.class);
private final String name;
private String name;
private MTable draftTable;
/**
* Marked true for draft tables. These need to have their FK references adjusted
@@ -408,6 +408,14 @@ public class MTable {
addColumn(column.rename(renameColumn.getNewName()));
}
/**
* Apply table rename to the model.
*/
public void apply(RenameTable renameTable) {
checkTableName(renameTable.getOldName());
this.name = renameTable.getNewName();
}
public String getName() {
return name;
}
@@ -547,7 +555,7 @@ public class MTable {
private void checkTableName(String tableName) {
if (!name.equals(tableName)) {
throw new IllegalArgumentException("addColumn tableName [" + tableName + "] does not match [" + name + "]");
throw new IllegalArgumentException("tableName [" + tableName + "] does not match [" + name + "]");
}
}
@@ -2,24 +2,7 @@ package io.ebeaninternal.dbmigration.model;
import io.ebean.migration.MigrationVersion;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.DdlHelp;
import io.ebeaninternal.dbmigration.migration.AddColumn;
import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
import io.ebeaninternal.dbmigration.migration.AlterTable;
import io.ebeaninternal.dbmigration.migration.ChangeSet;
import io.ebeaninternal.dbmigration.migration.ChangeSetType;
import io.ebeaninternal.dbmigration.migration.CreateIndex;
import io.ebeaninternal.dbmigration.migration.CreateTable;
import io.ebeaninternal.dbmigration.migration.DropColumn;
import io.ebeaninternal.dbmigration.migration.DropHistoryTable;
import io.ebeaninternal.dbmigration.migration.DropIndex;
import io.ebeaninternal.dbmigration.migration.DropTable;
import io.ebeaninternal.dbmigration.migration.Migration;
import io.ebeaninternal.dbmigration.migration.RenameColumn;
import io.ebeaninternal.dbmigration.migration.Sql;
import io.ebeaninternal.dbmigration.migration.*;
import io.ebeaninternal.server.deploy.TablespaceMeta;
import java.util.ArrayList;
@@ -122,14 +105,11 @@ public class ModelContainer {
* Apply a migration with associated changeSets to the model.
*/
public void apply(Migration migration, MigrationVersion version) {
List<ChangeSet> changeSets = migration.getChangeSet();
for (ChangeSet changeSet : changeSets) {
for (ChangeSet changeSet : migration.getChangeSet()) {
boolean pending = changeSet.getType() == ChangeSetType.PENDING_DROPS;
if (pending) {
// un-applied drop columns etc
pendingDrops.add(version, changeSet);
} else if (isDropsFor(changeSet)) {
pendingDrops.appliedDropsFor(changeSet);
}
@@ -150,15 +130,15 @@ public class ModelContainer {
* Apply a changeSet to the model.
*/
protected void applyChangeSet(ChangeSet changeSet) {
List<Object> changeSetChildren = changeSet.getChangeSetChildren();
for (Object change : changeSetChildren) {
for (Object change : changeSet.getChangeSetChildren()) {
if (change instanceof CreateTable) {
applyChange((CreateTable) change);
} else if (change instanceof DropTable) {
applyChange((DropTable) change);
} else if (change instanceof AlterTable) {
applyChange((AlterTable) change);
} else if (change instanceof RenameTable) {
applyChange((RenameTable) change);
} else if (change instanceof AlterColumn) {
applyChange((AlterColumn) change);
} else if (change instanceof AddColumn) {
@@ -265,7 +245,7 @@ public class ModelContainer {
protected void applyChange(DropTable dropTable) {
tables.remove(dropTable.getName());
}
/**
* Apply a AlterTable change to the model.
*/
@@ -294,6 +274,19 @@ public class ModelContainer {
}
}
protected void applyChange(RenameTable renameTable) {
MTable notExpected = tables.get(renameTable.getNewName());
if (notExpected != null) {
throw new IllegalStateException("RenameTable to newName [" + renameTable.getNewName() + "] but this table already exists in the model?");
}
MTable table = tables.remove(renameTable.getOldName());
if (table == null) {
throw new IllegalStateException("RenameTable oldName [" + renameTable.getOldName() + "] does not exist in model?");
}
table.apply(renameTable);
tables.put(renameTable.getNewName(), table);
}
/**
* Apply a CreateTable change to the model.
*/
@@ -10,6 +10,7 @@ import java.util.List;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class ModelContainerTest {
@@ -152,6 +153,42 @@ class ModelContainerTest {
assertThat(table.getColumn("short_title")).isNull();
}
@Test
void apply_renameTable() {
ModelContainer container = new ModelContainer();
container.apply(mig("7.0__renameTable.model.xml"), ver("7.0"));
final MTable table = container.getTable("document_newname");
assertThat(table.getColumn("title")).isNotNull();
assertThat(table.getColumn("short_title")).isNull();
}
@Test
void apply_renameTable_when_oldTableNotFound() {
ModelContainer container = new ModelContainer();
assertThatThrownBy(() -> {
container.apply(mig("7.0__renameTable.errOldTable.xml"), ver("7.0"));
}).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("RenameTable oldName");
final MTable table = container.getTable("document");
assertThat(table.getColumn("title")).isNotNull();
}
@Test
void apply_renameTable_when_newTableAlreadyExists() {
ModelContainer container = new ModelContainer();
assertThatThrownBy(() -> {
container.apply(mig("7.0__renameTable.errNewTable.xml"), ver("7.0"));
}).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("RenameTable to newName");
final MTable table = container.getTable("document");
assertThat(table.getColumn("title")).isNotNull();
}
@Test
void getSchemas() {
MTable t0 = new MTable("foo.one");
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply">
<createTable name="document" withHistory="true" pkName="pk_document">
<column name="id" type="bigint" primaryKey="true" references="document_draft.id" foreignKeyName="fk_document_id"/>
<column name="title" type="varchar(255)"/>
</createTable>
<createTable name="document_newname" pkName="pk_document">
<column name="id" type="bigint"/>
</createTable>
<renameTable oldName="document" newName="document_newname"/>
</changeSet>
</migration>
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply">
<createTable name="document" withHistory="true" pkName="pk_document">
<column name="id" type="bigint" primaryKey="true" references="document_draft.id" foreignKeyName="fk_document_id"/>
<column name="title" type="varchar(255)"/>
</createTable>
<renameTable oldName="document_doesNotExist" newName="document_newname"/>
</changeSet>
</migration>
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply">
<createTable name="document" withHistory="true" pkName="pk_document">
<column name="id" type="bigint" primaryKey="true" references="document_draft.id" foreignKeyName="fk_document_id"/>
<column name="title" type="varchar(255)"/>
</createTable>
<renameTable oldName="document" newName="document_newname"/>
</changeSet>
</migration>
+2 -2
View File
@@ -61,8 +61,8 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test-docker</artifactId>
<version>${ebean-test-docker.version}</version>
<artifactId>ebean-test-containers</artifactId>
<version>${ebean-test-containers.version}</version>
</dependency>
<dependency>
@@ -1,6 +1,6 @@
package io.ebean.test.config.platform;
import io.ebean.docker.commands.ElasticContainer;
import io.ebean.test.containers.ElasticContainer;
import java.util.Properties;
@@ -1,7 +1,7 @@
package io.ebean.test.config.platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.docker.container.ContainerFactory;
import io.ebean.test.containers.ContainerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1,6 +1,6 @@
package io.ebean.test.config.platform;
import io.ebean.docker.commands.RedisContainer;
import io.ebean.test.containers.RedisContainer;
import java.util.Properties;
+1 -1
View File
@@ -18,7 +18,7 @@ open module io.ebean.test {
requires com.fasterxml.jackson.databind;
requires com.fasterxml.jackson.datatype.jsr310;
requires transitive io.ebean.docker;
requires transitive io.ebean.test.containers;
requires transitive org.assertj.core;
requires transitive java.xml.bind;
requires transitive com.h2database;
@@ -1,6 +1,6 @@
package main;
import io.ebean.docker.commands.CockroachContainer;
import io.ebean.test.containers.CockroachContainer;
public class StartCockroach {
+1 -1
View File
@@ -1,6 +1,6 @@
package main;
import io.ebean.docker.commands.Db2Container;
import io.ebean.test.containers.Db2Container;
public class StartDb2 {
@@ -1,6 +1,6 @@
package main;
import io.ebean.docker.commands.MariaDBContainer;
import io.ebean.test.containers.MariaDBContainer;
public class StartMariaDb {
@@ -1,6 +1,6 @@
package main;
import io.ebean.docker.commands.MySqlContainer;
import io.ebean.test.containers.MySqlContainer;
public class StartMySql {
@@ -1,6 +1,6 @@
package main;
import io.ebean.docker.commands.NuoDBContainer;
import io.ebean.test.containers.NuoDBContainer;
public class StartNuoDB {
@@ -1,6 +1,6 @@
package main;
import io.ebean.docker.commands.OracleContainer;
import io.ebean.test.containers.OracleContainer;
public class StartOracle {
@@ -1,6 +1,6 @@
package main;
import io.ebean.docker.commands.PostgresContainer;
import io.ebean.test.containers.PostgresContainer;
public class StartPostgres {
@@ -1,6 +1,6 @@
package main;
import io.ebean.docker.commands.SqlServerContainer;
import io.ebean.test.containers.SqlServerContainer;
public class StartSqlServer {
@@ -1,6 +1,6 @@
package main;
import io.ebean.docker.commands.YugabyteContainer;
import io.ebean.test.containers.YugabyteContainer;
public class StartYugabyte {
+3 -3
View File
@@ -44,10 +44,10 @@
<ebean-ddl-runner.version>2.0</ebean-ddl-runner.version>
<ebean-migration-auto.version>1.2</ebean-migration-auto.version>
<ebean-migration.version>13.6.0</ebean-migration.version>
<ebean-test-docker.version>5.3</ebean-test-docker.version>
<ebean-test-containers.version>6.0</ebean-test-containers.version>
<ebean-datasource.version>8.0</ebean-datasource.version>
<ebean-agent.version>13.6.2</ebean-agent.version>
<ebean-maven-plugin.version>13.6.2</ebean-maven-plugin.version>
<ebean-agent.version>13.6.3</ebean-agent.version>
<ebean-maven-plugin.version>13.6.3</ebean-maven-plugin.version>
<surefire.useModulePath>false</surefire.useModulePath>
</properties>
+1 -1
View File
@@ -52,7 +52,7 @@
<path>
<groupId>io.ebean</groupId>
<artifactId>querybean-generator</artifactId>
<version>13.6.3-SNAPSHOT</version>
<version>13.6.4-SNAPSHOT</version>
</path>
</annotationProcessorPaths>
</configuration>