Skip to content

Commit fb22436

Browse files
committed
Merge remote-tracking branch 'origin/master' into upgrade-spanner
2 parents 72957b6 + 47a2661 commit fb22436

20 files changed

+779
-154
lines changed

.github/workflows/ci.yaml

+13-13
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.20.x"
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.19.x", "1.20.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

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20-alpine3.18 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.18
18+
FROM alpine:3.19
1919

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

Dockerfile.github-actions

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.18
1+
FROM alpine:3.19
22

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

FAQ.md

+1-1
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

+1-1
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

+1-1
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 pgx5
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

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Database drivers run migrations. [Add a new database?](database/driver.go)
4343
* [ClickHouse](database/clickhouse)
4444
* [Firebird](database/firebird)
4545
* [MS SQL Server](database/sqlserver)
46+
* [RQLite](database/rqlite)
4647

4748
### Database URLs
4849

database/parse_test.go

+9-8
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/postgres/TUTORIAL.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ If there were no errors, we should have two files available under `db/migrations
2727
Note the `sql` extension that we provided.
2828

2929
In the `.up.sql` file let's create the table:
30-
```
30+
```sql
3131
CREATE TABLE IF NOT EXISTS users(
3232
user_id serial PRIMARY KEY,
3333
username VARCHAR (50) UNIQUE NOT NULL,
@@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS users(
3636
);
3737
```
3838
And in the `.down.sql` let's delete it:
39-
```
39+
```sql
4040
DROP TABLE IF EXISTS users;
4141
```
4242
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)
@@ -79,7 +79,7 @@ Again, it should create for us two migrations files:
7979
In Postgres, when we want our queries to be done in a transaction, we need to wrap it with `BEGIN` and `COMMIT` commands.
8080
In our example, we are going to add a column to our database that can only accept enumerable values or NULL.
8181
Migration up:
82-
```
82+
```sql
8383
BEGIN;
8484

8585
CREATE TYPE enum_mood AS ENUM (
@@ -92,7 +92,7 @@ ALTER TABLE users ADD COLUMN mood enum_mood;
9292
COMMIT;
9393
```
9494
Migration down:
95-
```
95+
```sql
9696
BEGIN;
9797

9898
ALTER TABLE users DROP COLUMN mood;
@@ -124,7 +124,7 @@ Indexes:
124124

125125
## Optional: Run migrations within your Go app
126126
Here is a very simple app running migrations for the above configuration:
127-
```
127+
```go
128128
import (
129129
"log"
130130

database/rqlite/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# rqlite
2+
3+
`rqlite://admin:[email protected]:4001/?level=strong&timeout=5`
4+
5+
The `rqlite` url scheme is used for both secure and insecure connections. If connecting to an insecure database, pass `x-connect-insecure` in your URL query, or use `WithInstance` to pass an established connection.
6+
7+
The migrations table name is configurable through the `x-migrations-table` URL query parameter, or by using `WithInstance` and passing `MigrationsTable` through `Config`.
8+
9+
Other connect parameters are directly passed through to the database driver. For examples of connection strings, see https://github.com/rqlite/gorqlite#examples.
10+
11+
| URL Query | WithInstance Config | Description |
12+
|------------|---------------------|-------------|
13+
| `x-connect-insecure` | n/a: set on instance | Boolean to indicate whether to use an insecure connection. Defaults to `false`. |
14+
| `x-migrations-table` | `MigrationsTable` | Name of the migrations table. Defaults to `schema_migrations`. |
15+
16+
## Notes
17+
18+
* Uses the https://github.com/rqlite/gorqlite driver
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE IF EXISTS pets;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE TABLE pets (
2+
name string
3+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE IF EXISTS pets;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE pets ADD predator bool;

0 commit comments

Comments
 (0)