@@ -45,6 +45,7 @@ public class SchemaChanger: CustomStringConvertible {
4545 case addColumn( ColumnDefinition )
4646 case addIndex( IndexDefinition , ifNotExists: Bool )
4747 case dropColumn( String )
48+ case dropIndex( String , ifExists: Bool )
4849 case renameColumn( String , String )
4950 case renameTable( String )
5051 case createTable( columns: [ ColumnDefinition ] , ifNotExists: Bool )
@@ -60,6 +61,8 @@ public class SchemaChanger: CustomStringConvertible {
6061 return " ALTER TABLE \( table. quote ( ) ) RENAME COLUMN \( from. quote ( ) ) TO \( to. quote ( ) ) "
6162 case . dropColumn( let column) where SQLiteFeature . dropColumn. isSupported ( by: version) :
6263 return " ALTER TABLE \( table. quote ( ) ) DROP COLUMN \( column. quote ( ) ) "
64+ case . dropIndex( let name, let ifExists) :
65+ return " DROP INDEX \( ifExists ? " IF EXISTS " : " " ) \( name. quote ( ) ) "
6366 case . createTable( let columns, let ifNotExists) :
6467 return " CREATE TABLE \( ifNotExists ? " IF NOT EXISTS " : " " ) \( table. quote ( ) ) ( " +
6568 columns. map { $0. toSQL ( ) } . joined ( separator: " , " ) +
@@ -111,6 +114,10 @@ public class SchemaChanger: CustomStringConvertible {
111114 operations. append ( . dropColumn( column) )
112115 }
113116
117+ public func drop( index: String , ifExists: Bool = false ) {
118+ operations. append ( . dropIndex( index, ifExists: ifExists) )
119+ }
120+
114121 public func rename( column: String , to: String ) {
115122 operations. append ( . renameColumn( column, to) )
116123 }
@@ -324,8 +331,9 @@ extension TableDefinition {
324331 func apply( _ operation: SchemaChanger . Operation ? ) -> TableDefinition {
325332 switch operation {
326333 case . none: return self
327- case . createTable, . addIndex: fatalError ( )
334+ case . createTable, . addIndex, . dropIndex : fatalError ( )
328335 case . addColumn: fatalError ( " Use 'ALTER TABLE ADD COLUMN (...)' " )
336+
329337 case . dropColumn( let column) :
330338 return TableDefinition ( name: name,
331339 columns: columns. filter { $0. name != column } ,
0 commit comments