Skip to content

Commit

Permalink
#13 clickhouse cluster (#17)
Browse files Browse the repository at this point in the history
* #13 clickhouse cluster support
  • Loading branch information
raoptimus authored Apr 11, 2021
1 parent 6cbaf5d commit 9ba245c
Show file tree
Hide file tree
Showing 15 changed files with 1,440 additions and 29 deletions.
7 changes: 6 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ POSTGRES_PASSWORD=docker
POSTGRES_DSN=postgres://docker:docker@postgres:5432/docker?sslmode=disable
POSTGRES_MIGRATIONS_PATH=./db/postgresMigration/test_migrates

CLICKHOUSE_DSN=clickhouse://default:@clickhouse:9000/docker?sslmode=disable&compress=true&debug=false&cluster=test_cluster
CLICKHOUSE_DSN=clickhouse://default:@clickhouse:9000/docker?sslmode=disable&compress=true&debug=false
CLICKHOUSE_MIGRATIONS_PATH=./db/clickhouseMigration/test_migrates

CLICKHOUSE_CLUSTER_DSN1=clickhouse://default:@clickhouse1:9000/docker?sslmode=disable&compress=true&debug=false
CLICKHOUSE_CLUSTER_DSN2=clickhouse://default:@clickhouse2:9000/docker?sslmode=disable&compress=true&debug=false
CLICKHOUSE_CLUSTER_NAME=test_cluster
CLICKHOUSE_CLUSTER_MIGRATIONS_PATH=./db/clickhouseMigration/test_cluster_migrates
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Note that the directory must exist, or the command may trigger an error.
- `migrationTable` or `t`: string (defaults to migration), specifies the name of the database table for storing migration history information.
The table will be automatically created by the command if it does not exist.
You may also manually create it using the structure version varchar(255) primary key, apply_time integer.
- `migrationClusterName` or `cn`: string (defaults to empty), specifies the name of the database cluster name for storing migration history information.
The table will be automatically created in cluster by the command if it does not exist.
It uses only for clickhouse
- `dsn` or `d`: string (defaults to empty), Database connection strings are specified via URLs.
The URL format is driver dependent but generally has the form: driver://username:password@host:port/dbname?option1=true.
- `compact` or `c`: boolean (defaults to false), output in compact mode
Expand All @@ -94,6 +97,7 @@ The URL format is driver dependent but generally has the form: driver://username
DSN=clickhouse://default:@localhost:9000/docker?sslmode=disable&compress=true&debug=false
MIGRATION_PATH=./migrations
MIGRATION_TABLE=migration
MIGRATION_CLUSTER_NAME=test_cluster
COMPACT=true
INTERACTIVE=false
```
Expand All @@ -110,13 +114,14 @@ go get -u -d github.com/raoptimus/db-migrator.go/cmd/db-migrator
```
The custom version:
```
go get -u -d github.com/raoptimus/db-migrator.go/cmd/db-migrator@0.0.5
go get -u -d github.com/raoptimus/db-migrator.go/cmd/db-migrator@0.1.1
```

#### With docker
```
docker pull raoptimus/db-migrator
docker pull raoptimus/db-migrator:latest
```
See [https://hub.docker.com/r/raoptimus/db-migrator](https://hub.docker.com/r/raoptimus/db-migrator)

### Example
```
Expand Down
8 changes: 8 additions & 0 deletions cmd/db-migrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ func main() {
Value: "migration",
Usage: "Table name for history of migrates",
},
&cli.StringFlag{
Name: "migrationClusterName",
EnvVars: []string{"MIGRATION_CLUSTER_NAME"},
Aliases: []string{"cn"},
Value: "migration",
Usage: "Cluster name for history of migrates",
},
&cli.BoolFlag{
Name: "compact",
EnvVars: []string{"COMPACT"},
Expand Down Expand Up @@ -137,6 +144,7 @@ func before(c *cli.Context) error {
DSN: c.String("dsn"),
Directory: c.String("migrationPath"),
TableName: c.String("migrationTable"),
ClusterName: c.String("migrationClusterName"),
Compact: c.Bool("compact"),
Interactive: c.Bool("interactive"),
})
Expand Down
29 changes: 24 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"

services:
clickhouse:
image: yandex/clickhouse-server:20.6.5.8
image: yandex/clickhouse-server:20.9.2.20
volumes:
- "./docker/volume/clickhouse/dump:/docker-entrypoint-initdb.d/"

Expand All @@ -12,17 +12,36 @@ services:
- .env

app:
# image: golang:1.15.1-alpine3.12
image: raoptimus/go-magick:latest
working_dir: "/usr/src/app"
command: "sleep infinity"
depends_on:
- clickhouse
- postgres
links:
- clickhouse
- clickhouse1
- clickhouse2
- postgres
volumes:
- "./:/usr/src/app"
env_file:
- .env

zookeeper:
image: zookeeper

clickhouse1:
image: yandex/clickhouse-server:20.9.2.20
volumes:
- "./docker/volume/clickhouse-cluster/dump:/docker-entrypoint-initdb.d/"
- "./docker/volume/clickhouse-cluster/config/config_1.xml:/etc/clickhouse-server/config.xml"
- "./docker/volume/clickhouse-cluster/config/config_replica.xml:/etc/clickhouse-server/clickhouse_replication_config.xml"
depends_on:
- zookeeper

clickhouse2:
image: yandex/clickhouse-server:20.9.2.20
volumes:
- "./docker/volume/clickhouse-cluster/dump:/docker-entrypoint-initdb.d/"
- "./docker/volume/clickhouse-cluster/config/config_2.xml:/etc/clickhouse-server/config.xml"
- "./docker/volume/clickhouse-cluster/config/config_replica.xml:/etc/clickhouse-server/clickhouse_replication_config.xml"
depends_on:
- zookeeper
2 changes: 1 addition & 1 deletion docker/image/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.16-alpine as build
FROM golang:1.16-alpine3.12 as build

RUN apk add --update make git bash file

Expand Down
Loading

0 comments on commit 9ba245c

Please sign in to comment.