mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
#2702 - IllegalArgumentException: No rule for io.ebeaninternal.dbmigration.migration.RenameTable
Add support for applying the RenameTable change to the model.
This commit is contained in:
1 parent
8106ffd73d
commit
68680ffd34
6 files changed
+109
-28
No files matched your search
@@ -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 + "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-26
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user