Skip to content

Commit 1596f36

Browse files
committed
add rizal patch
1 parent 6b84fed commit 1596f36

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

database/clickhouse/clickhouse.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (ch *ClickHouse) Version() (int, bool, error) {
169169
var (
170170
version int
171171
dirty uint8
172-
query = "SELECT version, dirty FROM `" + ch.config.MigrationsTable + "` ORDER BY sequence DESC LIMIT 1"
172+
query = "SELECT version, dirty FROM " + quoteIdentifier(ch.config.DatabaseName) + "." + quoteIdentifier(ch.config.MigrationsTable) + " ORDER BY sequence DESC LIMIT 1"
173173
)
174174
if err := ch.conn.QueryRow(query).Scan(&version, &dirty); err != nil {
175175
if err == sql.ErrNoRows {
@@ -194,7 +194,7 @@ func (ch *ClickHouse) SetVersion(version int, dirty bool) error {
194194
return err
195195
}
196196

197-
query := "INSERT INTO " + ch.config.MigrationsTable + " (version, dirty, sequence) VALUES (?, ?, ?)"
197+
query := "INSERT INTO " + quoteIdentifier(ch.config.DatabaseName) + "." + quoteIdentifier(ch.config.MigrationsTable) + " (version, dirty, sequence) VALUES (?, ?, ?)"
198198
if _, err := tx.Exec(query, version, bool(dirty), time.Now().UnixNano()); err != nil {
199199
return &database.Error{OrigErr: err, Query: []byte(query)}
200200
}
@@ -236,18 +236,18 @@ func (ch *ClickHouse) ensureVersionTable() (err error) {
236236
// if not, create the empty migration table
237237
if len(ch.config.ClusterName) > 0 {
238238
query = fmt.Sprintf(`
239-
CREATE TABLE %s ON CLUSTER %s (
240-
version Int64,
241-
dirty UInt8,
242-
sequence UInt64
243-
) Engine=%s`, ch.config.MigrationsTable, ch.config.ClusterName, ch.config.MigrationsTableEngine)
239+
CREATE TABLE %s.%s ON CLUSTER %s (
240+
version Int64,
241+
dirty UInt8,
242+
sequence UInt64
243+
) Engine=%s`, quoteIdentifier(ch.config.DatabaseName), quoteIdentifier(ch.config.MigrationsTable), ch.config.ClusterName, ch.config.MigrationsTableEngine)
244244
} else {
245245
query = fmt.Sprintf(`
246-
CREATE TABLE %s (
247-
version Int64,
248-
dirty UInt8,
249-
sequence UInt64
250-
) Engine=%s`, ch.config.MigrationsTable, ch.config.MigrationsTableEngine)
246+
CREATE TABLE %s.%s (
247+
version Int64,
248+
dirty UInt8,
249+
sequence UInt64
250+
) Engine=%s`, quoteIdentifier(ch.config.DatabaseName), quoteIdentifier(ch.config.MigrationsTable), ch.config.MigrationsTableEngine)
251251
}
252252

253253
if strings.HasSuffix(ch.config.MigrationsTableEngine, "Tree") {

0 commit comments

Comments
 (0)