Skip to content

Commit 3825894

Browse files
committed
Don't use qualified table name when creating a foreign key reference
1 parent 993295a commit 3825894

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

SQLite/Typed/Schema.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ private func definition(column: Expressible, _ datatype: String, _ primaryKey: P
505505
private func reference(primary: (QueryType, Expressible)) -> Expressible {
506506
return " ".join([
507507
Expression<Void>(literal: "REFERENCES"),
508-
primary.0.tableName(),
508+
primary.0.tableName(qualified: false),
509509
"".wrap(primary.1) as Expression<Void>
510510
])
511511
}

SQLiteTests/SchemaTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ class SchemaTests : XCTestCase {
300300
"CREATE TABLE \"table\" (\"int64\" INTEGER NOT NULL REFERENCES \"table\" (\"int64\"))",
301301
table.create { t in t.column(int64, references: table, int64) }
302302
)
303+
XCTAssertEqual(
304+
"CREATE TABLE \"table\" (\"int64\" INTEGER NOT NULL REFERENCES \"table\" (\"int64\"))",
305+
table.create { t in t.column(int64, references: qualifiedTable, int64) }
306+
)
303307
XCTAssertEqual(
304308
"CREATE TABLE \"table\" (\"int64\" INTEGER NOT NULL UNIQUE REFERENCES \"table\" (\"int64\"))",
305309
table.create { t in t.column(int64, unique: true, references: table, int64) }
@@ -726,7 +730,7 @@ class SchemaTests : XCTestCase {
726730
)
727731
XCTAssertEqual(
728732
"CREATE UNIQUE INDEX IF NOT EXISTS \"main\".\"index_table_on_int64\" ON \"table\" (\"int64\")",
729-
Table("table", database: "main").createIndex([int64], unique: true, ifNotExists: true)
733+
qualifiedTable.createIndex([int64], unique: true, ifNotExists: true)
730734
)
731735
}
732736

SQLiteTests/TestHelpers.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@ func AssertThrows<T>(@autoclosure expression: () throws -> T, file: StaticString
110110
}
111111

112112
let table = Table("table")
113+
let qualifiedTable = Table("table", database: "main")
113114
let virtualTable = VirtualTable("virtual_table")
114115
let _view = View("view") // avoid Mac XCTestCase collision

0 commit comments

Comments
 (0)