Skip to content

Commit e29809a

Browse files
authored
Merge branch 'master' into pg-db-dump-truncate-fix
2 parents 6e91d4e + 0695426 commit e29809a

33 files changed

+2480
-658
lines changed

.github/workflows/ci.yaml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
name: lint
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/setup-go@v3
12+
- uses: actions/setup-go@v5
1313
with:
14-
go-version: 1.19
15-
- uses: actions/checkout@v3
14+
go-version: "1.21.x"
15+
- uses: actions/checkout@v4
1616
- name: golangci-lint
1717
uses: golangci/golangci-lint-action@v3
1818
with:
@@ -22,11 +22,11 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
go: ["1.18.x", "1.19.x"]
25+
go: ["1.20.x", "1.21.x"]
2626
steps:
27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2828

29-
- uses: actions/setup-go@v3
29+
- uses: actions/setup-go@v5
3030
with:
3131
go-version: ${{ matrix.go }}
3232

@@ -60,27 +60,27 @@ jobs:
6060
# 3. When the workflow is triggered by a tag with `v` prefix
6161
if: ${{ success() && github.repository == 'golang-migrate/migrate' && startsWith(github.ref, 'refs/tags/v') }}
6262
steps:
63-
- uses: actions/checkout@v3
63+
- uses: actions/checkout@v4
6464
with:
6565
fetch-depth: 0
6666
- uses: ruby/setup-ruby@v1
6767
with:
6868
ruby-version: 2.7
69-
- uses: actions/setup-go@v3
69+
- uses: actions/setup-go@v5
7070
with:
71-
go-version: "1.19.x"
71+
go-version: "1.21.x"
7272

73-
- uses: docker/setup-qemu-action@v1
74-
- uses: docker/setup-buildx-action@v1
75-
- uses: docker/login-action@v1
73+
- uses: docker/setup-qemu-action@v3
74+
- uses: docker/setup-buildx-action@v3
75+
- uses: docker/login-action@v3
7676
with:
7777
username: golangmigrate
7878
password: ${{ secrets.DOCKERHUB_TOKEN }}
7979

8080
- run: echo "SOURCE=$(make echo-source)" >> $GITHUB_ENV
8181
- run: echo "DATABASE=$(make echo-database)" >> $GITHUB_ENV
8282

83-
- uses: goreleaser/goreleaser-action@v2
83+
- uses: goreleaser/goreleaser-action@v5
8484
with:
8585
version: latest
8686
args: release --rm-dist
@@ -94,9 +94,15 @@ jobs:
9494
- run: package_cloud push golang-migrate/migrate/ubuntu/focal dist/migrate.linux-amd64.deb
9595
env:
9696
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
97+
- run: package_cloud push golang-migrate/migrate/ubuntu/jammy dist/migrate.linux-amd64.deb
98+
env:
99+
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
97100
- run: package_cloud push golang-migrate/migrate/debian/buster dist/migrate.linux-amd64.deb
98101
env:
99102
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
100103
- run: package_cloud push golang-migrate/migrate/debian/bullseye dist/migrate.linux-amd64.deb
101104
env:
102105
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
106+
- run: package_cloud push golang-migrate/migrate/debian/bookworm dist/migrate.linux-amd64.deb
107+
env:
108+
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ release:
8787
prerelease: auto
8888
source:
8989
enabled: true
90+
rlcp: true
9091
format: zip
9192
changelog:
9293
skip: false

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.19-alpine3.16 AS builder
1+
FROM golang:1.21-alpine3.19 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.16
18+
FROM alpine:3.19
1919

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

Dockerfile.github-actions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.16
1+
FROM alpine:3.19
22

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

FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
and whenever we want, not just once at the beginning of all tests.
5151

5252
#### Can I maintain my driver in my own repository?
53-
Yes, technically thats possible. We want to encourage you to contribute your driver to this respository though.
53+
Yes, technically thats possible. We want to encourage you to contribute your driver to this repository though.
5454
The driver's functionality is dictated by migrate's interfaces. That means there should really
5555
just be one driver for a database/ source. We want to prevent a future where several drivers doing the exact same thing,
5656
just implemented a bit differently, co-exist somewhere on GitHub. If users have to do research first to find the

GETTING_STARTED.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ migrate -database YOUR_DATABASE_URL -path PATH_TO_YOUR_MIGRATIONS up
2828

2929
Just add the code to your app and you're ready to go!
3030

31-
Before commiting your migrations you should run your migrations up, down, and then up again to see if migrations are working properly both ways.
31+
Before committing 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)
3333
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

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
SOURCE ?= file go_bindata github github_ee bitbucket aws_s3 google_cloud_storage godoc_vfs gitlab
2-
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx
2+
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgx5 rqlite
33
DATABASE_TEST ?= $(DATABASE) sqlite sqlite3 sqlcipher
44
VERSION ?= $(shell git describe --tags 2>/dev/null | cut -c 2-)
55
TEST_FLAGS ?=

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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.18%2C%201.19-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)
88
[![Go Report Card](https://goreportcard.com/badge/github.com/golang-migrate/migrate/v4)](https://goreportcard.com/report/github.com/golang-migrate/migrate/v4)
99

@@ -24,7 +24,8 @@ Forked from [mattes/migrate](https://github.com/mattes/migrate)
2424
Database drivers run migrations. [Add a new database?](database/driver.go)
2525

2626
* [PostgreSQL](database/postgres)
27-
* [PGX](database/pgx)
27+
* [PGX v4](database/pgx)
28+
* [PGX v5](database/pgx/v5)
2829
* [Redshift](database/redshift)
2930
* [Ql](database/ql)
3031
* [Cassandra](database/cassandra)
@@ -42,6 +43,7 @@ Database drivers run migrations. [Add a new database?](database/driver.go)
4243
* [ClickHouse](database/clickhouse)
4344
* [Firebird](database/firebird)
4445
* [MS SQL Server](database/sqlserver)
46+
* [RQLite](database/rqlite)
4547

4648
### Database URLs
4749

@@ -169,6 +171,11 @@ Each migration has an up and down migration. [Why?](FAQ.md#why-two-separate-file
169171

170172
[Best practices: How to write migrations.](MIGRATIONS.md)
171173

174+
## Coming from another db migration tool?
175+
176+
Check out [migradaptor](https://github.com/musinit/migradaptor/).
177+
*Note: migradaptor is not affliated or supported by this project*
178+
172179
## Versions
173180

174181
Version | Supported? | Import | Notes

cmd/migrate/README.md

Lines changed: 1 addition & 1 deletion
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/parse_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import (
88
)
99

1010
const reservedChars = "!#$%&'()*+,/:;=?@[]"
11+
const reservedCharTestNamePrefix = "reserved char "
1112

1213
const baseUsername = "username"
1314

15+
const scheme = "database://"
16+
1417
// TestUserUnencodedReservedURLChars documents the behavior of using unencoded reserved characters in usernames with
1518
// net/url Parse()
1619
func TestUserUnencodedReservedURLChars(t *testing.T) {
17-
scheme := "database://"
1820
urlSuffix := "password@localhost:12345/myDB?someParam=true"
1921
urlSuffixAndSep := ":" + urlSuffix
2022

@@ -64,7 +66,7 @@ func TestUserUnencodedReservedURLChars(t *testing.T) {
6466
testedChars := make([]string, 0, len(reservedChars))
6567
for _, tc := range testcases {
6668
testedChars = append(testedChars, tc.char)
67-
t.Run("reserved char "+tc.char, func(t *testing.T) {
69+
t.Run(reservedCharTestNamePrefix+tc.char, func(t *testing.T) {
6870
s := scheme + baseUsername + tc.char + urlSuffixAndSep
6971
u, err := url.Parse(s)
7072
if err == nil {
@@ -98,13 +100,12 @@ func TestUserUnencodedReservedURLChars(t *testing.T) {
98100
}
99101

100102
func TestUserEncodedReservedURLChars(t *testing.T) {
101-
scheme := "database://"
102103
urlSuffix := "password@localhost:12345/myDB?someParam=true"
103104
urlSuffixAndSep := ":" + urlSuffix
104105

105106
for _, c := range reservedChars {
106107
c := string(c)
107-
t.Run("reserved char "+c, func(t *testing.T) {
108+
t.Run(reservedCharTestNamePrefix+c, func(t *testing.T) {
108109
encodedChar := "%" + hex.EncodeToString([]byte(c))
109110
s := scheme + baseUsername + encodedChar + urlSuffixAndSep
110111
expectedUsername := baseUsername + c
@@ -126,7 +127,7 @@ func TestUserEncodedReservedURLChars(t *testing.T) {
126127
// with net/url Parse()
127128
func TestPasswordUnencodedReservedURLChars(t *testing.T) {
128129
username := baseUsername
129-
schemeAndUsernameAndSep := "database://" + username + ":"
130+
schemeAndUsernameAndSep := scheme + username + ":"
130131
basePassword := "password"
131132
urlSuffixAndSep := "@localhost:12345/myDB?someParam=true"
132133

@@ -174,7 +175,7 @@ func TestPasswordUnencodedReservedURLChars(t *testing.T) {
174175
testedChars := make([]string, 0, len(reservedChars))
175176
for _, tc := range testcases {
176177
testedChars = append(testedChars, tc.char)
177-
t.Run("reserved char "+tc.char, func(t *testing.T) {
178+
t.Run(reservedCharTestNamePrefix+tc.char, func(t *testing.T) {
178179
s := schemeAndUsernameAndSep + basePassword + tc.char + urlSuffixAndSep
179180
u, err := url.Parse(s)
180181
if err == nil {
@@ -213,13 +214,13 @@ func TestPasswordUnencodedReservedURLChars(t *testing.T) {
213214

214215
func TestPasswordEncodedReservedURLChars(t *testing.T) {
215216
username := baseUsername
216-
schemeAndUsernameAndSep := "database://" + username + ":"
217+
schemeAndUsernameAndSep := scheme + username + ":"
217218
basePassword := "password"
218219
urlSuffixAndSep := "@localhost:12345/myDB?someParam=true"
219220

220221
for _, c := range reservedChars {
221222
c := string(c)
222-
t.Run("reserved char "+c, func(t *testing.T) {
223+
t.Run(reservedCharTestNamePrefix+c, func(t *testing.T) {
223224
encodedChar := "%" + hex.EncodeToString([]byte(c))
224225
s := schemeAndUsernameAndSep + basePassword + encodedChar + urlSuffixAndSep
225226
expectedPassword := basePassword + c

database/pgx/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# pgx
22

3+
This package is for [pgx/v4](https://pkg.go.dev/github.com/jackc/pgx/v4). A backend for the newer [pgx/v5](https://pkg.go.dev/github.com/jackc/pgx/v5) is [also available](v5).
4+
35
`pgx://user:password@host:port/dbname?query`
46

57
| URL Query | WithInstance Config | Description |

database/pgx/pgx.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
func init() {
2929
db := Postgres{}
3030
database.Register("pgx", &db)
31+
database.Register("pgx4", &db)
3132
}
3233

3334
var (
@@ -150,7 +151,7 @@ func (p *Postgres) Open(url string) (database.Driver, error) {
150151
// i.e. pgx://user:password@host:port/db => postgres://user:password@host:port/db
151152
purl.Scheme = "postgres"
152153

153-
db, err := sql.Open("pgx", migrate.FilterCustomQuery(purl).String())
154+
db, err := sql.Open("pgx/v4", migrate.FilterCustomQuery(purl).String())
154155
if err != nil {
155156
return nil, err
156157
}

database/pgx/pgx_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@ import (
88
sqldriver "database/sql/driver"
99
"errors"
1010
"fmt"
11-
"log"
12-
1311
"io"
12+
"log"
1413
"strconv"
1514
"strings"
1615
"sync"
1716
"testing"
1817

19-
"github.com/golang-migrate/migrate/v4"
20-
2118
"github.com/dhui/dktest"
22-
19+
"github.com/golang-migrate/migrate/v4"
2320
"github.com/golang-migrate/migrate/v4/database"
21+
2422
dt "github.com/golang-migrate/migrate/v4/database/testing"
2523
"github.com/golang-migrate/migrate/v4/dktesting"
2624
_ "github.com/golang-migrate/migrate/v4/source/file"
@@ -41,6 +39,9 @@ var (
4139
{ImageName: "postgres:10", Options: opts},
4240
{ImageName: "postgres:11", Options: opts},
4341
{ImageName: "postgres:12", Options: opts},
42+
{ImageName: "postgres:13", Options: opts},
43+
{ImageName: "postgres:14", Options: opts},
44+
{ImageName: "postgres:15", Options: opts},
4445
}
4546
)
4647

database/pgx/v5/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# pgx
2+
3+
This package is for [pgx/v5](https://pkg.go.dev/github.com/jackc/pgx/v5). A backend for the older [pgx/v4](https://pkg.go.dev/github.com/jackc/pgx/v4). is [also available](..).
4+
5+
`pgx5://user:password@host:port/dbname?query`
6+
7+
| URL Query | WithInstance Config | Description |
8+
|------------|---------------------|-------------|
9+
| `x-migrations-table` | `MigrationsTable` | Name of the migrations table |
10+
| `x-migrations-table-quoted` | `MigrationsTableQuoted` | By default, migrate quotes the migration table for SQL injection safety reasons. This option disable quoting and naively checks that you have quoted the migration table name. e.g. `"my_schema"."schema_migrations"` |
11+
| `x-statement-timeout` | `StatementTimeout` | Abort any statement that takes more than the specified number of milliseconds |
12+
| `x-multi-statement` | `MultiStatementEnabled` | Enable multi-statement execution (default: false) |
13+
| `x-multi-statement-max-size` | `MultiStatementMaxSize` | Maximum size of single statement in bytes (default: 10MB) |
14+
| `dbname` | `DatabaseName` | The name of the database to connect to |
15+
| `search_path` | | This variable specifies the order in which schemas are searched when an object is referenced by a simple name with no schema specified. |
16+
| `user` | | The user to sign in as |
17+
| `password` | | The user's password |
18+
| `host` | | The host to connect to. Values that start with / are for unix domain sockets. (default is localhost) |
19+
| `port` | | The port to bind to. (default is 5432) |
20+
| `fallback_application_name` | | An application_name to fall back to if one isn't provided. |
21+
| `connect_timeout` | | Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely. |
22+
| `sslcert` | | Cert file location. The file must contain PEM encoded data. |
23+
| `sslkey` | | Key file location. The file must contain PEM encoded data. |
24+
| `sslrootcert` | | The location of the root certificate file. The file must contain PEM encoded data. |
25+
| `sslmode` | | Whether or not to use SSL (disable\|require\|verify-ca\|verify-full) |
26+
27+
28+
## Upgrading from v1
29+
30+
1. Write down the current migration version from schema_migrations
31+
1. `DROP TABLE schema_migrations`
32+
2. Wrap your existing migrations in transactions ([BEGIN/COMMIT](https://www.postgresql.org/docs/current/static/transaction-iso.html)) if you use multiple statements within one migration.
33+
3. Download and install the latest migrate version.
34+
4. Force the current migration version with `migrate force <current_version>`.
35+
36+
## Multi-statement mode
37+
38+
In PostgreSQL running multiple SQL statements in one `Exec` executes them inside a transaction. Sometimes this
39+
behavior is not desirable because some statements can be only run outside of transaction (e.g.
40+
`CREATE INDEX CONCURRENTLY`). If you want to use `CREATE INDEX CONCURRENTLY` without activating multi-statement mode
41+
you have to put such statements in a separate migration files.

0 commit comments

Comments
 (0)