Skip to content

Commit

Permalink
Merge pull request #16 from DIMO-Network/as-2994-update-nameindexer-t…
Browse files Browse the repository at this point in the history
…o-use-cloudevent-headers

Add migration command remove global register func.
  • Loading branch information
KevinJoiner authored Oct 15, 2024
2 parents b9f4401 + f0f554a commit 2c0ddc4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: golangci-lint
on:
pull_request:
branches: [ '**' ]
env:
GOPRIVATE: github.com/DIMO-Network
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
golangci:
runs-on: self-hosted
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ VERSION := $(shell git describe --tags || echo "v0.0.0")
VER_CUT := $(shell echo $(VERSION) | cut -c2-)

# Dependency versions
GOLANGCI_VERSION = v1.56.2
GOLANGCI_VERSION = latest

help:
@echo "\nSpecify a subcommand:\n"
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module github.com/DIMO-Network/clickhouse-infra

go 1.22.0
go 1.22.8

toolchain go1.23.2

require (
github.com/ClickHouse/clickhouse-go/v2 v2.29.0
github.com/DIMO-Network/model-garage v0.3.1
github.com/docker/go-connections v0.5.0
github.com/mdelapenya/tlscert v0.1.0
github.com/pressly/goose/v3 v3.22.1
Expand All @@ -14,7 +17,7 @@ require (
)

require (
dario.cat/mergo v1.0.0 // indirect
dario.cat/mergo v1.0.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/ClickHouse/ch-go v0.61.5 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
Expand All @@ -34,6 +37,7 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down Expand Up @@ -62,10 +66,8 @@ require (
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect
Expand Down
11 changes: 7 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
Expand All @@ -8,6 +8,8 @@ github.com/ClickHouse/ch-go v0.61.5 h1:zwR8QbYI0tsMiEcze/uIMK+Tz1D3XZXLdNrlaOpeE
github.com/ClickHouse/ch-go v0.61.5/go.mod h1:s1LJW/F/LcFs5HJnuogFMta50kKDO0lf9zzfrbl0RQg=
github.com/ClickHouse/clickhouse-go/v2 v2.29.0 h1:Dj1w59RssRyLgGHXtYaWU0eIM1pJsu9nGPi/btmvAqw=
github.com/ClickHouse/clickhouse-go/v2 v2.29.0/go.mod h1:bLookq6qZJ4Ush/6tOAnJGh1Sf3Sa/nQoMn71p7ZCUE=
github.com/DIMO-Network/model-garage v0.3.1 h1:1DBRKAL7drOicSuYzj5qKMytYKJ5GJcsKJQggmdybyI=
github.com/DIMO-Network/model-garage v0.3.1/go.mod h1:7lZc6XMwz699tSJwkBev3GZhVsOBtOWOBLTndrSj36o=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
Expand Down Expand Up @@ -121,8 +123,8 @@ github.com/pressly/goose/v3 v3.22.1 h1:2zICEfr1O3yTP9BRZMGPj7qFxQ+ik6yeo+z1LMuio
github.com/pressly/goose/v3 v3.22.1/go.mod h1:xtMpbstWyCpyH+0cxLTMCENWBG+0CSxvTsXhW95d5eo=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
Expand Down Expand Up @@ -242,6 +244,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e h1:Ao9GzfUMPH3zjVfzXG5rlWlk+Q8MXWKwWpwVQE1MXfw=
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4=
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc=
Expand Down
1 change: 0 additions & 1 deletion internal/codegen/migration.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ func init() {
_, filename, _, _ := runtime.Caller(0)
registerFunc := func() { goose.AddNamedMigrationContext(filename, up{{ .FuncName }}, down{{ .FuncName }}) }
registerFuncs = append(registerFuncs, registerFunc)
registerFunc()
}

func up{{ .FuncName }}(ctx context.Context, tx *sql.Tx) error {
Expand Down
28 changes: 28 additions & 0 deletions pkg/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"database/sql"
"embed"
"fmt"
"os"
"sync"

"github.com/ClickHouse/clickhouse-go/v2"
"github.com/pressly/goose/v3"
)

Expand Down Expand Up @@ -51,3 +53,29 @@ func RunGoose(ctx context.Context, gooseArgs []string, registerFuncs []func(), d
}
return nil
}

// RunGooseCmd parses cmdline arguments and runs the goose command using the provided registerFuncs.
func RunGooseCmd(ctx context.Context, registerFuncs []func()) error {
args := os.Args

if len(args) < 2 {
return fmt.Errorf("usage: %s <dbstring> <command> [args]", args[0])
}

dbstring := args[1]
dbOptions, err := clickhouse.ParseDSN(dbstring)
if err != nil {
return fmt.Errorf("failed to parse DSN: %w", err)
}
sqlDB := clickhouse.OpenDB(dbOptions)

err = RunGoose(ctx, args[2:], registerFuncs, sqlDB)
if err != nil {
_ = sqlDB.Close()
return fmt.Errorf("failed to run goose command: %w", err)
}
if err := sqlDB.Close(); err != nil {
return fmt.Errorf("failed to close db: %w", err)
}
return nil
}

0 comments on commit 2c0ddc4

Please sign in to comment.