Make our Rename migration more lenient about having already been performed.
This commit is contained in:
@@ -25,6 +25,8 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.samskivert.jdbc.JDBCUtil;
|
||||||
|
|
||||||
import static com.samskivert.jdbc.depot.Log.log;
|
import static com.samskivert.jdbc.depot.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,9 +77,27 @@ public abstract class EntityMigration extends Modifier
|
|||||||
try {
|
try {
|
||||||
log.info("Changing '" + _oldColumnName + "' to '" + _newColumnDef + "' in " +
|
log.info("Changing '" + _oldColumnName + "' to '" + _newColumnDef + "' in " +
|
||||||
_tableName);
|
_tableName);
|
||||||
return stmt.executeUpdate(
|
|
||||||
"alter table " + _tableName + " change column " + _oldColumnName + " " +
|
if (!JDBCUtil.tableContainsColumn(conn, _tableName, _oldColumnName)) {
|
||||||
_newColumnDef);
|
if (JDBCUtil.tableContainsColumn(conn, _tableName, _newColumnName)) {
|
||||||
|
// we'll accept this inconsistency
|
||||||
|
log.warning("Column rename appears already performed.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// but this is not OK
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
_tableName + " does not contain '" + _oldColumnName + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
// nor is this
|
||||||
|
if (JDBCUtil.tableContainsColumn(conn, _tableName, _newColumnName)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
_tableName + " already contains '" + _newColumnName + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
return stmt.executeUpdate("alter table " + _tableName + " change column " +
|
||||||
|
_oldColumnName + " " + _newColumnDef);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
stmt.close();
|
stmt.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user