This should really be automagic but for now we'll have a manual migration.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2063 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -108,8 +108,7 @@ public abstract class EntityMigration extends Modifier
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init (String tableName, HashMap<String,FieldMarshaller> marshallers)
|
protected void init (String tableName, HashMap<String,FieldMarshaller> marshallers) {
|
||||||
{
|
|
||||||
super.init(tableName, marshallers);
|
super.init(tableName, marshallers);
|
||||||
_newColumnDef = marshallers.get(_newColumnName).getColumnDefinition();
|
_newColumnDef = marshallers.get(_newColumnName).getColumnDefinition();
|
||||||
}
|
}
|
||||||
@@ -117,6 +116,35 @@ public abstract class EntityMigration extends Modifier
|
|||||||
protected String _oldColumnName, _newColumnName, _newColumnDef;
|
protected String _oldColumnName, _newColumnName, _newColumnDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenient migration for changing the type of an existing column.
|
||||||
|
*/
|
||||||
|
public static class Retype extends EntityMigration
|
||||||
|
{
|
||||||
|
public Retype (int targetVersion, String columnName) {
|
||||||
|
super(targetVersion);
|
||||||
|
_columnName = columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int invoke (Connection conn) throws SQLException {
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
try {
|
||||||
|
log.info("Updating type of '" + _columnName + "' in " + _tableName);
|
||||||
|
return stmt.executeUpdate("alter table " + _tableName + " change column " +
|
||||||
|
_columnName + " " + _newColumnDef);
|
||||||
|
} finally {
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void init (String tableName, HashMap<String,FieldMarshaller> marshallers) {
|
||||||
|
super.init(tableName, marshallers);
|
||||||
|
_newColumnDef = marshallers.get(_columnName).getColumnDefinition();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String _columnName, _newColumnDef;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this method returns true, this migration will be run <b>before</b> the default
|
* If this method returns true, this migration will be run <b>before</b> the default
|
||||||
* migrations, if false it will be run after.
|
* migrations, if false it will be run after.
|
||||||
|
|||||||
Reference in New Issue
Block a user