Skip to content

Commit d059f19

Browse files
committed
refactor(plugin-postgresql): drop the redundant public entry when public is the selected schema
1 parent 00ff7c5 commit d059f19

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Plugins/PostgreSQLDriverPlugin/PostgreSQLSchemaQueries.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ enum PostgreSQLSchemaQueries {
7777
}
7878

7979
static func setSearchPath(toSchema schema: String) -> String {
80-
let quotedIdentifier = schema.replacingOccurrences(of: "\"", with: "\"\"")
81-
return "SET search_path TO \"\(quotedIdentifier)\", public"
80+
let quotedIdentifier = "\"\(schema.replacingOccurrences(of: "\"", with: "\"\""))\""
81+
guard schema != "public" else {
82+
return "SET search_path TO \(quotedIdentifier)"
83+
}
84+
return "SET search_path TO \(quotedIdentifier), public"
8285
}
8386
}

TableProTests/Plugins/PostgreSQLSearchPathTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ struct PostgreSQLSearchPathTests {
1616
)
1717
}
1818

19+
@Test("omits the redundant public fallback when public is the selected schema")
20+
func publicSchema() {
21+
#expect(
22+
PostgreSQLSchemaQueries.setSearchPath(toSchema: "public")
23+
== "SET search_path TO \"public\""
24+
)
25+
}
26+
1927
@Test("preserves mixed-case schema names with identifier quoting")
2028
func mixedCaseSchema() {
2129
#expect(

0 commit comments

Comments
 (0)