Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
90273fe
clickhouse: Quote db name in ensureVersionTable
luca-nardelli Nov 29, 2022
9fe7383
Quote in drop as well
luca-nardelli Nov 30, 2022
839421e
Leverage quoteIdentifier from pgx
luca-nardelli Nov 30, 2022
50112e7
Add to clickhouse README.md database creation
volum-nova Jan 24, 2023
90a3ac4
Remove cluster adaptation for tables to pass tests
volum-nova Jan 24, 2023
64755d0
Update README.md
volum-nova Jan 24, 2023
3b02b18
Correct a spelling mistake
volum-nova Mar 19, 2023
92dec35
Move supported go version to standard place
SuperSandro2000 Jun 1, 2023
7a72550
add tests for scylladb. add scylladb to docs
mkorolyov Jun 21, 2023
45d23ed
Merge branch 'master' into scylladb_support
mkorolyov Jul 11, 2023
f8afa5a
small changes to retry failed by timeout CI
mkorolyov Jul 17, 2023
876a13d
Update aws-sdk-go to adress vulerabilitiy
Kenai Jul 18, 2023
f2e0b33
Update lib/pq to fix cert permissions issues
jorng Jul 20, 2023
129922a
Added support for pgx locking table
fortnox-andreas Sep 20, 2023
bead4a9
Added documentation and test for lock strategy
tsfcode Sep 20, 2023
12968a7
Add syntax highlighting to Postgres example
tbysctt Nov 4, 2023
72957b6
Updated version of spanner to support sequences and generate uuid
jsabbatini-upguard Nov 14, 2023
ee8a8e5
fix: typo
testwill Nov 27, 2023
5163ac7
feature: add rqlite support
swensone Nov 5, 2023
cf03803
Add rqlite 8.0.0 to tested database versions
swensone Dec 6, 2023
669437c
update rqlite 8 container version to 8.0.6
swensone Dec 14, 2023
7eac919
Merge pull request #1006 from testwill/typo
dhui Dec 19, 2023
4078ef8
New release prep
dhui Dec 19, 2023
b567287
Update from alpine 3.18 to 3.19
dhui Dec 19, 2023
5ded96d
Bump golang.org/x/crypto from 0.14.0 to 0.17.0
dependabot[bot] Dec 19, 2023
7d03609
add 8.11 and 8.12 versions and remove debug logging
swensone Dec 19, 2023
bfedabb
Merge remote-tracking branch 'upstream/master'
swensone Dec 19, 2023
834fa39
Merge pull request #1014 from golang-migrate/dependabot/go_modules/go…
dhui Dec 20, 2023
f375aeb
Merge pull request #1007 from swensone/master
dhui Dec 20, 2023
c3ebd52
Bump google.golang.org/grpc from 1.55.0 to 1.56.3
dependabot[bot] Dec 20, 2023
b39ee92
Merge pull request #999 from tobyscott25/patch-1
dhui Dec 20, 2023
47a2661
Merge pull request #1015 from golang-migrate/dependabot/go_modules/go…
dhui Dec 20, 2023
fb22436
Merge remote-tracking branch 'origin/master' into upgrade-spanner
dhui Dec 20, 2023
5026488
Clean up require directive grouping
dhui Dec 20, 2023
90c5015
Merge pull request #959 from jorng/libpq-update
dhui Dec 20, 2023
76efa72
Merge branch 'master' into master
dhui Dec 20, 2023
1d1cd48
Merge branch 'master' into scylladb_support
dhui Dec 20, 2023
0695426
Merge pull request #929 from SuperSandro2000/patch-1
dhui Dec 20, 2023
2063684
Merge branch 'master' into master
dhui Dec 20, 2023
0ba6fc3
Merge pull request #1002 from jsabbatini-upguard/upgrade-spanner
dhui Dec 20, 2023
a94396c
Merge pull request #857 from luca-nardelli/master
dhui Dec 20, 2023
eb64ffa
Merge pull request #947 from mkorolyov/scylladb_support
dhui Dec 20, 2023
691f687
Reformat ScyllaDB/Cassandra docs
dhui Dec 20, 2023
e8edcdc
Merge branch 'master' into master
dhui Dec 20, 2023
ab24e76
Merge branch 'master' into clickhouse_create_database_migrations
dhui Dec 20, 2023
091ad5d
Quote locktable from config in queries
tsfcode Dec 20, 2023
9c551d4
Merge pull request #875 from no-name16/clickhouse_create_database_mig…
dhui Dec 20, 2023
c7c5011
Merge pull request #956 from Kenai/master
dhui Dec 20, 2023
f2c4b52
Update aws-sdk-go from v1.44.301 to v1.49.6
dhui Dec 20, 2023
cd17c5a
Drop support for Go 1.19 and add support for Go 1.21
dhui Dec 20, 2023
d63a5c2
Only test against YugabyteDB LTS releases
dhui Dec 20, 2023
5aa4670
Fix GoReleaser deprecations
dhui Dec 20, 2023
0815e2d
Merge pull request #992 from fortnox-andreas/master
dhui Dec 20, 2023
8147693
[sqlserver] Ensure version table in provided schema
alex-kuck Oct 26, 2022
0350a00
[sqlserver] Always access version table with explicit schema
alex-kuck Oct 26, 2022
516f038
Merge pull request #840 from alex-kuck/fix/839/sqlserver_version_table
dhui Dec 31, 2023
a860f0c
Bump github.com/dvsekhvalnov/jose2go from 1.5.0 to 1.6.0
dependabot[bot] Dec 31, 2023
0d41589
Merge pull request #1022 from golang-migrate/dependabot/go_modules/gi…
dhui Jan 2, 2024
94b8fa5
rqlite is spelled with all lowercase
otoolep Jan 5, 2024
a5dc5d1
Merge pull request #1025 from otoolep/patch-1
dhui Jan 11, 2024
7f85f9c
chore: fix some typos
occupyhabit Mar 23, 2024
ff8a961
Update yugabyte test images
dhui Mar 25, 2024
87ba13c
Merge pull request #1061 from occupyhabit/master
dhui Mar 25, 2024
e913336
Drop support for Go 1.20 and add support for Go 1.22
dhui Mar 25, 2024
9d70a39
chore: fix some typos in comments
goodfirm Apr 10, 2024
4bc6777
Add dktesting.Cleanup() method
dhui Apr 15, 2024
2884a8e
Cleanup postgres images after tests run
dhui Apr 15, 2024
1b707a7
Cleanup cassandra images after tests run
dhui Apr 15, 2024
06614d9
Cleanup yugabytedb images after tests run
dhui Apr 15, 2024
49cac86
Cleanup mongodb images after tests run
dhui Apr 15, 2024
b1d02e2
Cleanup sqlserver images after tests run
dhui Apr 16, 2024
f4950c1
Fallback to dktest.DefaultCleanupTimeout if the dktest.Options doesn'…
dhui Apr 16, 2024
2c5df87
Merge pull request #1072 from dhui/dktesting-cleanup
dhui Apr 16, 2024
1a002d0
Set golangci-lint to 1.54.2 (latest is broken) (#1046)
rockdaboot Apr 16, 2024
d1df97b
Bump github.com/jackc/pgx/v4 from 4.18.1 to 4.18.2
dependabot[bot] Apr 16, 2024
2e0872f
Bump google.golang.org/protobuf from 1.31.0 to 1.33.0
dependabot[bot] Apr 16, 2024
128b650
Merge pull request #1050 from golang-migrate/dependabot/go_modules/gi…
dhui Apr 16, 2024
837776f
Merge pull request #1054 from golang-migrate/dependabot/go_modules/go…
dhui Apr 16, 2024
a78d1ab
Bump github.com/jackc/pgx/v5 from 5.3.1 to 5.5.4
dependabot[bot] Apr 16, 2024
c523775
Merge pull request #1055 from golang-migrate/dependabot/go_modules/gi…
dhui Apr 17, 2024
f100226
Update dktest from v0.4.0 to v0.4.1 to fix docker vulnerability
dhui Apr 17, 2024
0c456c4
Merge pull request #1068 from goodfirm/master
dhui Apr 17, 2024
e428ece
Make MySQL SetVersion compatible with sql_safe_update
maxmati Apr 10, 2024
859d92b
Bump golang.org/x/net from 0.21.0 to 0.23.0
dependabot[bot] Apr 19, 2024
45e4f1e
Merge pull request #1074 from golang-migrate/dependabot/go_modules/go…
dhui Apr 30, 2024
04b36eb
Merge pull request #1070 from certifaction/mysql-safe-update
dhui Apr 30, 2024
c81eaf7
Upgrade go-sqlite3 to v1.14.22
gjabell May 31, 2024
da72428
Update README.md
adityassharma-ss Jun 4, 2024
cabb2db
🧑‍💻 improve error message for invalid source, database, resolves: #1102
Shion1305 Jun 5, 2024
1735cb3
🚨 golangci-lint: disable interfacer linter
Shion1305 Jun 5, 2024
34594af
🚨 golangci-lint: fix for errcheck lint errors
Shion1305 Jun 5, 2024
b16220c
Merge pull request #1105 from Shion1305/shion/issue-1104
dhui Jun 10, 2024
1585b87
Merge pull request #1103 from Shion1305/shion/issue-1102
dhui Jun 10, 2024
2477f63
Merge pull request #1098 from gjabell/master
dhui Jun 10, 2024
41e389a
Support .deb package for Noble Numbat (24.04)
muzammilar Jul 17, 2024
899a244
Fix redshift tests
dhui Aug 30, 2024
e1a7e31
Use forked version of postgres 8 to avoid Docker image format version…
dhui Sep 6, 2024
f44379d
Merge pull request #1151 from dhui/fix-redshift-tests
dhui Sep 6, 2024
1b1c6f6
Use newer math/rand/v2
dhui Aug 26, 2024
897be38
chore: remove deprecated `rand.Seed()` in testing.docker (#1149)
joschi Sep 7, 2024
d28e549
Update dktest from v0.4.1 to v0.4.2
dhui Sep 7, 2024
ee93fd4
build: use Go 1.23 to build the project
joschi Aug 13, 2024
f4d986b
test(mysql): run tests with MySQL 8.0, 8.4, and 9.0
joschi Aug 7, 2024
0444ec8
test(postgres): run tests with PostgreSQL 16
joschi Aug 7, 2024
6ceb5a9
fix(tests): fix Docker imports
joschi Sep 7, 2024
e40e64c
Merge pull request #1133 from joschi/go-1.23
dhui Sep 8, 2024
65a3bd5
Merge pull request #1153 from joschi/fix-docker-imports
dhui Sep 8, 2024
7e8f6be
Merge pull request #1126 from joschi/tests-postgres-16
dhui Sep 8, 2024
ddd7fa6
Merge pull request #1127 from joschi/tests-mysql-9
dhui Sep 8, 2024
5b6f623
Bump google.golang.org/grpc from 1.64.0 to 1.64.1
dependabot[bot] Sep 8, 2024
1e02b42
Merge pull request #1119 from muzammilar/add-noble-numbat
dhui Sep 8, 2024
67c71f9
Merge pull request #1152 from golang-migrate/dependabot/go_modules/go…
dhui Sep 8, 2024
d5eb594
Merge pull request #1101 from adityassharma-ss/patch-1
dhui Sep 8, 2024
555501f
Update dktest from v0.4.2 to v0.4.3
dhui Sep 8, 2024
e22d012
Don't output sensitive information on error
Sep 12, 2024
c378583
Merge pull request #1162 from rselbach/rselbach/no-sensitive-info
dhui Sep 23, 2024
ddbc0e4
"Rebase" off the parent, as best as one can when this repo isn't an a…
nik-kc Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jobs:
key: go-mod-v1-{{ arch }}-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run: go get github.com/mattn/goveralls
- run: goveralls -service=circle-ci -coverprofile /tmp/coverage/combined.txt

"golang-1_16":
<<: *template
Expand Down
49 changes: 18 additions & 31 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,30 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: "1.20.x"
- uses: actions/checkout@v3
go-version: "1.23.x"
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: latest

test:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.19.x", "1.20.x"]
go: ["1.22.x", "1.23.x"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: Run test
run: make test COVERAGE_DIR=/tmp/coverage

- name: Send goveralls coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: /tmp/coverage/combined.txt
flag-name: Go-${{ matrix.go }}
parallel: true

check-coverage:
name: Check coverage
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true

goreleaser:
name: Release a new version
needs: [lint, test]
Expand All @@ -60,30 +44,30 @@ jobs:
# 3. When the workflow is triggered by a tag with `v` prefix
if: ${{ success() && github.repository == 'golang-migrate/migrate' && startsWith(github.ref, 'refs/tags/v') }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: "1.19.x"
go-version: "1.23.x"

- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: golangmigrate
password: ${{ secrets.DOCKERHUB_TOKEN }}

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

- uses: goreleaser/goreleaser-action@v2
- uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --rm-dist
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -97,6 +81,9 @@ jobs:
- run: package_cloud push golang-migrate/migrate/ubuntu/jammy dist/migrate.linux-amd64.deb
env:
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
- run: package_cloud push golang-migrate/migrate/ubuntu/noble dist/migrate.linux-amd64.deb
env:
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
- run: package_cloud push golang-migrate/migrate/debian/buster dist/migrate.linux-amd64.deb
env:
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run:
linters:
enable:
#- golint
- interfacer
#- interfacer
- unconvert
#- dupl
- goconst
Expand Down
1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ release:
prerelease: auto
source:
enabled: true
rlcp: true
format: zip
changelog:
skip: false
Expand Down
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ before_install:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.30.0
- echo "TRAVIS_GO_VERSION=${TRAVIS_GO_VERSION}"

install:
- go get github.com/mattn/goveralls

script:
- golangci-lint run
- make test COVERAGE_DIR=/tmp/coverage

after_success:
- goveralls -service=travis-ci -coverprofile /tmp/coverage/combined.txt
- make list-external-deps > dependency_tree.txt && cat dependency_tree.txt
- make build-cli
- gem install --no-document fpm
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-alpine3.18 AS builder
FROM golang:1.23-alpine3.20 AS builder
ARG VERSION

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

RUN make build-docker

FROM alpine:3.18
FROM alpine:3.20

RUN apk add --no-cache ca-certificates

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.github-actions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.18
FROM alpine:3.19

RUN apk add --no-cache ca-certificates

Expand Down
2 changes: 1 addition & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
and whenever we want, not just once at the beginning of all tests.

#### Can I maintain my driver in my own repository?
Yes, technically thats possible. We want to encourage you to contribute your driver to this respository though.
Yes, technically thats possible. We want to encourage you to contribute your driver to this repository though.
The driver's functionality is dictated by migrate's interfaces. That means there should really
just be one driver for a database/ source. We want to prevent a future where several drivers doing the exact same thing,
just implemented a bit differently, co-exist somewhere on GitHub. If users have to do research first to find the
Expand Down
2 changes: 1 addition & 1 deletion GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ migrate -database YOUR_DATABASE_URL -path PATH_TO_YOUR_MIGRATIONS up

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

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

Expand Down
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
SOURCE ?= file go_bindata github github_ee bitbucket aws_s3 google_cloud_storage godoc_vfs gitlab
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgx5
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgx5 rqlite duckdb
DATABASE_TEST ?= $(DATABASE) sqlite sqlite3 sqlcipher
VERSION ?= $(shell git describe --tags 2>/dev/null | cut -c 2-)
TEST_FLAGS ?=
REPO_OWNER ?= $(shell cd .. && basename "$$(pwd)")
COVERAGE_DIR ?= .coverage

build:
CGO_ENABLED=0 go build -ldflags='-X main.Version=$(VERSION)' -tags '$(DATABASE) $(SOURCE)' ./cmd/migrate
CGO_ENABLED=1 go build -ldflags='-X main.Version=$(VERSION)' -tags '$(DATABASE) $(SOURCE)' ./cmd/migrate

build-docker:
CGO_ENABLED=0 go build -a -o build/migrate.linux-386 -ldflags="-s -w -X main.Version=${VERSION}" -tags "$(DATABASE) $(SOURCE)" ./cmd/migrate
CGO_ENABLED=1 go build -a -o build/migrate.linux-386 -ldflags="-s -w -X main.Version=${VERSION}" -tags "$(DATABASE) $(SOURCE)" ./cmd/migrate

build-cli: clean
-mkdir ./cli/build
cd ./cmd/migrate && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o ../../cli/build/migrate.linux-amd64 -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -a -o ../../cli/build/migrate.linux-armv7 -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -o ../../cli/build/migrate.linux-arm64 -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -o ../../cli/build/migrate.darwin-amd64 -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -a -o ../../cli/build/migrate.windows-386.exe -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -o ../../cli/build/migrate.windows-amd64.exe -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -o ../../cli/build/migrate.linux-amd64 -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build -a -o ../../cli/build/migrate.linux-armv7 -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -a -o ../../cli/build/migrate.linux-arm64 -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -a -o ../../cli/build/migrate.darwin-amd64 -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -a -o ../../cli/build/migrate.windows-386.exe -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cmd/migrate && CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -a -o ../../cli/build/migrate.windows-amd64.exe -ldflags='-X main.Version=$(VERSION) -extldflags "-static"' -tags '$(DATABASE) $(SOURCE)' .
cd ./cli/build && find . -name 'migrate*' | xargs -I{} tar czf {}.tar.gz {}
cd ./cli/build && shasum -a 256 * > sha256sum.txt
cat ./cli/build/sha256sum.txt
Expand Down
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[![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)
[![GoDoc](https://pkg.go.dev/badge/github.com/golang-migrate/migrate)](https://pkg.go.dev/github.com/golang-migrate/migrate/v4)
[![Coverage Status](https://img.shields.io/coveralls/github/golang-migrate/migrate/master.svg)](https://coveralls.io/github/golang-migrate/migrate?branch=master)
[![packagecloud.io](https://img.shields.io/badge/deb-packagecloud.io-844fec.svg)](https://packagecloud.io/golang-migrate/migrate?filter=debs)
[![Docker Pulls](https://img.shields.io/docker/pulls/migrate/migrate.svg)](https://hub.docker.com/r/migrate/migrate/)
![Supported Go Versions](https://img.shields.io/badge/Go-1.19%2C%201.20-lightgrey.svg)
[![GitHub Release](https://img.shields.io/github/release/golang-migrate/migrate.svg)](https://github.com/golang-migrate/migrate/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/golang-migrate/migrate/v4)](https://goreportcard.com/report/github.com/golang-migrate/migrate/v4)
# NOTE
# NOTE: This is a Kubecost internal fork of https://github.com/golang-migrate/migrate for implementing DuckDB migration support. If this project goes well and our internal fork is adopted, we should strongly consider contributed back to upstream.
# NOTE
# Forked on 2023-07-12

# migrate

Expand All @@ -28,11 +24,11 @@ Database drivers run migrations. [Add a new database?](database/driver.go)
* [PGX v5](database/pgx/v5)
* [Redshift](database/redshift)
* [Ql](database/ql)
* [Cassandra](database/cassandra)
* [Cassandra / ScyllaDB](database/cassandra)
* [SQLite](database/sqlite)
* [SQLite3](database/sqlite3) ([todo #165](https://github.com/mattes/migrate/issues/165))
* [SQLCipher](database/sqlcipher)
* [MySQL/ MariaDB](database/mysql)
* [MySQL / MariaDB](database/mysql)
* [Neo4j](database/neo4j)
* [MongoDB](database/mongodb)
* [CrateDB](database/crate) ([todo #170](https://github.com/mattes/migrate/issues/170))
Expand All @@ -43,6 +39,7 @@ Database drivers run migrations. [Add a new database?](database/driver.go)
* [ClickHouse](database/clickhouse)
* [Firebird](database/firebird)
* [MS SQL Server](database/sqlserver)
* [rqlite](database/rqlite)

### Database URLs

Expand Down Expand Up @@ -144,7 +141,7 @@ func main() {
m, err := migrate.NewWithDatabaseInstance(
"file:///migrations",
"postgres", driver)
m.Up() // or m.Step(2) if you want to explicitly set the number of migrations to run
m.Up() // or m.Steps(2) if you want to explicitly set the number of migrations to run
}
```

Expand Down Expand Up @@ -173,7 +170,7 @@ Each migration has an up and down migration. [Why?](FAQ.md#why-two-separate-file
## Coming from another db migration tool?

Check out [migradaptor](https://github.com/musinit/migradaptor/).
*Note: migradaptor is not affliated or supported by this project*
*Note: migradaptor is not affiliated or supported by this project*

## Versions

Expand Down
11 changes: 8 additions & 3 deletions database/cassandra/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Cassandra
# Cassandra / ScyllaDB

* Drop command will not work on Cassandra 2.X because it rely on
* `Drop()` method will not work on Cassandra 2.X because it rely on
system_schema table which comes with 3.X
* Other commands should work properly but are **not tested**
* Other methods should work properly but are **not tested**
* The Cassandra driver (gocql) does not natively support executing multiple statements in a single query. To allow for multiple statements in a single migration, you can use the `x-multi-statement` param. There are two important caveats:
* This mode splits the migration text into separately-executed statements by a semi-colon `;`. Thus `x-multi-statement` cannot be used when a statement in the migration contains a string with a semi-colon.
* The queries are not executed in any sort of transaction/batch, meaning you are responsible for fixing partial migrations.

**ScyllaDB**

* No additional configuration is required since it is a drop-in replacement for Cassandra.
* The `Drop()` method` works for ScyllaDB 5.1


## Usage
`cassandra://host:port/keyspace?param1=value&param2=value2`
Expand Down
18 changes: 17 additions & 1 deletion database/cassandra/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ var (
// Although Cassandra 2.x is supported by the Apache Foundation,
// the migrate db driver only supports Cassandra 3.x since it uses
// the system_schema keyspace.
// last ScyllaDB version tested is 5.1.11
specs = []dktesting.ContainerSpec{
{ImageName: "cassandra:3.0", Options: opts},
{ImageName: "cassandra:3.11", Options: opts},
{ImageName: "scylladb/scylla:5.1.11", Options: opts},
}
)

Expand Down Expand Up @@ -59,6 +61,20 @@ func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
}

func Test(t *testing.T) {
t.Run("test", test)
t.Run("testMigrate", testMigrate)

t.Cleanup(func() {
for _, spec := range specs {
t.Log("Cleaning up ", spec.ImageName)
if err := spec.Cleanup(); err != nil {
t.Error("Error removing ", spec.ImageName, "error:", err)
}
}
})
}

func test(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
ip, port, err := c.Port(9042)
if err != nil {
Expand All @@ -79,7 +95,7 @@ func Test(t *testing.T) {
})
}

func TestMigrate(t *testing.T) {
func testMigrate(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
ip, port, err := c.Port(9042)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion database/clickhouse/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

## Notes

* The Clickhouse driver does not natively support executing multipe statements in a single query. To allow for multiple statements in a single migration, you can use the `x-multi-statement` param. There are two important caveats:
* The Clickhouse driver does not natively support executing multiple statements in a single query. To allow for multiple statements in a single migration, you can use the `x-multi-statement` param. There are two important caveats:
* This mode splits the migration text into separately-executed statements by a semi-colon `;`. Thus `x-multi-statement` cannot be used when a statement in the migration contains a string with a semi-colon.
* The queries are not executed in any sort of transaction/batch, meaning you are responsible for fixing partial migrations.
* Using the default TinyLog table engine for the schema_versions table prevents backing up the table if using the [clickhouse-backup](https://github.com/AlexAkulov/clickhouse-backup) tool. If backing up the database with make sure the migrations are run with `x-migrations-table-engine=MergeTree`.
* Clickhouse cluster mode is not officially supported, since it's not tested right now, but you can try enabling `schema_migrations` table replication by specifying a `x-cluster-name`:
* When `x-cluster-name` is specified, `x-migrations-table-engine` also should be specified. See the docs regarding [replicated table engines](https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/replication/#table_engines-replication).
* When `x-cluster-name` is specified, only the `schema_migrations` table is replicated across the cluster. You still need to write your migrations so that the application tables are replicated within the cluster.
* If you want to create database inside the migration, you should know, that table which will manage migrations `schema-migrations table` will be in `default` table, so you can't use `USE <database_name>` inside migration. In this case you may not specify the database in the connection string (example you can find [here](examples/migrations/003_create_database.up.sql))
15 changes: 12 additions & 3 deletions database/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (ch *ClickHouse) ensureVersionTable() (err error) {

var (
table string
query = "SHOW TABLES FROM " + ch.config.DatabaseName + " LIKE '" + ch.config.MigrationsTable + "'"
query = "SHOW TABLES FROM " + quoteIdentifier(ch.config.DatabaseName) + " LIKE '" + ch.config.MigrationsTable + "'"
)
// check if migration table exists
if err := ch.conn.QueryRow(query).Scan(&table); err != nil {
Expand Down Expand Up @@ -259,7 +259,7 @@ func (ch *ClickHouse) ensureVersionTable() (err error) {
}

func (ch *ClickHouse) Drop() (err error) {
query := "SHOW TABLES FROM " + ch.config.DatabaseName
query := "SHOW TABLES FROM " + quoteIdentifier(ch.config.DatabaseName)
tables, err := ch.conn.Query(query)

if err != nil {
Expand All @@ -277,7 +277,7 @@ func (ch *ClickHouse) Drop() (err error) {
return err
}

query = "DROP TABLE IF EXISTS " + ch.config.DatabaseName + "." + table
query = "DROP TABLE IF EXISTS " + quoteIdentifier(ch.config.DatabaseName) + "." + quoteIdentifier(table)

if _, err := ch.conn.Exec(query); err != nil {
return &database.Error{OrigErr: err, Query: []byte(query)}
Expand Down Expand Up @@ -305,3 +305,12 @@ func (ch *ClickHouse) Unlock() error {
return nil
}
func (ch *ClickHouse) Close() error { return ch.conn.Close() }

// Copied from lib/pq implementation: https://github.com/lib/pq/blob/v1.9.0/conn.go#L1611
func quoteIdentifier(name string) string {
end := strings.IndexRune(name, 0)
if end > -1 {
name = name[:end]
}
return `"` + strings.Replace(name, `"`, `""`, -1) + `"`
}
Loading
Loading