Skip to content

Commit

Permalink
CH replicated dialect from config
Browse files Browse the repository at this point in the history
  • Loading branch information
chapsuk committed Jan 29, 2023
1 parent 77b4b87 commit d1ca637
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ func fillDBConfig(cfg *driver.Config) {
return
}

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

if viper.IsSet("vertica.dsn") {
cfg.Dialect = "vertica"
cfg.Dsn = viper.GetString("vertica.dsn")
Expand Down
7 changes: 3 additions & 4 deletions driver/goose/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
type Goose struct {
db *sql.DB
dir string
dialect string
versionTableName string
}

Expand All @@ -23,19 +22,19 @@ func New(dialect, dsn, tableName, dir string) (*Goose, error) {
orig.SetTableName(tableName)
orig.SetLogger(&utils.StdLogger{})

driverName := dialect
if dialect == "clickhouse-replicated" {
dialect = "clickhouse"
driverName = "clickhouse"
}

db, err := sql.Open(dialect, dsn)
db, err := sql.Open(driverName, dsn)
if err != nil {
return nil, err
}

return &Goose{
db: db,
dir: dir,
dialect: dialect,
versionTableName: tableName,
}, nil
}
Expand Down

0 comments on commit d1ca637

Please sign in to comment.