Skip to content

Commit dcd6988

Browse files
authored
Merge branch 'master' into master
2 parents 29d97ae + 65171ff commit dcd6988

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

postgresql/helpers.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,16 @@ func findStringSubmatchMap(expression string, text string) map[string]string {
606606
func defaultDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
607607
return old == new
608608
}
609+
610+
// quoteTable can quote a table name with or without a schema prefix
611+
// Example:
612+
//
613+
// my_table -> "my_table"
614+
// public.my_table -> "public"."my_table"
615+
func quoteTableName(tableName string) string {
616+
parts := strings.Split(tableName, ".")
617+
for i := range parts {
618+
parts[i] = pq.QuoteIdentifier(parts[i])
619+
}
620+
return strings.Join(parts, ".")
621+
}

postgresql/helpers_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,31 @@ func TestFindStringSubmatchMap(t *testing.T) {
1717
},
1818
)
1919
}
20+
21+
func TestQuoteTableName(t *testing.T) {
22+
tests := []struct {
23+
name string
24+
input string
25+
expected string
26+
}{
27+
{
28+
name: "simple table name",
29+
input: "users",
30+
expected: `"users"`,
31+
},
32+
{
33+
name: "table name with schema",
34+
input: "test.users",
35+
expected: `"test"."users"`,
36+
},
37+
}
38+
39+
for _, tt := range tests {
40+
t.Run(tt.name, func(t *testing.T) {
41+
actual := quoteTableName(tt.input)
42+
if actual != tt.expected {
43+
t.Errorf("quoteTableName() = %v, want %v", actual, tt.expected)
44+
}
45+
})
46+
}
47+
}

postgresql/resource_postgresql_publication.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ func setPubTables(txn *sql.Tx, d *schema.ResourceData) error {
183183
added := arrayDifference(newList, oldList)
184184

185185
for _, p := range added {
186-
query := fmt.Sprintf("ALTER PUBLICATION %s ADD TABLE %s", pubName, p.(string))
186+
query := fmt.Sprintf("ALTER PUBLICATION %s ADD TABLE %s", pubName, quoteTableName(p.(string)))
187187
queries = append(queries, query)
188188
}
189189

190190
for _, p := range dropped {
191-
query := fmt.Sprintf("ALTER PUBLICATION %s DROP TABLE %s", pubName, p.(string))
191+
query := fmt.Sprintf("ALTER PUBLICATION %s DROP TABLE %s", pubName, quoteTableName(p.(string)))
192192
queries = append(queries, query)
193193
}
194194

@@ -461,7 +461,7 @@ func getTablesForPublication(d *schema.ResourceData) (string, error) {
461461
return tablesString, fmt.Errorf("'%s' is duplicated for attribute `%s`", elem.(string), pubTablesAttr)
462462
}
463463
for _, t := range tables {
464-
tlist = append(tlist, t.(string))
464+
tlist = append(tlist, quoteTableName(t.(string)))
465465
}
466466
tablesString = fmt.Sprintf("FOR TABLE %s", strings.Join(tlist, ", "))
467467
}

website/docs/index.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ The following arguments are supported:
166166
* `clientcert` - (Optional) - Configure the SSL client certificate.
167167
* `cert` - (Required) - The SSL client certificate file path. The file must contain PEM encoded data.
168168
* `key` - (Required) - The SSL client certificate private key file path. The file must contain PEM encoded data.
169+
* `sslinline` - (Optional) - If set to `true`, arguments accept inline ssl cert and key rather than a filename. Defaults to `false`.
169170
* `sslrootcert` - (Optional) - The SSL server root certificate file path. The file must contain PEM encoded data.
170171
* `connect_timeout` - (Optional) Maximum wait for connection, in seconds. The
171172
default is `180s`. Zero or not specified means wait indefinitely.

0 commit comments

Comments
 (0)