Skip to content

Commit

Permalink
Update goose to 2.7.0, support clickhouse (#16)
Browse files Browse the repository at this point in the history
* Update goose to 2.7.0, support clickhouse
  • Loading branch information
chapsuk authored Feb 7, 2021
1 parent 2850494 commit f1ea9f9
Show file tree
Hide file tree
Showing 126 changed files with 8,061 additions and 281 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
- postgresql

before_install:
- docker run --rm=true -p 9000:9000 --name miga-clickhouse -e CLICKHOUSE_DB=miga -e CLICKHOUSE_USER=user -e CLICKHOUSE_PASSWORD=password -d yandex/clickhouse-server
- mysql -e "CREATE DATABASE miga;"
- mysql -e "CREATE USER user@localhost IDENTIFIED BY 'password'";
- mysql -e "GRANT ALL ON miga.* TO user@localhost";
Expand Down
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
NAME = miga
VERSION ?= v0.7.3
VERSION ?= v0.8.0
PG_CONTAINER_NAME = miga-pg
MYSQL_CONTAINER_NAME = miga-mysql
CLICKHOUSE_CONTAINER_NAME = miga-clickhouse
IMAGE_NAME = chapsuk/$(NAME)

TRAVIS_POSTGRES = postgres://postgres:@127.0.0.1:5432/miga?sslmode=disable
Expand All @@ -24,13 +25,13 @@ release: docker_build
.PHONY: test
test:
go clean -testcache
go test -v -race ./...
go test -mod=vendor -v -race ./...

.PHONY: db_up
db_up: postgres_up mysql_up
db_up: postgres_up mysql_up clickhouse_up

.PHONY: db_down
db_down: postgres_down mysql_down
db_down: postgres_down mysql_down clickhouse_down

.PHONY: postgres_up
postgres_up: postgres_down
Expand All @@ -55,6 +56,21 @@ mysql_up: mysql_down
-e MYSQL_ROOT_PASSWORD=mysql \
--name=$(MYSQL_CONTAINER_NAME) mysql:5.7

.PHONY: clickhouse_down
clickhouse_down:
-docker rm -f $(CLICKHOUSE_CONTAINER_NAME)

.PHONY: clickhouse_up
clickhouse_up: clickhouse_down
docker run -d \
-p 8123:8123 \
-p 9000:9000 \
-e CLICKHOUSE_DB=miga \
-e CLICKHOUSE_USER=user \
-e CLICKHOUSE_PASSWORD=password \
--name=$(CLICKHOUSE_CONTAINER_NAME) \
--ulimit nofile=262144:262144 yandex/clickhouse-server

.PHONY: mysql_down
mysql_down:
-docker rm -f $(MYSQL_CONTAINER_NAME)
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Aimed to add extra features and hide some limitations of existing golang migrati

## Supporting

PackageName | Version | Postgres | MySQL
----------- | ------- | ------------------- | --------
[goose](https://github.com/pressly/goose) | 2.6.0 | :heavy_check_mark: | :heavy_check_mark:
[migrate](https://github.com/golang-migrate/migrate) | 4.2.5 | :heavy_check_mark: | :heavy_check_mark:
[impg](https://github.com/im-kulikov/migrate) | 0.1 | :heavy_check_mark:
PackageName | Version | Postgres | MySQL | Clickhouse
----------- | ------- | ------------------- | -------- | --------
[goose](https://github.com/pressly/goose) | 2.7.0 (+ [patches](https://github.com/pressly/goose/compare/v2.7.0...chapsuk:clickhouse?expand=1)) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:
[migrate](https://github.com/golang-migrate/migrate) | 4.2.5 | :heavy_check_mark: | :heavy_check_mark: |
[impg](https://github.com/im-kulikov/migrate) | 0.1 | :heavy_check_mark: | |


## Features
Expand Down
1 change: 0 additions & 1 deletion commands/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ func DownTo(ctx *cli.Context, d driver.Interface) error {
if err != nil {
return err
}

return d.DownTo(version)
}
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func fillDBConfig(cfg *driver.Config) {
cfg.Dsn = viper.GetString("mysql.dsn")
return
}

if viper.IsSet("clickhouse.dsn") {
cfg.Dialect = "clickhouse"
cfg.Dsn = viper.GetString("clickhouse.dsn")
return
}
}

func dirExists(dir string) bool {
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ module miga

go 1.15

replace github.com/pressly/goose v2.7.0+incompatible => github.com/chapsuk/goose v2.1.1-0.20210207132231-8dfe4480e4dd+incompatible

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/ClickHouse/clickhouse-go v1.4.3
github.com/go-pg/pg v8.0.3+incompatible
github.com/go-sql-driver/mysql v1.4.1
github.com/golang-migrate/migrate/v4 v4.2.5
Expand All @@ -13,7 +16,7 @@ require (
github.com/onsi/ginkgo v1.15.0 // indirect
github.com/onsi/gomega v1.10.5 // indirect
github.com/pkg/errors v0.8.1
github.com/pressly/goose v2.6.0+incompatible
github.com/pressly/goose v2.7.0+incompatible
github.com/smartystreets/goconvey v1.6.4
github.com/spf13/viper v1.3.2
go.uber.org/atomic v1.3.2 // indirect
Expand Down
14 changes: 12 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7O
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/ClickHouse/clickhouse-go v1.4.3 h1:iAFMa2UrQdR5bHJ2/yaSLffZkxpcOYQMCUuKeNXGdqc=
github.com/ClickHouse/clickhouse-go v1.4.3/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
github.com/Microsoft/go-winio v0.4.11 h1:zoIOcVf0xPN1tnMVbTtEdI+P8OofVk3NObnwOQ6nK2Q=
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
Expand All @@ -16,8 +18,14 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
github.com/aws/aws-sdk-go v1.15.54/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
github.com/bkaradzic/go-lz4 v1.0.0 h1:RXc4wYsyz985CkXXeX04y4VnZFGG8Rd43pRaHsOXAKk=
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/chapsuk/goose v2.1.1-0.20210207132231-8dfe4480e4dd+incompatible h1:PqLx+VuytlOOJllLRZ+MwHR1Vpf0WzEm4/fuSPWfwoA=
github.com/chapsuk/goose v2.1.1-0.20210207132231-8dfe4480e4dd+incompatible/go.mod h1:Hxz/pZdYgssUl71fM7d6PFquTFm6QX39rxiui8J6UEA=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down Expand Up @@ -57,6 +65,7 @@ github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3I
github.com/go-ini/ini v1.39.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-pg/pg v8.0.3+incompatible h1:h+wfgh3nBdyTcYPQtK7GGnAFhVUGH33F9SEcMv5wbzI=
github.com/go-pg/pg v8.0.3+incompatible/go.mod h1:a2oXow+aFOrvwcKs3eIA0lNFmMilrxK2sOkB5NWe0vA=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
Expand Down Expand Up @@ -114,6 +123,7 @@ github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a h1:eeaG9XMUvRBYX
github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
Expand Down Expand Up @@ -153,13 +163,13 @@ github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zM
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pressly/goose v2.6.0+incompatible h1:3f8zIQ8rfgP9tyI0Hmcs2YNAqUCL1c+diLe3iU8Qd/k=
github.com/pressly/goose v2.6.0+incompatible/go.mod h1:m+QHWCqxR3k8D9l7qfzuC/djtlfzxr34mozWDYEu1z8=
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"gopkg.in/urfave/cli.v2"

_ "github.com/ClickHouse/clickhouse-go"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
)
Expand Down
3 changes: 3 additions & 0 deletions tests/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
func TestConvert(t *testing.T) {
for driverName, dialects := range drivers {
for _, dialect := range dialects {
if dialect == "clickhouse" {
continue
}
for tdriverName := range drivers {
if tdriverName == driverName {
continue
Expand Down
8 changes: 8 additions & 0 deletions tests/migrations/goose_clickhouse/00001_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- +goose Up
CREATE TABLE users (
id BIGINT,
name VARCHAR(128)
) engine=MergeTree() order by id;

-- +goose Down
DROP TABLE IF EXISTS users;
8 changes: 8 additions & 0 deletions tests/migrations/goose_clickhouse/00002_wallets.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- +goose Up
CREATE TABLE wallets (
id BIGINT,
user_id BIGINT
) engine=MergeTree() order by id;

-- +goose Down
DROP TABLE IF EXISTS wallets;
5 changes: 5 additions & 0 deletions tests/migrations/goose_clickhouse/00003_add_users_email.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +goose Up
ALTER TABLE users ADD COLUMN email VARCHAR(128);

-- +goose Down
ALTER TABLE users DROP COLUMN email;
5 changes: 5 additions & 0 deletions tests/migrations/goose_clickhouse/00101_wrong.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +goose Up
ALTER TABLE users ADD COLUMN email VARCHAR;

-- +goose Down
ALTER TABLE users DROP COLUMN IF EXISTS email;
7 changes: 7 additions & 0 deletions tests/migrations/goose_clickhouse/00102_never.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- +goose Up
CREATE TABLE never (
id INT
) engine=Memory;

-- +goose Down
DROP TABLE IF EXISTS never;
11 changes: 10 additions & 1 deletion tests/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"miga/driver"

_ "github.com/ClickHouse/clickhouse-go"
. "github.com/smartystreets/goconvey/convey"
)

Expand Down Expand Up @@ -97,6 +98,9 @@ var migrationCases = []testCase{
So(count, ShouldEqual, 1)
So(r.Err(), ShouldBeNil)
},
Condition: func(driverName, dialect string) bool {
return dialect != "clickhouse"
},
},
{
Description: "#6 plpsql statement, should create histories table and func for create inheritans",
Expand Down Expand Up @@ -277,11 +281,16 @@ func TestMigrations(t *testing.T) {
strings.ToUpper(dialect),
)
Convey(desc, t, func() {
dir := "./migrations/" + string(driverName)
if dialect == "clickhouse" {
dir += "_clickhouse"
}

driverInst, err := driver.New(&driver.Config{
Name: string(driverName),
Dialect: dialect,
Dsn: string(dsns[dialect]),
Dir: "./migrations/" + string(driverName),
Dir: dir,
VersionTableName: string(driverName) + "_db_version",
})
So(err, ShouldBeNil)
Expand Down
7 changes: 4 additions & 3 deletions tests/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ type (

var (
drivers = map[driverName]dialects{
"goose": []string{"mysql", "postgres"},
"goose": []string{"mysql", "postgres", "clickhouse"},
"migrate": []string{"mysql", "postgres"},
"impg": []string{"postgres"},
}

dsns = map[string]dsn{
"postgres": "postgres://user:password@127.0.0.1:5432/miga?sslmode=disable",
"mysql": "user:password@tcp(127.0.0.1:3306)/miga",
"postgres": "postgres://user:password@127.0.0.1:5432/miga?sslmode=disable",
"mysql": "user:password@tcp(127.0.0.1:3306)/miga",
"clickhouse": "tcp://127.0.0.1:9000?username=user&password=password&database=miga",
}
)
28 changes: 28 additions & 0 deletions vendor/github.com/ClickHouse/clickhouse-go/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/ClickHouse/clickhouse-go/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/ClickHouse/clickhouse-go/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/ClickHouse/clickhouse-go/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/ClickHouse/clickhouse-go/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f1ea9f9

Please sign in to comment.