diff --git a/src/java/com/samskivert/depot/SchemaMigration.java b/src/java/com/samskivert/depot/SchemaMigration.java index 6dd8fa3..fa68475 100644 --- a/src/java/com/samskivert/depot/SchemaMigration.java +++ b/src/java/com/samskivert/depot/SchemaMigration.java @@ -209,6 +209,32 @@ public abstract class SchemaMigration extends Modifier protected ColumnDefinition _newColumnDef; } + /** + * A convenient migration for dropping a column from an entity. + */ + public static class DropIndex extends SchemaMigration + { + public DropIndex (int targetVersion, String ixName) { + super(targetVersion); + _ixName = ixName; + } + + @Override + protected int invoke (Connection conn, DatabaseLiaison liaison) throws SQLException { + if (!liaison.tableContainsIndex(conn, _tableName, _ixName)) { + // we'll accept this inconsistency + log.warning(_tableName + " index '" + _ixName + "' does not exist."); + return 0; + } + + log.info("Dropping index '" + _ixName + "' from " + _tableName); + liaison.dropIndex(conn, _tableName, _ixName); + return 1; + } + + protected String _ixName; + } + /** * If this method returns true, this migration will be run before the default * migrations, if false it will be run after.