mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
FIX: DDL process comment change correctly & drop references when index is dropped (#1109)
This commit is contained in:
committed by
Rob Bygrave
parent
f342d9d561
commit
f2e8b652fa
@@ -0,0 +1,22 @@
|
||||
package io.ebean.dbmigration.ddlgeneration.platform;
|
||||
|
||||
public class DdlHelp {
|
||||
public static final String DROP_DEFAULT = "DROP DEFAULT";
|
||||
|
||||
public static final String DROP_COMMENT = "DROP COMMENT";
|
||||
|
||||
/**
|
||||
* Return true if the default value is the special DROP DEFAULT value.
|
||||
*/
|
||||
public static boolean isDropDefault(String defaultValue) {
|
||||
return DROP_DEFAULT.equals(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the default value is the special DROP DEFAULT value.
|
||||
*/
|
||||
public static boolean isDropComment(String comment) {
|
||||
return DROP_COMMENT.equals(comment);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebean.dbmigration.model;
|
||||
|
||||
import io.ebean.dbmigration.ddlgeneration.platform.DdlHelp;
|
||||
import io.ebean.dbmigration.migration.AlterColumn;
|
||||
import io.ebean.dbmigration.migration.Column;
|
||||
|
||||
@@ -313,14 +314,18 @@ public class MColumn {
|
||||
if (different(defaultValue, newColumn.defaultValue)) {
|
||||
AlterColumn alter = getAlterColumn(tableName, tableWithHistory);
|
||||
if (newColumn.defaultValue == null) {
|
||||
alter.setDefaultValue("DROP DEFAULT");
|
||||
alter.setDefaultValue(DdlHelp.DROP_DEFAULT);
|
||||
} else {
|
||||
alter.setDefaultValue(newColumn.defaultValue);
|
||||
}
|
||||
}
|
||||
if (different(comment, newColumn.comment)) {
|
||||
AlterColumn alter = getAlterColumn(tableName, tableWithHistory);
|
||||
alter.setComment(newColumn.comment);
|
||||
if (newColumn.comment == null) {
|
||||
alter.setComment(DdlHelp.DROP_COMMENT);
|
||||
} else {
|
||||
alter.setComment(newColumn.comment);
|
||||
}
|
||||
}
|
||||
if (different(checkConstraint, newColumn.checkConstraint)) {
|
||||
AlterColumn alter = getAlterColumn(tableName, tableWithHistory);
|
||||
@@ -388,6 +393,7 @@ public class MColumn {
|
||||
}
|
||||
if (hasValue(alterColumn.getDropForeignKey())) {
|
||||
foreignKeyName = null;
|
||||
references = null;
|
||||
}
|
||||
if (hasValue(alterColumn.getDropForeignKeyIndex())) {
|
||||
foreignKeyIndex = null;
|
||||
@@ -405,6 +411,9 @@ public class MColumn {
|
||||
}
|
||||
if (hasValue(alterColumn.getDefaultValue())) {
|
||||
defaultValue = alterColumn.getDefaultValue();
|
||||
if (DdlHelp.isDropDefault(defaultValue)) {
|
||||
defaultValue = null;
|
||||
}
|
||||
}
|
||||
if (hasValue(alterColumn.getCheckConstraint())) {
|
||||
checkConstraint = alterColumn.getCheckConstraint();
|
||||
@@ -427,6 +436,12 @@ public class MColumn {
|
||||
if (hasValue(alterColumn.getForeignKeyIndex())) {
|
||||
foreignKeyIndex = alterColumn.getForeignKeyIndex();
|
||||
}
|
||||
if (hasValue(alterColumn.getComment())) {
|
||||
comment = alterColumn.getComment();
|
||||
if (DdlHelp.isDropComment(comment)) {
|
||||
comment = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package io.ebean.dbmigration.model;
|
||||
|
||||
import io.ebean.dbmigration.ddlgeneration.platform.DdlHelp;
|
||||
import io.ebean.dbmigration.migration.AddColumn;
|
||||
import io.ebean.dbmigration.migration.AddHistoryTable;
|
||||
import io.ebean.dbmigration.migration.AddTableComment;
|
||||
import io.ebean.dbmigration.migration.AlterColumn;
|
||||
import io.ebean.dbmigration.migration.ChangeSet;
|
||||
import io.ebean.dbmigration.migration.ChangeSetType;
|
||||
@@ -132,6 +134,10 @@ public class ModelContainer {
|
||||
applyChange((AddHistoryTable) change);
|
||||
} else if (change instanceof DropHistoryTable) {
|
||||
applyChange((DropHistoryTable) change);
|
||||
} else if (change instanceof AddTableComment) {
|
||||
applyChange((AddTableComment) change);
|
||||
} else {
|
||||
throw new IllegalArgumentException("No rule for " + change);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,6 +165,18 @@ public class ModelContainer {
|
||||
}
|
||||
table.setWithHistory(false);
|
||||
}
|
||||
|
||||
private void applyChange(AddTableComment change) {
|
||||
MTable table = tables.get(change.getName());
|
||||
if (table == null) {
|
||||
throw new IllegalStateException("Table [" + change.getName() + "] does not exist in model?");
|
||||
}
|
||||
if (DdlHelp.isDropComment(change.getComment())) {
|
||||
table.setComment(null);
|
||||
} else {
|
||||
table.setComment(change.getComment());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a CreateTable change to the model.
|
||||
|
||||
Reference in New Issue
Block a user