Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#36 multiple insert query does not work to clickhouse #37

Merged
merged 6 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 3 additions & 5 deletions .env
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
GO_IMAGE_VERSION="1.22"
GO_LINT_VERSION="1.55.2"
POSTGRES_DB=docker
POSTGRES_USER=docker
POSTGRES_PASSWORD=docker
POSTGRES_DSN=postgres://docker:docker@postgres:5432/docker?sslmode=disable
POSTGRES_MIGRATIONS_PATH=./fixtures/postgres

CLICKHOUSE_DSN=clickhouse://default:@clickhouse:9000/docker?sslmode=disable&compress=true&debug=false
CLICKHOUSE_DSN=clickhouse://default:@clickhouse:9000/default?compress=true&debug=false
CLICKHOUSE_MIGRATIONS_PATH=./fixtures/clickhouse
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_DSN1=clickhouse://default:@clickhouse1:9000,clickhouse2:9000/default?compress=true&debug=false
CLICKHOUSE_CLUSTER_DSN2=clickhouse://default:@clickhouse2:9000/default?compress=true&debug=false
CLICKHOUSE_CLUSTER_NAME=test_cluster
CLICKHOUSE_CLUSTER_MIGRATIONS_PATH=./fixtures/clickhouse_cluster

Expand Down
55 changes: 9 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Test

on:
push:
on: [push]

jobs:
docker:
Expand All @@ -10,54 +9,18 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
#
# - name: Cache go mods
# uses: actions/cache@v3
# with:
# path: |
# ~/.cache/go-build
# ~/go/pkg/mod
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
uses: actions/checkout@v4

- name: Pull containers
run: docker-compose -f "docker-compose.yml" pull

- name: Start containers
run: docker-compose -f "docker-compose.yml" up -d --build

- name: Run ps
run: docker-compose -f "docker-compose.yml" ps

- name: Run logs
run: docker-compose -f "docker-compose.yml" logs
- name: Run docker-compose
uses: hoverkraft-tech/[email protected]
with:
compose-file: "./docker-compose.yml"

- name: Run lint
run: docker-compose -f "docker-compose.yml" exec -T app make lint
run: docker compose exec -T app make lint

- name: Run unit tests
run: docker-compose -f "docker-compose.yml" exec -T app make test-unit

- name: Sleep for 10 seconds
uses: jakejarvis/wait-action@master
with:
time: '10s'
run: docker compose exec -T app make test-unit

- name: Run integration tests
run: docker-compose -f "docker-compose.yml" exec -T app make test-integration

# - name: Publish Test Report
# uses: mikepenz/action-junit-report@v4
# if: success() || failure()
# with:
# report_paths: '**/.report/*.xml'

# - name: Test & publish code coverage
# uses: paambaati/[email protected]
# with:
# coverageLocations: |
# ${{github.workspace}}/.report/*.json:cobertura

- name: Stop containers
if: always()
run: docker-compose -f "docker-compose.yml" down
run: docker compose exec -T app make test-integration
56 changes: 11 additions & 45 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,6 @@ run:
# include test files or not, default is true
tests: false

# list of build tags, all linters use it. Default is empty list.
# build-tags:
# - mytag

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-dirs:
- doc
- docker

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
- \.pb\.go$
- \.pb\.gw\.go$

# - ".*\\.my\\.go$"
# - lib/bad.go

# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand Down Expand Up @@ -72,13 +41,13 @@ linters:
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error.
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- exportloopref # checks for pointers to enclosing loop variables
- copyloopvar # checks for pointers to enclosing loop variables
- forcetypeassert # finds forced type assertions
- goconst # Finds repeated strings that could be replaced by a constant
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt.
- goerr113 # Golang linter to check the errors handling expressions
- gomnd # An analyzer to detect magic numbers.
- err113 # Golang linter to check the errors handling expressions
- mnd # An analyzer to detect magic numbers.
- gosec # Inspects source code for security problems
- ireturn # Accept Interfaces, Return Concrete Types
- importas # Enforces consistent import aliases
Expand Down Expand Up @@ -107,7 +76,6 @@ linters:
- decorder # check declaration order and count of types, constants, variables and functions
- depguard # Go linter that checks if package imports are in a list of acceptable packages
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
- exhaustive # check exhaustiveness of enum switch statements
- exhaustruct # Checks if all structure fields are initialized
- forbidigo # Forbids identifiers
Expand Down Expand Up @@ -149,10 +117,6 @@ linters:
- wsl # Whitespace Linter - Forces you to use empty lines!

output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
# default is "colored-line-number"
format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: false

Expand All @@ -170,11 +134,6 @@ output:

# all available settings of specific linters
linters-settings:
govet:
check-shadowing: true

golint:
min-confidence: 0

dupl:
threshold: 100
Expand Down Expand Up @@ -211,10 +170,17 @@ linters-settings:

issues:
exclude-use-default: true
exclude-dirs-use-default: true
exclude-dirs:
- doc
- docker
exclude-files:
- \.pb\.go$
- \.pb\.gw\.go$
exclude-rules:
- linters:
- govet
text: "declaration of \"err\" shadows declaration"
- linters:
- goerr113
- err113
text: "do not define dynamic errors, use wrapped static errors instead"
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG GO_IMAGE_VERSION
FROM golang:${GO_IMAGE_VERSION}-alpine
FROM golang:1.23-alpine
RUN apk add --no-cache \
tzdata \
ca-certificates \
Expand All @@ -16,8 +15,7 @@ RUN export BINDIR=/go/bin \
#RUN go install github.com/boumenot/gocover-cobertura@latest \
# && go install github.com/jstemmer/go-junit-report@latest

ARG GO_LINT_VERSION
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v${GO_LINT_VERSION}
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.62.2

RUN go env -w GOFLAGS=-buildvcs=false && \
go env -w CGO_ENABLED=0
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ version:
@echo "GIT_COMMIT: ${GIT_COMMIT}"

build-docker-image: ## Build docker image
@docker login -u "${DOCKER_ID_USER}" -p "${DOCKER_PASS}" docker.io
@#docker login -u "${DOCKER_ID_USER}" -p "${DOCKER_PASS}" docker.io
@docker build \
--platform linux/x86_64 \
--build-arg VERSION=${VERSION} \
Expand Down Expand Up @@ -123,3 +123,6 @@ gen-mocks-dry-run: install-mockery ## Run mockery --dry-run=true
mockery --srcpkg=$${d} --output=$${d}/mock$$(basename -- "$${d/./''}") --all --dry-run=true; \
done; \
'

start:
@docker-compose -f "docker-compose.yml" -f "docker-compose.dev.yml" up -d
5 changes: 5 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
clickhouse1:
ports:
- 9000:9000
- 8123:8123
6 changes: 0 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.7"

services:
clickhouse:
image: clickhouse/clickhouse-server:23.11-alpine
Expand All @@ -22,9 +20,6 @@ services:
build:
context: ./
dockerfile: Dockerfile
args:
GO_IMAGE_VERSION: ${GO_IMAGE_VERSION}
GO_LINT_VERSION: ${GO_LINT_VERSION}
working_dir: "/usr/src/app"
command: "sleep infinity"
depends_on:
Expand Down Expand Up @@ -56,7 +51,6 @@ services:
image: clickhouse/clickhouse-server:23.11-alpine
restart: on-failure
volumes:
- "./docker/volume/clickhouse-cluster/dump:/docker-entrypoint-initdb.d/"
- "./docker/volume/clickhouse-cluster/config/clickhouse1:/etc/clickhouse-server/config.d/"
depends_on:
- clickhouse-keeper
Expand Down
6 changes: 4 additions & 2 deletions docker/image/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG GO_IMAGE_VERSION
FROM golang:${GO_IMAGE_VERSION}-alpine as build
FROM golang:1.23-alpine as build

RUN apk add --update make bash file

Expand All @@ -18,5 +17,8 @@ RUN make build

FROM alpine:latest AS db-migrator

RUN apk add --no-cache tzdata ca-certificates
ENV TZ UTC

WORKDIR /usr/bin
COPY --from=build /go/src/db-migrator/.build .
1 change: 0 additions & 1 deletion docker/volume/clickhouse-cluster/dump/init.sql

This file was deleted.

1 change: 0 additions & 1 deletion docker/volume/clickhouse/dump/init.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ALTER TABLE test DROP COLUMN text;
ALTER TABLE test ON CLUSTER test_cluster
DROP COLUMN text;

Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ALTER TABLE test ADD COLUMN text String;
ALTER TABLE test ON CLUSTER test_cluster
ADD COLUMN text String;

INSERT INTO test (value, text) VALUES (1, 'Hello');
Original file line number Diff line number Diff line change
@@ -1 +1 @@
insert into test2 values (time) values (now());
INSERT INTO test2 (time) VALUES (now());
27 changes: 20 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
module github.com/raoptimus/db-migrator.go

go 1.22
go 1.23

require (
github.com/ClickHouse/clickhouse-go v1.5.4
github.com/ClickHouse/clickhouse-go/v2 v2.30.0
github.com/go-sql-driver/mysql v1.8.1
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
github.com/raoptimus/db-migrator.go/pkg/console v0.0.0-20240503100150-5445e535daaf
github.com/raoptimus/db-migrator.go/pkg/iohelp v0.0.0-20240503100150-5445e535daaf
github.com/raoptimus/db-migrator.go/pkg/sqlio v0.0.0-20240503100150-5445e535daaf
github.com/raoptimus/db-migrator.go/pkg/timex v0.0.0-20240503100150-5445e535daaf
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.2
github.com/stretchr/testify v1.10.0
github.com/urfave/cli/v2 v2.27.5
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/ClickHouse/ch-go v0.63.1 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.7.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/paulmach/orb v0.11.1 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
golang.org/x/sys v0.27.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading