Skip to content

Commit 6dd3599

Browse files
authored
[DX-3716] Use FORCE to drop DBs (#1973)
* Use FORCE to drop DBs * Silent deploys * Requires * lessorequal
1 parent 8c59288 commit 6dd3599

3 files changed

Lines changed: 39 additions & 37 deletions

File tree

.github/workflows/build_external.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jobs:
3434
3535
build-chainlink:
3636
needs: init
37-
environment: integration
37+
environment:
38+
name: integration
39+
deployment: false
3840
permissions:
3941
contents: read
4042
id-token: write
@@ -76,7 +78,9 @@ jobs:
7678
7779
solana-build-relay:
7880
needs: init
79-
environment: integration
81+
environment:
82+
name: integration
83+
deployment: false
8084
permissions:
8185
id-token: write
8286
contents: read
@@ -115,7 +119,9 @@ jobs:
115119

116120
starknet-build-relay:
117121
needs: init
118-
environment: integration
122+
environment:
123+
name: integration
124+
deployment: false
119125
permissions:
120126
id-token: write
121127
contents: read

.github/workflows/release.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ on:
5252
type: choice
5353
# Keep this up-to-date with the modules in the repository.
5454
options:
55-
- '.'
56-
- 'keystore'
57-
- 'observability-lib'
58-
- 'pkg/values'
59-
- 'pkg/workflows/sdk/v2/pb'
60-
- 'pkg/chipingress'
61-
- 'pkg/monitoring'
55+
- "."
56+
- "keystore"
57+
- "observability-lib"
58+
- "pkg/values"
59+
- "pkg/workflows/sdk/v2/pb"
60+
- "pkg/chipingress"
61+
- "pkg/monitoring"
6262

6363
tag-prefix-override:
6464
# Tags for go modules have some formatting requirements.
@@ -84,7 +84,7 @@ on:
8484
head-ref-override:
8585
# This overrides/forces the tag to point to something other than the HEAD of the branch the workflow is running on.
8686
# This is only needed if the commit to be released is not the HEAD of the branch.
87-
description: 'HEAD REF (override) - the ref/sha the new release/tag will reference. Defaults to the HEAD of the current branch.'
87+
description: "HEAD REF (override) - the ref/sha the new release/tag will reference. Defaults to the HEAD of the current branch."
8888
required: false
8989
# default: ${{ github.ref_name }} - not possible here
9090
type: string
@@ -93,12 +93,12 @@ on:
9393
# Normally, the workflow determines the latest version/release by comparing the git tags matching the desired format (see tag-prefix-override).
9494
# This overrides the latest release/version to be a specific ref. The computed API diff will be between this ref and the head ref (or release-ref-override if specified).
9595
# If this is set then version-override is required, as overriding the base ref breaks the normal version recommendation heuristic.
96-
description: 'BASE REF (override) - The most recent release/version/ref to compare against. Defaults to the latest (semver) tag with the associated tag prefix. version-override is required if this is set.'
96+
description: "BASE REF (override) - The most recent release/version/ref to compare against. Defaults to the latest (semver) tag with the associated tag prefix. version-override is required if this is set."
9797
required: false
9898
type: string
9999

100100
dry-run:
101-
description: 'DRY RUN - Run everything, except for release creation.'
101+
description: "DRY RUN - Run everything, except for release creation."
102102
required: true
103103
type: boolean
104104
default: false
@@ -202,7 +202,7 @@ jobs:
202202
203203
release:
204204
name: Version and Draft Release ${{ inputs.dry-run && '(dry-run)' || '' }}
205-
needs: [ process-inputs, approval-gate ]
205+
needs: [process-inputs, approval-gate]
206206
runs-on: ubuntu-latest
207207
permissions:
208208
contents: write
@@ -344,14 +344,15 @@ jobs:
344344
345345
gh release create "${release_args[@]}"
346346
347-
348347
# Used to enforce approvals before kicking off the rest of the jobs.
349348
approval-gate:
350349
name: Approval Gate ${{ inputs.dry-run && '(dry-run bypass)' || '' }}
351-
needs: [ review-context, process-inputs ]
350+
needs: [review-context, process-inputs]
352351
runs-on: ubuntu-latest
353352
# Only require approval gate if not a dry-run
354-
environment: ${{ !inputs.dry-run && 'approval-gate-foundations' || '' }}
353+
environment:
354+
name: ${{ !inputs.dry-run && 'approval-gate-foundations' || '' }}
355+
deployment: false
355356
steps:
356357
- name: Exit successfully
357358
run: exit 0

pkg/sqlutil/sqltest/sqltest.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/google/uuid"
1414
"github.com/jmoiron/sqlx"
15+
"github.com/lib/pq"
1516
"github.com/scylladb/go-reflectx"
1617
"github.com/stretchr/testify/assert"
1718
"github.com/stretchr/testify/require"
@@ -57,35 +58,28 @@ func SkipInMemory(t *testing.T) {
5758
// CreateOrReplace creates a new database with the given name (optionally from template), and schedules it to be dropped
5859
// after test completion.
5960
func CreateOrReplace(t testing.TB, u url.URL, dbName string, template string) url.URL {
60-
if u.Path == "" {
61-
t.Fatal("path missing from database URL")
62-
}
61+
require.NotEmpty(t, u.Path, "path missing from database URL")
62+
require.LessOrEqual(t, len(dbName), 63, "dbName %v too long (%d), max is 63 bytes", dbName, len(dbName))
6363

64-
if l := len(dbName); l > 63 {
65-
t.Fatalf("dbName %v too long (%d), max is 63 bytes", dbName, l)
66-
}
6764
// Cannot drop test database if we are connected to it, so we must connect
6865
// to a different one. 'postgres' should be present on all postgres installations
6966
u.Path = "/postgres"
7067
db, err := sql.Open(pg.DriverPostgres, u.String())
71-
if err != nil {
72-
t.Fatalf("in order to drop the test database, we need to connect to a separate database"+
73-
" called 'postgres'. But we are unable to open 'postgres' database: %+v\n", err)
74-
}
68+
require.NoError(t, err, "in order to drop the test database, we need to connect to a separate database"+
69+
" called 'postgres'. But we are unable to open 'postgres' database")
7570
defer db.Close()
7671

77-
_, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", dbName))
78-
if err != nil {
79-
t.Fatalf("unable to drop postgres migrations test database: %v", err)
80-
}
72+
quotedName := pq.QuoteIdentifier(dbName)
73+
// WITH (FORCE) requires PostgreSQL 13+; terminates backends and avoids "being accessed by other users".
74+
_, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s WITH (FORCE)", quotedName))
75+
require.NoError(t, err, "unable to drop postgres migrations test database")
8176
if template != "" {
82-
_, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s WITH TEMPLATE %s", dbName, template))
77+
quotedTemplate := pq.QuoteIdentifier(template)
78+
_, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s WITH TEMPLATE %s", quotedName, quotedTemplate))
8379
} else {
84-
_, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s", dbName))
85-
}
86-
if err != nil {
87-
t.Fatalf("unable to create postgres test database with name '%s': %v", dbName, err)
80+
_, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s", quotedName))
8881
}
82+
require.NoError(t, err, "unable to create postgres test database with name '%s'", dbName)
8983
u.Path = fmt.Sprintf("/%s", dbName)
9084
// simple best effort; some tests seem to hold a db connection and race with this drop
9185
t.Cleanup(func() {
@@ -120,7 +114,8 @@ func drop(dbURL url.URL) error {
120114
}
121115
defer db.Close()
122116

123-
_, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", dbname))
117+
quoted := pq.QuoteIdentifier(dbname)
118+
_, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s WITH (FORCE)", quoted))
124119
if err != nil {
125120
return fmt.Errorf("unable to drop postgres migrations test database: %v", err)
126121
}

0 commit comments

Comments
 (0)