mirror of
https://github.com/pressly/goose.git
synced 2025-05-30 19:23:14 +00:00
clickhouse: set mutations_sync 2 for delete version (#454)
This commit is contained in:
parent
32ad603fee
commit
ad90652042
@ -322,7 +322,7 @@ func (m ClickHouseDialect) migrationSQL() string {
|
||||
}
|
||||
|
||||
func (m ClickHouseDialect) deleteVersionSQL() string {
|
||||
return fmt.Sprintf("ALTER TABLE %s DELETE WHERE version_id = $1", TableName())
|
||||
return fmt.Sprintf("ALTER TABLE %s DELETE WHERE version_id = $1 SETTINGS mutations_sync = 2", TableName())
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
|
2
go.mod
2
go.mod
@ -4,7 +4,6 @@ go 1.17
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.2.0
|
||||
github.com/avast/retry-go/v4 v4.3.2
|
||||
github.com/denisenkom/go-mssqldb v0.12.3
|
||||
github.com/go-sql-driver/mysql v1.7.0
|
||||
github.com/jackc/pgx/v4 v4.17.2
|
||||
@ -56,6 +55,7 @@ require (
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20220927061507-ef77025ab5aa // indirect
|
||||
github.com/shopspring/decimal v1.3.1 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/stretchr/testify v1.8.1 // indirect
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -16,8 +16,6 @@ github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v
|
||||
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
|
||||
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/avast/retry-go/v4 v4.3.2 h1:x4sTEu3jSwr7zNjya8NTdIN+U88u/jtO/q3OupBoDtM=
|
||||
github.com/avast/retry-go/v4 v4.3.2/go.mod h1:rg6XFaiuFYII0Xu3RDbZQkxCofFwruZKW8oEF1jpWiU=
|
||||
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
|
||||
github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4=
|
||||
github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
|
||||
|
@ -1,13 +1,10 @@
|
||||
package clickhouse_test
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/avast/retry-go/v4"
|
||||
"github.com/pressly/goose/v3"
|
||||
"github.com/pressly/goose/v3/internal/check"
|
||||
"github.com/pressly/goose/v3/internal/testdb"
|
||||
@ -23,16 +20,6 @@ func TestClickUpDownAll(t *testing.T) {
|
||||
|
||||
check.NoError(t, goose.SetDialect("clickhouse"))
|
||||
|
||||
retryCheckTableMutation := func(table string) func() error {
|
||||
return func() error {
|
||||
ok := checkTableMutation(t, db, table)
|
||||
if !ok {
|
||||
return errors.New("mutation not done for table: " + table)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
This test applies all up migrations, asserts we have all the entries in
|
||||
the versions table, applies all down migration and asserts we have zero
|
||||
@ -69,11 +56,6 @@ func TestClickUpDownAll(t *testing.T) {
|
||||
|
||||
err = goose.DownTo(db, migrationDir, 0)
|
||||
check.NoError(t, err)
|
||||
err = retry.Do(
|
||||
retryCheckTableMutation(goose.TableName()),
|
||||
retry.Delay(1*time.Second),
|
||||
)
|
||||
check.NoError(t, err)
|
||||
|
||||
currentVersion, err = goose.GetDBVersion(db)
|
||||
check.NoError(t, err)
|
||||
@ -170,40 +152,3 @@ func TestRemoteImportMigration(t *testing.T) {
|
||||
check.NoError(t, err)
|
||||
check.Number(t, count, 265)
|
||||
}
|
||||
|
||||
func checkTableMutation(t *testing.T, db *sql.DB, tableName string) bool {
|
||||
t.Helper()
|
||||
rows, err := db.Query(
|
||||
`select mutation_id, command, is_done, create_time from system.mutations where table=$1`,
|
||||
tableName,
|
||||
)
|
||||
check.NoError(t, err)
|
||||
|
||||
type result struct {
|
||||
mutationID string `db:"mutation_id"`
|
||||
command string `db:"command"`
|
||||
isDone int64 `db:"is_done"`
|
||||
createTime time.Time `db:"create_time"`
|
||||
}
|
||||
var results []result
|
||||
for rows.Next() {
|
||||
var r result
|
||||
err = rows.Scan(&r.mutationID, &r.command, &r.isDone, &r.createTime)
|
||||
check.NoError(t, err)
|
||||
results = append(results, r)
|
||||
}
|
||||
check.NoError(t, rows.Close())
|
||||
check.NoError(t, rows.Err())
|
||||
// No results means there are no mutations. Assume they are all done.
|
||||
if len(results) == 0 {
|
||||
return true
|
||||
}
|
||||
// Loop through all the mutations, if at least one of them is
|
||||
// not done, return false.
|
||||
for _, r := range results {
|
||||
if r.isDone != 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user