Skip to content

Commit

Permalink
alter delete constraint (#239)
Browse files Browse the repository at this point in the history
* add alter table delete constraints

* add constraint name

* add constraint name
  • Loading branch information
tanner0101 authored Oct 14, 2019
1 parent a0f3d62 commit 8f2238d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/MySQL/SQL/MySQLAlterTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public struct MySQLAlterTable: SQLAlterTable {

/// See `SQLAlterTable`.
public typealias TableConstraint = MySQLTableConstraint

public typealias Identifier = MySQLIdentifier

/// See `SQLAlterTable`.
public static func alterTable(_ table: TableIdentifier) -> MySQLAlterTable {
Expand All @@ -28,7 +30,9 @@ public struct MySQLAlterTable: SQLAlterTable {

/// See `SQLAlterTable`.
public var constraints: [TableConstraint]


public var deleteConstraints: [Identifier]

/// Specifies the position of a column being added to a table.
public enum ColumnPosition: SQLSerializable {
/// Add the column at the beginning of the table.
Expand Down Expand Up @@ -59,6 +63,7 @@ public struct MySQLAlterTable: SQLAlterTable {
self.deleteColumns = []
self.constraints = []
self.columnPositions = [:]
self.deleteConstraints = []
}

/// See `SQLSerializable`.
Expand All @@ -76,6 +81,8 @@ public struct MySQLAlterTable: SQLAlterTable {
} + constraints.map { "ADD " + $0.serialize(&binds) }
let deleteActions = deleteColumns.map {
return "DROP " + $0.identifier.serialize(&binds)
} + deleteConstraints.map {
return "DROP INDEX " + $0.serialize(&binds)
}
sql.append((actions + deleteActions).joined(separator: ", "))
return sql.joined(separator: " ")
Expand Down

0 comments on commit 8f2238d

Please sign in to comment.