From 08e20c8c5bbb95dc81dbe52d3ae271fde87e82ae Mon Sep 17 00:00:00 2001 From: tanner0101 Date: Tue, 19 Jun 2018 20:26:22 -0400 Subject: [PATCH] unique constraint name fix --- Sources/FluentSQL/SQL+SchemaSupporting.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/FluentSQL/SQL+SchemaSupporting.swift b/Sources/FluentSQL/SQL+SchemaSupporting.swift index c18ba3cc..b9797d94 100644 --- a/Sources/FluentSQL/SQL+SchemaSupporting.swift +++ b/Sources/FluentSQL/SQL+SchemaSupporting.swift @@ -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))")) } }