Skip to content

Commit 30b6b9a

Browse files
authored
Merge branch 'master' into master
2 parents 79c741f + 952f3f0 commit 30b6b9a

File tree

19 files changed

+321
-342
lines changed

19 files changed

+321
-342
lines changed

.github/workflows/ci.yaml

+14-9
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@ on:
66

77
jobs:
88
lint:
9+
name: lint
910
runs-on: ubuntu-latest
1011
steps:
11-
- uses: actions/checkout@v2
12-
12+
- uses: actions/setup-go@v3
13+
with:
14+
go-version: "1.20.x"
15+
- uses: actions/checkout@v3
1316
- name: golangci-lint
14-
uses: golangci/golangci-lint-action@v2
17+
uses: golangci/golangci-lint-action@v3
18+
with:
19+
version: latest
1520

1621
test:
1722
runs-on: ubuntu-latest
1823
strategy:
1924
matrix:
20-
go: ["1.17.x", "1.18.x"]
25+
go: ["1.19.x", "1.20.x"]
2126
steps:
22-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v3
2328

24-
- uses: actions/setup-go@v2
29+
- uses: actions/setup-go@v3
2530
with:
2631
go-version: ${{ matrix.go }}
2732

@@ -55,15 +60,15 @@ jobs:
5560
# 3. When the workflow is triggered by a tag with `v` prefix
5661
if: ${{ success() && github.repository == 'golang-migrate/migrate' && startsWith(github.ref, 'refs/tags/v') }}
5762
steps:
58-
- uses: actions/checkout@v2
63+
- uses: actions/checkout@v3
5964
with:
6065
fetch-depth: 0
6166
- uses: ruby/setup-ruby@v1
6267
with:
6368
ruby-version: 2.7
64-
- uses: actions/setup-go@v2
69+
- uses: actions/setup-go@v3
6570
with:
66-
go-version: "1.18.x"
71+
go-version: "1.19.x"
6772

6873
- uses: docker/setup-qemu-action@v1
6974
- uses: docker/setup-buildx-action@v1

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.16-alpine3.13 AS builder
1+
FROM golang:1.19-alpine3.16 AS builder
22
ARG VERSION
33

44
RUN apk add --no-cache git gcc musl-dev make
@@ -15,7 +15,7 @@ COPY . ./
1515

1616
RUN make build-docker
1717

18-
FROM alpine:3.13
18+
FROM alpine:3.16
1919

2020
RUN apk add --no-cache ca-certificates
2121

Dockerfile.github-actions

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.13
1+
FROM alpine:3.16
22

33
RUN apk add --no-cache ca-certificates
44

@@ -8,4 +8,4 @@ RUN ln -s /usr/local/bin/migrate /usr/bin/migrate
88
RUN ln -s /usr/local/bin/migrate /migrate
99

1010
ENTRYPOINT ["migrate"]
11-
CMD ["--help"]
11+
CMD ["--help"]

GETTING_STARTED.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Getting started
22
Before you start, you should understand the concept of forward/up and reverse/down database migrations.
33

4-
Configure a database for your application. Make sure that your database driver is supported [here](README.md#databases)
4+
Configure a database for your application. Make sure that your database driver is supported [here](README.md#databases).
55

66
## Create migrations
77
Create some migrations using migrate CLI. Here is an example:
@@ -10,7 +10,7 @@ migrate create -ext sql -dir db/migrations -seq create_users_table
1010
```
1111
Once you create your files, you should fill them.
1212

13-
**IMPORTANT:** In a project developed by more than one person there is a chance of migrations inconsistency - e.g. two developers can create conflicting migrations, and the developer that created his migration later gets it merged to the repository first.
13+
**IMPORTANT:** In a project developed by more than one person there is a chance of migrations inconsistency - e.g. two developers can create conflicting migrations, and the developer that created their migration later gets it merged to the repository first.
1414
Developers and Teams should keep an eye on such cases (especially during code review).
1515
[Here](https://github.com/golang-migrate/migrate/issues/179#issuecomment-475821264) is the issue summary if you would like to read more.
1616

@@ -30,7 +30,7 @@ Just add the code to your app and you're ready to go!
3030

3131
Before commiting your migrations you should run your migrations up, down, and then up again to see if migrations are working properly both ways.
3232
(e.g. if you created a table in a migration but reverse migration did not delete it, you will encounter an error when running the forward migration again)
33-
It's also worth checking your migrations in a separate, containerized environment. You can find some tools in the end of this document.
33+
It's also worth checking your migrations in a separate, containerized environment. You can find some tools at the [end of this document](#further-reading).
3434

3535
**IMPORTANT:** If you would like to run multiple instances of your app on different machines be sure to use a database that supports locking when running migrations. Otherwise you may encounter issues.
3636

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/golang-migrate/migrate/CI/master)](https://github.com/golang-migrate/migrate/actions/workflows/ci.yaml?query=branch%3Amaster)
1+
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/golang-migrate/migrate/ci.yaml?branch=master)](https://github.com/golang-migrate/migrate/actions/workflows/ci.yaml?query=branch%3Amaster)
22
[![GoDoc](https://pkg.go.dev/badge/github.com/golang-migrate/migrate)](https://pkg.go.dev/github.com/golang-migrate/migrate/v4)
33
[![Coverage Status](https://img.shields.io/coveralls/github/golang-migrate/migrate/master.svg)](https://coveralls.io/github/golang-migrate/migrate?branch=master)
44
[![packagecloud.io](https://img.shields.io/badge/deb-packagecloud.io-844fec.svg)](https://packagecloud.io/golang-migrate/migrate?filter=debs)
55
[![Docker Pulls](https://img.shields.io/docker/pulls/migrate/migrate.svg)](https://hub.docker.com/r/migrate/migrate/)
6-
![Supported Go Versions](https://img.shields.io/badge/Go-1.17%2C%201.18-lightgrey.svg)
6+
![Supported Go Versions](https://img.shields.io/badge/Go-1.19%2C%201.20-lightgrey.svg)
77
[![GitHub Release](https://img.shields.io/github/release/golang-migrate/migrate.svg)](https://github.com/golang-migrate/migrate/releases)
8-
[![Go Report Card](https://goreportcard.com/badge/github.com/golang-migrate/migrate)](https://goreportcard.com/report/github.com/golang-migrate/migrate)
8+
[![Go Report Card](https://goreportcard.com/badge/github.com/golang-migrate/migrate/v4)](https://goreportcard.com/report/github.com/golang-migrate/migrate/v4)
99

1010
# migrate
1111

@@ -109,7 +109,7 @@ $ docker run -v {{ migration dir }}:/migrations --network host migrate/migrate
109109
* Uses `io.Reader` streams internally for low memory overhead.
110110
* Thread-safe and no goroutine leaks.
111111

112-
__[Go Documentation](https://godoc.org/github.com/golang-migrate/migrate)__
112+
__[Go Documentation](https://pkg.go.dev/github.com/golang-migrate/migrate/v4)__
113113

114114
```go
115115
import (

SECURITY.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
| Version | Supported |
6+
| ------- | ------------------ |
7+
| master | :white_check_mark: |
8+
| 4.x | :white_check_mark: |
9+
| 3.x | :x: |
10+
| < 3.0 | :x: |
11+
12+
## Reporting a Vulnerability
13+
14+
We prefer [coordinated disclosures](https://en.wikipedia.org/wiki/Coordinated_vulnerability_disclosure). To start one, create a GitHub security advisory following [these instructions](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability)
15+
16+
Please suggest potential impact and urgency in your reports.

cmd/migrate/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[Release Downloads](https://github.com/golang-migrate/migrate/releases)
88

99
```bash
10-
$ curl -L https://github.com/golang-migrate/migrate/releases/download/$version/migrate.$platform-amd64.tar.gz | tar xvz
10+
$ curl -L https://github.com/golang-migrate/migrate/releases/download/$version/migrate.$os-$arch.tar.gz | tar xvz
1111
```
1212

1313
### MacOS

database/cockroachdb/TUTORIAL.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ And in the `.down.sql` let's delete it:
5050
```
5151
DROP TABLE IF EXISTS example.users;
5252
```
53-
By adding `IF EXISTS/IF NOT EXISTS` we are making migrations idempotent - you can read more about idempotency in [getting started](GETTING_STARTED.md#create-migrations)
53+
By adding `IF EXISTS/IF NOT EXISTS` we are making migrations idempotent - you can read more about idempotency in [getting started](/GETTING_STARTED.md#create-migrations)
5454

5555
## Run migrations
5656
```
@@ -139,4 +139,4 @@ func main() {
139139
}
140140
}
141141
```
142-
You can find details [here](README.md#use-in-your-go-project)
142+
You can find details [here](README.md#use-in-your-go-project)

database/driver.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ var drivers = make(map[string]Driver)
2525
// Driver is the interface every database driver must implement.
2626
//
2727
// How to implement a database driver?
28-
// 1. Implement this interface.
29-
// 2. Optionally, add a function named `WithInstance`.
30-
// This function should accept an existing DB instance and a Config{} struct
31-
// and return a driver instance.
32-
// 3. Add a test that calls database/testing.go:Test()
33-
// 4. Add own tests for Open(), WithInstance() (when provided) and Close().
34-
// All other functions are tested by tests in database/testing.
35-
// Saves you some time and makes sure all database drivers behave the same way.
36-
// 5. Call Register in init().
37-
// 6. Create a internal/cli/build_<driver-name>.go file
38-
// 7. Add driver name in 'DATABASE' variable in Makefile
28+
// 1. Implement this interface.
29+
// 2. Optionally, add a function named `WithInstance`.
30+
// This function should accept an existing DB instance and a Config{} struct
31+
// and return a driver instance.
32+
// 3. Add a test that calls database/testing.go:Test()
33+
// 4. Add own tests for Open(), WithInstance() (when provided) and Close().
34+
// All other functions are tested by tests in database/testing.
35+
// Saves you some time and makes sure all database drivers behave the same way.
36+
// 5. Call Register in init().
37+
// 6. Create a internal/cli/build_<driver-name>.go file
38+
// 7. Add driver name in 'DATABASE' variable in Makefile
3939
//
4040
// Guidelines:
41-
// * Don't try to correct user input. Don't assume things.
41+
// - Don't try to correct user input. Don't assume things.
4242
// When in doubt, return an error and explain the situation to the user.
43-
// * All configuration input must come from the URL string in func Open()
43+
// - All configuration input must come from the URL string in func Open()
4444
// or the Config{} struct in WithInstance. Don't os.Getenv().
4545
type Driver interface {
4646
// Open returns a new driver instance configured with parameters

database/yugabytedb/yugabytedb.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/golang-migrate/migrate/v4"
1515
"github.com/golang-migrate/migrate/v4/database"
1616
"github.com/hashicorp/go-multierror"
17+
"github.com/jackc/pgconn"
18+
"github.com/jackc/pgerrcode"
1719
"github.com/lib/pq"
1820
"go.uber.org/atomic"
1921
)
@@ -462,18 +464,16 @@ func (c *YugabyteDB) newBackoff(ctx context.Context) backoff.BackOff {
462464
}
463465

464466
func errIsRetryable(err error) bool {
465-
pqErr := pq.Error{}
466-
if !errors.As(err, &pqErr) {
467+
var pgErr *pgconn.PgError
468+
if !errors.As(err, &pgErr) {
467469
return false
468470
}
469471

470-
code := string(pqErr.Code)
471-
472472
// Assume that it's safe to retry 08006 and XX000 because we check for lock existence
473473
// before creating and lock ID is primary key. Version field in migrations table is primary key too
474-
// and delete all versions is an idempotend operation.
475-
return code == "40001" || // Serialization error (optimistic locking conflict)
476-
code == "40P01" || // Deadlock
477-
code == "08006" || // Connection failure (node down, need to reconnect)
478-
code == "XX000" // Internal error (may happen during HA)
474+
// and delete all versions is an idempotent operation.
475+
return pgErr.Code == pgerrcode.SerializationFailure || // optimistic locking conflict
476+
pgErr.Code == pgerrcode.DeadlockDetected ||
477+
pgErr.Code == pgerrcode.ConnectionFailure || // node down, need to reconnect
478+
pgErr.Code == pgerrcode.InternalError // may happen during HA
479479
}

0 commit comments

Comments
 (0)