From bf069760b04c45977ef09167d92e4cfba048b853 Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Wed, 6 Mar 2024 16:23:12 +0200 Subject: [PATCH 01/20] crdb docker --- tests/docker-compose.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 177994bf..4a05f3ff 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -19,3 +19,16 @@ services: interval: 10s timeout: 5s retries: 5 + cockroachdb: + image: cockroachdb/cockroach:latest-${CRDBVERSION} + command: + - "start-single-node" + - "--insecure" + ports: + - 26257:26257 + - 8080:8080 + healthcheck: + test: [ "CMD-SHELL", "pg_isready" ] + interval: 10s + timeout: 5s + retries: 5 From 450009036b3f13e425f8bfbf68957621c980dffb Mon Sep 17 00:00:00 2001 From: Harel Safra Date: Wed, 6 Mar 2024 23:15:34 +0200 Subject: [PATCH 02/20] crdb unit tests --- .github/workflows/test.yml | 32 +++++++++++++++++-- Makefile | 6 ++-- tests/docker-compose-crdb.yml | 14 ++++++++ ...cker-compose.yml => docker-compose-pg.yml} | 15 +-------- tests/switch_crdb.sh | 9 ++++++ tests/testacc_cleanup.sh | 4 +-- tests/testacc_full.sh | 22 +++++++++---- tests/testacc_setup.sh | 2 +- 8 files changed, 75 insertions(+), 29 deletions(-) create mode 100644 tests/docker-compose-crdb.yml rename tests/{docker-compose.yml => docker-compose-pg.yml} (54%) create mode 100755 tests/switch_crdb.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1ec3320b..2ffb050b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ on: pull_request: jobs: - test: + test-pg: runs-on: ubuntu-latest strategy: @@ -33,4 +33,32 @@ jobs: run: make vet - name: testacc - run: make testacc + run: make testacc tech=pg + + test-crdb: + runs-on: ubuntu-latest + + strategy: + matrix: + pgversion: [ v23.2 ] + + env: + CRDBVERSION: ${{ matrix.pgversion }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: test + run: make test + + - name: vet + run: make vet + + - name: testacc + run: make testacc tech=crdb diff --git a/Makefile b/Makefile index 8c764715..d2c02787 100644 --- a/Makefile +++ b/Makefile @@ -13,13 +13,13 @@ test: fmtcheck xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 testacc_setup: fmtcheck - @sh -c "'$(CURDIR)/tests/testacc_setup.sh'" + @sh -c "'$(CURDIR)/tests/testacc_setup.sh' $(tech)" testacc_cleanup: fmtcheck - @sh -c "'$(CURDIR)/tests/testacc_cleanup.sh'" + @sh -c "'$(CURDIR)/tests/testacc_cleanup.sh' $(tech)" testacc: fmtcheck - @sh -c "'$(CURDIR)/tests/testacc_full.sh'" + sh -c "'$(CURDIR)/tests/testacc_full.sh' $(tech)" vet: @echo "go vet ." diff --git a/tests/docker-compose-crdb.yml b/tests/docker-compose-crdb.yml new file mode 100644 index 00000000..06063524 --- /dev/null +++ b/tests/docker-compose-crdb.yml @@ -0,0 +1,14 @@ +version: "3" + +services: + cockroachdb: + image: cockroachdb/cockroach:latest-${CRDBVERSION} + command: + - "start-single-node" + - "--accept-sql-without-tls" + ports: + - 26257:26257 + - 8080:8080 + environment: + - COCKROACH_USER=${PGUSER} + - COCKROACH_PASSWORD=${PGPASSWORD} diff --git a/tests/docker-compose.yml b/tests/docker-compose-pg.yml similarity index 54% rename from tests/docker-compose.yml rename to tests/docker-compose-pg.yml index 4a05f3ff..1dd6c223 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose-pg.yml @@ -18,17 +18,4 @@ services: test: [ "CMD-SHELL", "pg_isready" ] interval: 10s timeout: 5s - retries: 5 - cockroachdb: - image: cockroachdb/cockroach:latest-${CRDBVERSION} - command: - - "start-single-node" - - "--insecure" - ports: - - 26257:26257 - - 8080:8080 - healthcheck: - test: [ "CMD-SHELL", "pg_isready" ] - interval: 10s - timeout: 5s - retries: 5 + retries: 5 \ No newline at end of file diff --git a/tests/switch_crdb.sh b/tests/switch_crdb.sh new file mode 100755 index 00000000..13017375 --- /dev/null +++ b/tests/switch_crdb.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +export TF_ACC=true +export PGHOST=localhost +export PGPORT=26257 +export PGUSER=postgres +export PGPASSWORD=postgres +export PGSSLMODE=disable +export PGSUPERUSER=true diff --git a/tests/testacc_cleanup.sh b/tests/testacc_cleanup.sh index c6cb970b..e899ea7e 100755 --- a/tests/testacc_cleanup.sh +++ b/tests/testacc_cleanup.sh @@ -1,5 +1,5 @@ #!/bin/bash -source "$(pwd)"/tests/switch_superuser.sh -docker compose -f "$(pwd)"/tests/docker-compose.yml down +#source "$(pwd)"/tests/switch_superuser.sh +docker compose -f "$(pwd)"/tests/docker-compose-${1}.yml down unset TF_ACC PGHOST PGPORT PGUSER PGPASSWORD PGSSLMODE PGSUPERUSER diff --git a/tests/testacc_full.sh b/tests/testacc_full.sh index 39b2941f..832733d7 100755 --- a/tests/testacc_full.sh +++ b/tests/testacc_full.sh @@ -8,7 +8,7 @@ log() { } setup() { - "$(pwd)"/tests/testacc_setup.sh + "$(pwd)"/tests/testacc_setup.sh $1 } run() { @@ -19,16 +19,24 @@ run() { } cleanup() { - "$(pwd)"/tests/testacc_cleanup.sh + "$(pwd)"/tests/testacc_cleanup.sh $1 } run_suite() { suite=${1?} - log "setup ($1)" && setup + tech=${2?} + log "setup ($1)" && setup "$tech" source "./tests/switch_$suite.sh" - log "run ($1)" && run || (log "cleanup" && cleanup && exit 1) - log "cleanup ($1)" && cleanup + log "run ($1)" && run || (log "cleanup" && cleanup $tech && exit 1) + log "cleanup ($1)" && cleanup $tech } -run_suite "superuser" -run_suite "rds" +echo $1 +if [ "$1" == "pg" ]; then + run_suite "superuser" "pg" + run_suite "rds" "pg" +else + run_suite "crdb" "crdb" +fi + + diff --git a/tests/testacc_setup.sh b/tests/testacc_setup.sh index 5b26abb8..121eddc0 100755 --- a/tests/testacc_setup.sh +++ b/tests/testacc_setup.sh @@ -1,4 +1,4 @@ #!/bin/bash source "$(pwd)"/tests/switch_superuser.sh -docker compose -f "$(pwd)"/tests/docker-compose.yml up -d --wait +docker compose -f "$(pwd)"/tests/docker-compose-${1}.yml up -d --wait From 9b58bafebbc533e73d7230ec9cad51234e7e98ee Mon Sep 17 00:00:00 2001 From: Harel Safra Date: Wed, 6 Mar 2024 23:17:47 +0200 Subject: [PATCH 03/20] crdb tests --- .github/workflows/test.yml | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2ffb050b..07c90cc5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,30 +35,30 @@ jobs: - name: testacc run: make testacc tech=pg - test-crdb: - runs-on: ubuntu-latest + test-crdb: + runs-on: ubuntu-latest - strategy: - matrix: - pgversion: [ v23.2 ] + strategy: + matrix: + pgversion: [ v23.2 ] - env: - CRDBVERSION: ${{ matrix.pgversion }} + env: + CRDBVERSION: ${{ matrix.pgversion }} - steps: - - name: Checkout - uses: actions/checkout@v3 + steps: + - name: Checkout + uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' - - name: test - run: make test + - name: test + run: make test - - name: vet - run: make vet + - name: vet + run: make vet - - name: testacc - run: make testacc tech=crdb + - name: testacc + run: make testacc tech=crdb From 88b683efc1bbe5fbb19ce3babd404353c8174cb2 Mon Sep 17 00:00:00 2001 From: Harel Safra Date: Wed, 6 Mar 2024 23:47:24 +0200 Subject: [PATCH 04/20] healthcheck --- tests/docker-compose-crdb.yml | 6 ++++++ tests/testacc_cleanup.sh | 2 +- tests/testacc_full.sh | 2 +- tests/testacc_setup.sh | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/docker-compose-crdb.yml b/tests/docker-compose-crdb.yml index 06063524..361f0d2a 100644 --- a/tests/docker-compose-crdb.yml +++ b/tests/docker-compose-crdb.yml @@ -12,3 +12,9 @@ services: environment: - COCKROACH_USER=${PGUSER} - COCKROACH_PASSWORD=${PGPASSWORD} + healthcheck: + test: [ "CMD", "curl", "http://tests-cockroachdb-1:8080/health?ready=1" ] + interval: 2s + timeout: 1m + retries: 5 + diff --git a/tests/testacc_cleanup.sh b/tests/testacc_cleanup.sh index e899ea7e..3cf3006e 100755 --- a/tests/testacc_cleanup.sh +++ b/tests/testacc_cleanup.sh @@ -1,5 +1,5 @@ #!/bin/bash -#source "$(pwd)"/tests/switch_superuser.sh +source "$(pwd)"/tests/switch_superuser.sh docker compose -f "$(pwd)"/tests/docker-compose-${1}.yml down unset TF_ACC PGHOST PGPORT PGUSER PGPASSWORD PGSSLMODE PGSUPERUSER diff --git a/tests/testacc_full.sh b/tests/testacc_full.sh index 832733d7..09addc5b 100755 --- a/tests/testacc_full.sh +++ b/tests/testacc_full.sh @@ -31,7 +31,7 @@ run_suite() { log "cleanup ($1)" && cleanup $tech } -echo $1 + if [ "$1" == "pg" ]; then run_suite "superuser" "pg" run_suite "rds" "pg" diff --git a/tests/testacc_setup.sh b/tests/testacc_setup.sh index 121eddc0..471d190f 100755 --- a/tests/testacc_setup.sh +++ b/tests/testacc_setup.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -x source "$(pwd)"/tests/switch_superuser.sh docker compose -f "$(pwd)"/tests/docker-compose-${1}.yml up -d --wait From ac79e67c8e20da9c18020e2fa14e46d90e90b5f3 Mon Sep 17 00:00:00 2001 From: Harel Safra Date: Wed, 6 Mar 2024 23:49:43 +0200 Subject: [PATCH 05/20] remove debug --- tests/testacc_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testacc_setup.sh b/tests/testacc_setup.sh index 471d190f..121eddc0 100755 --- a/tests/testacc_setup.sh +++ b/tests/testacc_setup.sh @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash source "$(pwd)"/tests/switch_superuser.sh docker compose -f "$(pwd)"/tests/docker-compose-${1}.yml up -d --wait From 637bc17dc6254bb3f55679763e6c61604dde965a Mon Sep 17 00:00:00 2001 From: Harel Safra Date: Wed, 6 Mar 2024 23:50:36 +0200 Subject: [PATCH 06/20] copy past --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07c90cc5..60f18f7f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,10 +40,10 @@ jobs: strategy: matrix: - pgversion: [ v23.2 ] + crdbversion: [ v23.2 ] env: - CRDBVERSION: ${{ matrix.pgversion }} + CRDBVERSION: ${{ crdbversion.pgversion }} steps: - name: Checkout From 8a906318bf0bcd0b6e4303f4f07f345d8c21aaa1 Mon Sep 17 00:00:00 2001 From: Harel Safra Date: Wed, 6 Mar 2024 23:51:32 +0200 Subject: [PATCH 07/20] wrong place --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 60f18f7f..14e75b40 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,7 +43,7 @@ jobs: crdbversion: [ v23.2 ] env: - CRDBVERSION: ${{ crdbversion.pgversion }} + CRDBVERSION: ${{ matrix.crdbversion }} steps: - name: Checkout From 91399847781faa23510d239e0131308f1814f3e9 Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Mon, 11 Mar 2024 13:25:22 +0200 Subject: [PATCH 08/20] crdb test --- postgresql/resource_postgresql_database.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index efd4226c..74ae211d 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -166,16 +166,28 @@ func createDatabase(db *DBConnection, d *schema.ResourceData) error { //cockroachdb support only encoding = 'UTF-8' (instead of UTF8), not supports DEFAULT switch v, ok := d.GetOk(dbEncodingAttr); { - case ok && strings.ToUpper(v.(string)) == "DEFAULT" && db.dbType == dbTypePostgresql: - fmt.Fprintf(b, " ENCODING = DEFAULT") - case ok: + case ok && db.dbType == dbTypePostgresql: fmt.Fprintf(b, " ENCODING = '%s' ", pqQuoteLiteral(v.(string))) + case ok && v.(string) != "UTF8" && v.(string) != "UNICODE" && db.dbType == dbTypeCockroachdb: + log.Printf("[ERROR] Cockroachdb does not support %s encoding", v.(string)) case v.(string) == "" && db.dbType == dbTypePostgresql: fmt.Fprint(b, ` ENCODING = 'UTF8'`) - case v.(string) == "" && db.dbType == dbTypeCockroachdb: - fmt.Fprint(b, ` ENCODING = 'UTF-8'`) } + switch v, ok := d.GetOk(dbEncodingAttr); { + case ok && strings.ToUpper(v.(string)) == "DEFAULT" && db.dbType == dbTypePostgresql: + fmt.Fprintf(b, " ENCODING DEFAULT") + case ok && db.dbType == dbTypePostgresql: + fmt.Fprintf(b, " ENCODING '%s' ", pqQuoteLiteral(v.(string))) + case ok && db.dbType == dbTypeCockroachdb && v.(string) != "UTF8" && v.(string) != "UTF-8" && v.(string) != "UNICODE": + log.Printf("[ERROR] Cockroachdb does not support %s encoding", v.(string)) + case ok && db.dbType == dbTypeCockroachdb && (v.(string) == "UTF8" || v.(string) == "UTF-8" || v.(string) != "UNICODE"): + fmt.Fprintf(b, " ENCODING = '%s' ", pqQuoteLiteral(v.(string))) + case v.(string) == "" && db.dbType == dbTypePostgresql: + fmt.Fprint(b, ` ENCODING 'UTF8'`) + case v.(string) == "" && db.dbType == dbTypeCockroachdb: + fmt.Fprint(b, ` ENCODING = 'UTF8'`) + } // Don't specify LC_COLLATE if user didn't specify it // This will use the default one (usually the one defined in the template database) switch v, ok := d.GetOk(dbCollationAttr); { From 3d401fd3e9e40c99ce3b0a2d4f9fbb5c9a5c4e4f Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Mon, 11 Mar 2024 13:35:03 +0200 Subject: [PATCH 09/20] crdb test --- postgresql/resource_postgresql_database.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index 74ae211d..ece1bd09 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -165,14 +165,14 @@ func createDatabase(db *DBConnection, d *schema.ResourceData) error { } //cockroachdb support only encoding = 'UTF-8' (instead of UTF8), not supports DEFAULT - switch v, ok := d.GetOk(dbEncodingAttr); { - case ok && db.dbType == dbTypePostgresql: - fmt.Fprintf(b, " ENCODING = '%s' ", pqQuoteLiteral(v.(string))) - case ok && v.(string) != "UTF8" && v.(string) != "UNICODE" && db.dbType == dbTypeCockroachdb: - log.Printf("[ERROR] Cockroachdb does not support %s encoding", v.(string)) - case v.(string) == "" && db.dbType == dbTypePostgresql: - fmt.Fprint(b, ` ENCODING = 'UTF8'`) - } + //switch v, ok := d.GetOk(dbEncodingAttr); { + //case ok && db.dbType == dbTypePostgresql: + // fmt.Fprintf(b, " ENCODING = '%s' ", pqQuoteLiteral(v.(string))) + //case ok && v.(string) != "UTF8" && v.(string) != "UNICODE" && db.dbType == dbTypeCockroachdb: + // log.Printf("[ERROR] Cockroachdb does not support %s encoding", v.(string)) + //case v.(string) == "" && db.dbType == dbTypePostgresql: + // fmt.Fprint(b, ` ENCODING = 'UTF8'`) + //} switch v, ok := d.GetOk(dbEncodingAttr); { case ok && strings.ToUpper(v.(string)) == "DEFAULT" && db.dbType == dbTypePostgresql: From bebe6f2510c7c01fb45894f22cca1a6df30d2984 Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 16:09:11 +0300 Subject: [PATCH 10/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index ece1bd09..2f2c799b 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -525,6 +525,8 @@ func setDBConnLimit(db QueryAble, d *schema.ResourceData) error { connLimit := d.Get(dbConnLimitAttr).(int) dbName := d.Get(dbNameAttr).(string) + case db.dbTypeCockroachdb == dbTypeCockroachdb && connLimit == 0: + return fmt.Errorf("Cockroachdb does not support setting CONNECTION LIMIT to 0" sql := fmt.Sprintf("ALTER DATABASE %s CONNECTION LIMIT = %d", pq.QuoteIdentifier(dbName), connLimit) if _, err := db.Exec(sql); err != nil { return fmt.Errorf("Error updating database CONNECTION LIMIT: %w", err) From 642669f137e9c4b3b7983cfc81bf4ac389e5862f Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 16:14:56 +0300 Subject: [PATCH 11/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index 2f2c799b..0075ea27 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -526,7 +526,7 @@ func setDBConnLimit(db QueryAble, d *schema.ResourceData) error { connLimit := d.Get(dbConnLimitAttr).(int) dbName := d.Get(dbNameAttr).(string) case db.dbTypeCockroachdb == dbTypeCockroachdb && connLimit == 0: - return fmt.Errorf("Cockroachdb does not support setting CONNECTION LIMIT to 0" + return fmt.Errorf("Cockroachdb does not support setting CONNECTION LIMIT to 0") sql := fmt.Sprintf("ALTER DATABASE %s CONNECTION LIMIT = %d", pq.QuoteIdentifier(dbName), connLimit) if _, err := db.Exec(sql); err != nil { return fmt.Errorf("Error updating database CONNECTION LIMIT: %w", err) From 702a6fe6ba3a9e7f8f172d9ef2a0c114cf65045d Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 16:16:32 +0300 Subject: [PATCH 12/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index 0075ea27..3c1e3daa 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -525,7 +525,7 @@ func setDBConnLimit(db QueryAble, d *schema.ResourceData) error { connLimit := d.Get(dbConnLimitAttr).(int) dbName := d.Get(dbNameAttr).(string) - case db.dbTypeCockroachdb == dbTypeCockroachdb && connLimit == 0: + if db.dbTypeCockroachdb == dbTypeCockroachdb && connLimit == 0: return fmt.Errorf("Cockroachdb does not support setting CONNECTION LIMIT to 0") sql := fmt.Sprintf("ALTER DATABASE %s CONNECTION LIMIT = %d", pq.QuoteIdentifier(dbName), connLimit) if _, err := db.Exec(sql); err != nil { From 58eb0e679f24fbfdc7eadc220159d0ceff8b5fcb Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 16:22:13 +0300 Subject: [PATCH 13/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index 3c1e3daa..cfcd72ed 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -525,8 +525,9 @@ func setDBConnLimit(db QueryAble, d *schema.ResourceData) error { connLimit := d.Get(dbConnLimitAttr).(int) dbName := d.Get(dbNameAttr).(string) - if db.dbTypeCockroachdb == dbTypeCockroachdb && connLimit == 0: + if db.dbTypeCockroachdb == dbTypeCockroachdb && connLimit == 0 { return fmt.Errorf("Cockroachdb does not support setting CONNECTION LIMIT to 0") + } sql := fmt.Sprintf("ALTER DATABASE %s CONNECTION LIMIT = %d", pq.QuoteIdentifier(dbName), connLimit) if _, err := db.Exec(sql); err != nil { return fmt.Errorf("Error updating database CONNECTION LIMIT: %w", err) From b3d672fcf404e7e82a5cf9d29be736dfdc7570d9 Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 16:30:38 +0300 Subject: [PATCH 14/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index cfcd72ed..c34e4142 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -518,15 +518,15 @@ func setDBTablespace(db QueryAble, d *schema.ResourceData) error { return nil } -func setDBConnLimit(db QueryAble, d *schema.ResourceData) error { +func setDBConnLimit(db *DBConnection, d *schema.ResourceData) error { if !d.HasChange(dbConnLimitAttr) { return nil } connLimit := d.Get(dbConnLimitAttr).(int) dbName := d.Get(dbNameAttr).(string) - if db.dbTypeCockroachdb == dbTypeCockroachdb && connLimit == 0 { - return fmt.Errorf("Cockroachdb does not support setting CONNECTION LIMIT to 0") + if db.dbType == dbTypeCockroachdb && connLimit == 0 { + return fmt.Errorf("Cockroachdb does not support setting CONNECTION LIMIT to 0") } sql := fmt.Sprintf("ALTER DATABASE %s CONNECTION LIMIT = %d", pq.QuoteIdentifier(dbName), connLimit) if _, err := db.Exec(sql); err != nil { From 3f517e10d7e5b60002f5d8965095b2cd9f6858db Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 16:42:12 +0300 Subject: [PATCH 15/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index c34e4142..c0d8daa2 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -222,6 +222,9 @@ func createDatabase(db *DBConnection, d *schema.ResourceData) error { { val := d.Get(dbConnLimitAttr).(int) + if db.dbType == dbTypeCockroachdb && val == 0 { + log.Printf("[ERROR] Cockroachdb does not support setting CONNECTION LIMIT to 0") + } fmt.Fprint(b, " CONNECTION LIMIT ", val) } From ffbd4c78be42f3c72a8169455b8cf589ddc1d731 Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 18:45:54 +0300 Subject: [PATCH 16/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index c0d8daa2..8a914b75 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -224,8 +224,9 @@ func createDatabase(db *DBConnection, d *schema.ResourceData) error { val := d.Get(dbConnLimitAttr).(int) if db.dbType == dbTypeCockroachdb && val == 0 { log.Printf("[ERROR] Cockroachdb does not support setting CONNECTION LIMIT to 0") + } else { + fmt.Fprint(b, " CONNECTION LIMIT ", val) } - fmt.Fprint(b, " CONNECTION LIMIT ", val) } if db.featureSupported(featureDBIsTemplate) { From 701453e512fa56b561b453c5be1fa976d5a433d9 Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 19:09:39 +0300 Subject: [PATCH 17/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index 8a914b75..cef2bfda 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -220,13 +220,11 @@ func createDatabase(db *DBConnection, d *schema.ResourceData) error { fmt.Fprint(b, " ALLOW_CONNECTIONS ", val) } - { - val := d.Get(dbConnLimitAttr).(int) - if db.dbType == dbTypeCockroachdb && val == 0 { - log.Printf("[ERROR] Cockroachdb does not support setting CONNECTION LIMIT to 0") - } else { - fmt.Fprint(b, " CONNECTION LIMIT ", val) - } + val := d.Get(dbConnLimitAttr).(int) + if db.dbType == dbTypeCockroachdb && val == 0 { + log.Printf("[ERROR] Cockroachdb does not support setting CONNECTION LIMIT to 0") + } else { + fmt.Fprint(b, " CONNECTION LIMIT ", val) } if db.featureSupported(featureDBIsTemplate) { From 0e76a99312ee1f3d93352076a50a8fc8588dc9ff Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 19:31:22 +0300 Subject: [PATCH 18/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index cef2bfda..9ad474f8 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -532,7 +532,7 @@ func setDBConnLimit(db *DBConnection, d *schema.ResourceData) error { } sql := fmt.Sprintf("ALTER DATABASE %s CONNECTION LIMIT = %d", pq.QuoteIdentifier(dbName), connLimit) if _, err := db.Exec(sql); err != nil { - return fmt.Errorf("Error updating database CONNECTION LIMIT: %w", err) + return fmt.Errorf("Error updating database CONNECTION LIMIT: %w %w", err, sql) } return nil From 6e642ddd4b97bd67cba153f11fabd34a039a7a76 Mon Sep 17 00:00:00 2001 From: Tamara Bernshtein Date: Thu, 25 Apr 2024 19:35:18 +0300 Subject: [PATCH 19/20] fix CONNECTION LIMIT --- postgresql/resource_postgresql_database.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresql/resource_postgresql_database.go b/postgresql/resource_postgresql_database.go index 9ad474f8..cb14afc0 100644 --- a/postgresql/resource_postgresql_database.go +++ b/postgresql/resource_postgresql_database.go @@ -532,7 +532,7 @@ func setDBConnLimit(db *DBConnection, d *schema.ResourceData) error { } sql := fmt.Sprintf("ALTER DATABASE %s CONNECTION LIMIT = %d", pq.QuoteIdentifier(dbName), connLimit) if _, err := db.Exec(sql); err != nil { - return fmt.Errorf("Error updating database CONNECTION LIMIT: %w %w", err, sql) + return fmt.Errorf("Error updating database CONNECTION LIMIT: %w %s", err, sql) } return nil From 3d15d6509bf6fcc65ff8799c5fad3aef6766da59 Mon Sep 17 00:00:00 2001 From: Harel Safra Date: Mon, 23 Sep 2024 17:00:38 +0100 Subject: [PATCH 20/20] version 2 for goreleaser --- .goreleaser.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 34fef1d2..a5366780 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,6 @@ # Visit https://goreleaser.com for documentation on how to customize this # behavior. +version: 2 before: hooks: # this is just an example and not a requirement for provider building/publishing