Skip to content

Commit

Permalink
Merge pull request #522 from vapor/unique-constraint-name-fix
Browse files Browse the repository at this point in the history
unique constraint name fix
  • Loading branch information
tanner0101 authored Jun 20, 2018
2 parents a821d46 + 08e20c8 commit f8378e3
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 f8378e3

Please sign in to comment.