Skip to content

Commit b4047a1

Browse files
authored
Merge pull request #617 from kaworu/pr/kaworu/database/clickhouse/honor-DefaultMigrationsTableEngine
clickhouse: honor `DefaultMigrationsTableEngine` when created `WithInstance()`
2 parents aef2747 + 9db2d01 commit b4047a1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

database/clickhouse/clickhouse.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func (ch *ClickHouse) init() error {
127127
ch.config.MultiStatementMaxSize = DefaultMultiStatementMaxSize
128128
}
129129

130+
if len(ch.config.MigrationsTableEngine) == 0 {
131+
ch.config.MigrationsTableEngine = DefaultMigrationsTableEngine
132+
}
133+
130134
return ch.ensureVersionTable()
131135
}
132136

database/clickhouse/clickhouse_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func TestCases(t *testing.T) {
7979
t.Run("Migrate_"+engine, func(t *testing.T) { testMigrate(t, engine) })
8080
t.Run("Version_"+engine, func(t *testing.T) { testVersion(t, engine) })
8181
t.Run("Drop_"+engine, func(t *testing.T) { testDrop(t, engine) })
82-
8382
}
83+
t.Run("WithInstanceDefaultConfigValues", func(t *testing.T) { testSimpleWithInstanceDefaultConfigValues(t) })
8484
}
8585

8686
func testSimple(t *testing.T, engine string) {
@@ -106,6 +106,33 @@ func testSimple(t *testing.T, engine string) {
106106
})
107107
}
108108

109+
func testSimpleWithInstanceDefaultConfigValues(t *testing.T) {
110+
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
111+
ip, port, err := c.Port(defaultPort)
112+
if err != nil {
113+
t.Fatal(err)
114+
}
115+
116+
addr := clickhouseConnectionString(ip, port, "")
117+
conn, err := sql.Open("clickhouse", addr)
118+
if err != nil {
119+
t.Fatal(err)
120+
}
121+
d, err := clickhouse.WithInstance(conn, &clickhouse.Config{})
122+
if err != nil {
123+
_ = conn.Close()
124+
t.Fatal(err)
125+
}
126+
defer func() {
127+
if err := d.Close(); err != nil {
128+
t.Error(err)
129+
}
130+
}()
131+
132+
dt.Test(t, d, []byte("SELECT 1"))
133+
})
134+
}
135+
109136
func testMigrate(t *testing.T, engine string) {
110137
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
111138
ip, port, err := c.Port(defaultPort)

0 commit comments

Comments
 (0)