From 926a6e8197a16b89a4a544485382d8ed4f55f528 Mon Sep 17 00:00:00 2001 From: Hakkenouw <58526958+Hakkenouw@users.noreply.github.com> Date: Sat, 24 Feb 2024 07:59:39 -0700 Subject: [PATCH 1/3] Add `sslinline` argument description to index.html.markdown (#409) --- website/docs/index.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 87fa62cb..3cc75a8e 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -166,6 +166,7 @@ The following arguments are supported: * `clientcert` - (Optional) - Configure the SSL client certificate. * `cert` - (Required) - The SSL client certificate file path. The file must contain PEM encoded data. * `key` - (Required) - The SSL client certificate private key file path. The file must contain PEM encoded data. + * `sslinline` - (Optional) - If set to `true`, arguments accept inline ssl cert and key rather than a filename. Defaults to `false`. * `sslrootcert` - (Optional) - The SSL server root certificate file path. The file must contain PEM encoded data. * `connect_timeout` - (Optional) Maximum wait for connection, in seconds. The default is `180s`. Zero or not specified means wait indefinitely. From 65171ff554902a48b3a19ed7e1b44da389073b47 Mon Sep 17 00:00:00 2001 From: Jerome Quere Date: Sat, 24 Feb 2024 16:04:40 +0100 Subject: [PATCH 2/3] fix: quote table name in postgresql_publication (#402) --- postgresql/helpers.go | 13 +++++++++ postgresql/helpers_test.go | 28 +++++++++++++++++++ postgresql/resource_postgresql_publication.go | 6 ++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/postgresql/helpers.go b/postgresql/helpers.go index 1cc0cd1d..f74f0b78 100644 --- a/postgresql/helpers.go +++ b/postgresql/helpers.go @@ -606,3 +606,16 @@ func findStringSubmatchMap(expression string, text string) map[string]string { func defaultDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool { return old == new } + +// quoteTable can quote a table name with or without a schema prefix +// Example: +// +// my_table -> "my_table" +// public.my_table -> "public"."my_table" +func quoteTableName(tableName string) string { + parts := strings.Split(tableName, ".") + for i := range parts { + parts[i] = pq.QuoteIdentifier(parts[i]) + } + return strings.Join(parts, ".") +} diff --git a/postgresql/helpers_test.go b/postgresql/helpers_test.go index 95632d50..6b60d806 100644 --- a/postgresql/helpers_test.go +++ b/postgresql/helpers_test.go @@ -17,3 +17,31 @@ func TestFindStringSubmatchMap(t *testing.T) { }, ) } + +func TestQuoteTableName(t *testing.T) { + tests := []struct { + name string + input string + expected string + }{ + { + name: "simple table name", + input: "users", + expected: `"users"`, + }, + { + name: "table name with schema", + input: "test.users", + expected: `"test"."users"`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := quoteTableName(tt.input) + if actual != tt.expected { + t.Errorf("quoteTableName() = %v, want %v", actual, tt.expected) + } + }) + } +} diff --git a/postgresql/resource_postgresql_publication.go b/postgresql/resource_postgresql_publication.go index f8cea648..4e99ae55 100644 --- a/postgresql/resource_postgresql_publication.go +++ b/postgresql/resource_postgresql_publication.go @@ -183,12 +183,12 @@ func setPubTables(txn *sql.Tx, d *schema.ResourceData) error { added := arrayDifference(newList, oldList) for _, p := range added { - query := fmt.Sprintf("ALTER PUBLICATION %s ADD TABLE %s", pubName, p.(string)) + query := fmt.Sprintf("ALTER PUBLICATION %s ADD TABLE %s", pubName, quoteTableName(p.(string))) queries = append(queries, query) } for _, p := range dropped { - query := fmt.Sprintf("ALTER PUBLICATION %s DROP TABLE %s", pubName, p.(string)) + query := fmt.Sprintf("ALTER PUBLICATION %s DROP TABLE %s", pubName, quoteTableName(p.(string))) queries = append(queries, query) } @@ -461,7 +461,7 @@ func getTablesForPublication(d *schema.ResourceData) (string, error) { return tablesString, fmt.Errorf("'%s' is duplicated for attribute `%s`", elem.(string), pubTablesAttr) } for _, t := range tables { - tlist = append(tlist, t.(string)) + tlist = append(tlist, quoteTableName(t.(string))) } tablesString = fmt.Sprintf("FOR TABLE %s", strings.Join(tlist, ", ")) } From 43c86279f3c1f1a9c3cc863808cb2a5d65201be3 Mon Sep 17 00:00:00 2001 From: Okumura Takahiro Date: Sun, 25 Feb 2024 01:26:31 +0900 Subject: [PATCH 3/3] Fix indentation in index.html.markdown (#380) --- website/docs/index.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 3cc75a8e..d8ff9062 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -153,7 +153,7 @@ The following arguments are supported: * `password` - (Optional) Password for the server connection. * `database_username` - (Optional) Username of the user in the database if different than connection username (See [user name maps](https://www.postgresql.org/docs/current/auth-username-maps.html)). * `superuser` - (Optional) Should be set to `false` if the user to connect is not a PostgreSQL superuser (as is the case in AWS RDS or GCP SQL). -* In this case, some features might be disabled (e.g.: Refreshing state password from database). + In this case, some features might be disabled (e.g.: Refreshing state password from database). * `sslmode` - (Optional) Set the priority for an SSL connection to the server. Valid values for `sslmode` are (note: `prefer` is not supported by Go's [`lib/pq`][libpq])):