Skip to content

Commit

Permalink
unique constraint name fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Jun 20, 2018
1 parent a821d46 commit 08e20c8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/FluentSQL/SQL+SchemaSupporting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ extension SchemaSupporting where
{
/// See `SchemaSupporting`.
public static func schemaUnique(on: [QueryField]) -> SchemaConstraint {
let uid = on.map { $0.identifier.string }.joined(separator: "+")
let uid = on.map {
guard let table = $0.table else {
fatalError("Cannot create unique constraint on column without table identifier: \($0).")
}
return "\(table.identifier.string).\($0.identifier.string)"
}.joined(separator: "+")
return .constraint(.unique(on.map { $0.identifier }), .identifier("uq:\(normalizeSQLConstraintIdentifier(uid))"))
}
}
Expand Down

0 comments on commit 08e20c8

Please sign in to comment.