Skip to content

Commit

Permalink
Fix create db and upgrade clickhouse-server to v22.8 (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
farbodsalimi authored Jan 31, 2023
1 parent f3bc9f5 commit 3a9a4f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ services:
POSTGRES_PASSWORD: postgres

clickhouse:
image: yandex/clickhouse-server:19.16
image: clickhouse/clickhouse-server:22.8
2 changes: 1 addition & 1 deletion pkg/driver/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (drv *Driver) DropDatabase() error {
func (drv *Driver) schemaDump(db *sql.DB, buf *bytes.Buffer, databaseName string) error {
buf.WriteString("\n--\n-- Database schema\n--\n\n")

buf.WriteString("CREATE DATABASE " + drv.quoteIdentifier(databaseName) + " IF NOT EXISTS;\n\n")
buf.WriteString("CREATE DATABASE IF NOT EXISTS" + drv.quoteIdentifier(databaseName) + ";\n\n")

tables, err := dbutil.QueryColumn(db, "show tables")
if err != nil {
Expand Down
18 changes: 15 additions & 3 deletions pkg/driver/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ func TestClickHouseDatabaseExists_Error(t *testing.T) {
drv.databaseURL.RawQuery = values.Encode()

exists, err := drv.DatabaseExists()
require.EqualError(t, err, "code: 192, message: Unknown user invalid")
require.EqualError(
t,
err,
"code: 516, message: invalid: Authentication failed: password is incorrect or there is no user with such name",
)
require.Equal(t, false, exists)
}

Expand All @@ -193,7 +197,11 @@ func TestClickHouseCreateMigrationsTable(t *testing.T) {
// migrations table should not exist
count := 0
err := db.QueryRow("select count(*) from schema_migrations").Scan(&count)
require.EqualError(t, err, "code: 60, message: Table dbmate_test.schema_migrations doesn't exist.")
require.EqualError(
t,
err,
"code: 60, message: Table dbmate_test.schema_migrations doesn't exist",
)

// create table
err = drv.CreateMigrationsTable(db)
Expand All @@ -218,7 +226,11 @@ func TestClickHouseCreateMigrationsTable(t *testing.T) {
// migrations table should not exist
count := 0
err := db.QueryRow("select count(*) from \"testMigrations\"").Scan(&count)
require.EqualError(t, err, "code: 60, message: Table dbmate_test.testMigrations doesn't exist.")
require.EqualError(
t,
err,
"code: 60, message: Table dbmate_test.testMigrations doesn't exist",
)

// create table
err = drv.CreateMigrationsTable(db)
Expand Down

0 comments on commit 3a9a4f1

Please sign in to comment.