Skip to content
Open
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
25 changes: 25 additions & 0 deletions .circleci/build-canary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

set -e +o pipefail

if [[ -z $CIRCLE_PULL_REQUEST ]]; then
echo "Skipping canary build. Not a Pull Request"
exit 0
fi

echo CIRCLE_PULL_REQUEST=$CIRCLE_PULL_REQUEST
CIRCLE_PR_NUMBER=$(echo $CIRCLE_PULL_REQUEST | awk -F/ '{print $NF}')
echo CIRCLE_PR_NUMBER=$CIRCLE_PR_NUMBER

labels=$(curl -H "Authorization: token ${GITHUB_API_TOKEN}" -X GET https://api.github.com/repos/${GITHUB_REPO}/pulls/${CIRCLE_PR_NUMBER} | jq -r '.labels[].name')

if [[ $(echo $labels | grep $CANARY_LABEL | wc -l) -eq 1 ]]; then
export VERSION=canary-pr-${CIRCLE_PR_NUMBER}-$(git describe --tags --always)
echo "Building canary image $VERSION"
bash .circleci/docker.sh
curl -X POST -H "Authorization: token ${GITHUB_API_TOKEN}" \
-d "{\"body\": \"Docker image **${DOCKER_REPO}:${VERSION}** is now ready for deployment!\"}" \
https://api.github.com/repos/${GITHUB_REPO}/issues/${CIRCLE_PR_NUMBER}/comments
else
echo "Canary build skipped."
fi
94 changes: 94 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: 2.1
jobs:
build:
docker:
- image: eu.gcr.io/fraudshield-207318/circle-golang:latest
auth:
username: _json_key
password: $GCLOUD_SERVICE_KEY
- image: eu.gcr.io/fraudshield-207318/clickhouse-server:latest
auth:
username: _json_key
password: $GCLOUD_SERVICE_KEY
environment:
- LOG_LEVEL: error
environment:
TEST_RESULTS: /tmp/test-results # path to where test results will be saved
steps:
- run:
name: Git setup
command: |
# use http api token to fetch private repos
git config --global url."https://${GITHUB_API_TOKEN}:x-oauth-basic@github.com/24metrics".insteadOf "https://github.com/24metrics"

- checkout

- run: mkdir -p $TEST_RESULTS # create the test results directory

- restore_cache:
name: Restore dependencies cache
keys:
- go-mod-v4-{{ checksum "go.sum" }}

- run:
name: Download Dependencies
command: |
make dep

- run:
name: Go Build
command: |
VERSION=${CIRCLE_TAG:-${CIRCLE_BRANCH}-$(git describe --tags --always)}
echo Version is $VERSION
echo $VERSION > VERSION.txt
go test -v ./...
make dist

- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
- '/go/pkg/mod'

- store_artifacts: # upload test summary for display in Artifacts
path: /tmp/test-results
destination: raw-test-output

- store_test_results: # upload test results for display in Test Summary
path: /tmp/test-results

- persist_to_workspace:
root: /home/circleci/project # the default working directory
paths:
- .

publish-github-release:
docker:
- image: circleci/golang
steps:
- attach_workspace:
at: ./
- run:
name: "Publish Release on GitHub"
command: |
go install github.com/tcnksm/ghr@latest
export VERSION=$(cat VERSION.txt)
ghr -t ${GITHUB_API_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./bin/

workflows:
pipeline:
jobs:
- build:
context: clickshield-vars
filters:
tags:
only: /^v\d+\.\d+\.\d.*/
- publish-github-release:
context: clickshield-vars
requires:
- build
filters:
branches:
only:
- master
tags:
only: /^v\d+\.\d+\.\d.*/
17 changes: 17 additions & 0 deletions .circleci/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e +o pipefail

if [[ -z $DOCKER_FILE ]]; then
echo "DOCKER_FILE env is not set"
exit 1
fi

docker login -u _json_key -p "${GCLOUD_SERVICE_KEY}" eu.gcr.io
docker build -t ${DOCKER_REPO}:${VERSION} -f ${DOCKER_FILE} .
docker push ${DOCKER_REPO}:${VERSION}
docker tag ${DOCKER_REPO}:${VERSION} ${DOCKER_REPO}:latest
docker push ${DOCKER_REPO}:latest

curl -X POST -H 'Content-type: application/json' \
-d "{\"text\":\":docker: Docker image ${DOCKER_REPO}:${VERSION} is now ready for deployment! Check the <$CIRCLE_BUILD_URL|build status>.\"}" $SLACK_WEBHOOK
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
cmd/goose/goose*
*.swp
*.test
*.db
bin/
goose
custom-goose
15 changes: 0 additions & 15 deletions Gopkg.toml

This file was deleted.

13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
dep:
go mod tidy
go mod download

build-local:
CGO_ENABLED=0 go build -o ./bin/goose-local ./cmd/goose

dist:
@mkdir -p ./bin
@rm -f ./bin/*
GOOS=darwin GOARCH=amd64 go build -o ./bin/goose-darwin64 ./cmd/goose
GOOS=linux GOARCH=amd64 go build -o ./bin/goose-linux64 ./cmd/goose
GOOS=linux GOARCH=386 go build -o ./bin/goose-linux386 ./cmd/goose
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./bin/goose-darwin64 ./cmd/goose
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/goose-linux64 ./cmd/goose
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o ./bin/goose-linux386 ./cmd/goose

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Goose is a database migration tool. Manage your database schema by creating incr

# Install

$ go get -u github.com/pressly/goose/cmd/goose
$ go get -u github.com/24metrics/goose/cmd/goose

This will install the `goose` binary to your `$GOPATH/bin` directory.

Expand Down
14 changes: 7 additions & 7 deletions clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"strings"
"testing"

_ "github.com/kshvakov/clickhouse"
_ "github.com/ClickHouse/clickhouse-go/v2"
"github.com/stretchr/testify/assert"
)

func TestClickHouseDialect(t *testing.T) {
out, err := exec.Command("go", strings.Fields("build -i -o ./cmd/goose/goose ./cmd/goose")...).CombinedOutput()
out, err := exec.Command("go", strings.Fields("build -o ./cmd/goose/goose ./cmd/goose")...).CombinedOutput()
if !assert.NoError(t, err, string(out)) {
return
}
Expand All @@ -26,11 +26,11 @@ func TestClickHouseDialect(t *testing.T) {

row := connect.QueryRow("SELECT COUNT() FROM system.tables WHERE database = 'goose_test' AND name = 'goose_db_version'")
var count int
if err := row.Scan(&count); !assert.Equal(t, sql.ErrNoRows, err) {
if err := row.Scan(&count); !assert.Equal(t, nil, err) {
return
}
{
out, err := exec.Command("./cmd/goose/goose", strings.Fields(`clickhouse native://127.0.0.1:9000?debug=true&database=goose_test status`)...).CombinedOutput()
out, err := exec.Command("./cmd/goose/goose", strings.Fields(`clickhouse native://127.0.0.1:9000/goose_test?debug=true status`)...).CombinedOutput()
if !assert.NoError(t, err, string(out)) {
return
}
Expand All @@ -57,7 +57,7 @@ func TestClickHouseDialect(t *testing.T) {
return
}
{
out, err := exec.Command("./cmd/goose/goose", strings.Fields(`-dir examples/sql-migrations/clickhouse clickhouse native://127.0.0.1:9000?debug=true&database=goose_test up`)...).CombinedOutput()
out, err := exec.Command("./cmd/goose/goose", strings.Fields(`-dir examples/sql-migrations/clickhouse clickhouse native://127.0.0.1:9000/goose_test?debug=true up`)...).CombinedOutput()
if !assert.NoError(t, err, string(out)) {
return
}
Expand All @@ -84,7 +84,7 @@ func TestClickHouseDialect(t *testing.T) {
return
}
{
out, err := exec.Command("./cmd/goose/goose", strings.Fields(`-dir examples/sql-migrations/clickhouse clickhouse native://127.0.0.1:9000?debug=true&database=goose_test down`)...).CombinedOutput()
out, err := exec.Command("./cmd/goose/goose", strings.Fields(`-dir examples/sql-migrations/clickhouse clickhouse native://127.0.0.1:9000/goose_test?debug=true down`)...).CombinedOutput()
if !assert.NoError(t, err, string(out)) {
return
}
Expand All @@ -96,7 +96,7 @@ func TestClickHouseDialect(t *testing.T) {
return
}

if err := connect.QueryRow("SELECT COUNT() FROM system.columns WHERE database = 'goose_test' AND table = 'events' AND name = 'CreatedAt'").Scan(&countOfColumns); !assert.Equal(t, sql.ErrNoRows, err) {
if err := connect.QueryRow("SELECT COUNT() FROM system.columns WHERE database = 'goose_test' AND table = 'events' AND name = 'CreatedAt'").Scan(&countOfColumns); !assert.Equal(t, nil, err) {
return
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/goose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"log"
"os"

"github.com/pressly/goose"
"github.com/24metrics/goose"
// Init DB drivers.
_ "github.com/ClickHouse/clickhouse-go/v2"
_ "github.com/go-sql-driver/mysql"
_ "github.com/kshvakov/clickhouse"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
_ "github.com/ziutek/mymysql/godrv"
Expand Down Expand Up @@ -105,7 +105,7 @@ Examples:
goose postgres "user=postgres dbname=postgres sslmode=disable" status
goose mysql "user:password@/dbname?parseTime=true" status
goose redshift "postgres://user:password@qwerty.us-east-1.redshift.amazonaws.com:5439/db" status
goose clickhouse "native://127.0.0.1:9000?username=user&password=password&database=dbname" status
goose clickhouse "native://127.0.0.1:9000/goose_test?username=user&password=password" status

Options:
`
Expand Down
3 changes: 2 additions & 1 deletion dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ func (ClickHouseDialect) createVersionTableSQL() string {
is_applied UInt8,
date Date default today(),
tstamp DateTime default now()
) Engine = MergeTree(date, (date), 8192)
) Engine = MergeTree
ORDER BY (date)
`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ CREATE TABLE IF NOT EXISTS events (
EventDate Date,
EventTime DateTime,
OsID UInt8
) Engine=MergeTree(EventDate, (EventDate), 8192);
) Engine=MergeTree
ORDER BY (EventDate);

-- +goose Down
DROP TABLE events;
DROP TABLE events;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- +goose Up
ALTER TABLE events ADD COLUMN CreatedAt DateTime default now();
-- +goose Down
ALTER TABLE events DROP COLUMN CreatedAt;
ALTER TABLE events DROP COLUMN CreatedAt;
20 changes: 20 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/24metrics/goose

go 1.16

require (
github.com/ClickHouse/ch-go v0.61.1 // indirect
github.com/ClickHouse/clickhouse-go/v2 v2.17.1
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/google/uuid v1.6.0 // indirect
github.com/lib/pq v1.2.1-0.20190813065522-78223426e7c6
github.com/mattn/go-sqlite3 v1.14.14
github.com/paulmach/orb v0.11.0 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pressly/goose v2.6.0+incompatible
github.com/stretchr/testify v1.8.4
github.com/ziutek/mymysql v1.5.4
go.opentelemetry.io/otel v1.22.0 // indirect
golang.org/x/sys v0.16.0 // indirect
)
Loading