perf: refactor

This commit is contained in:
ryan
2026-06-20 09:48:33 +08:00
parent cac6e88bc0
commit 200525a1ab
6 changed files with 149 additions and 179 deletions
+5 -1
View File
@@ -41,6 +41,10 @@ func init() {
}
cfg := config.Config.ClickHouse
if cfg.Database == "" {
log.Fatalf("[ClickHouse] database name is required (expected: wavelet)\n")
}
opts := buildClickHouseOptions()
var err error
@@ -148,4 +152,4 @@ func SetChDBForTest(d *gorm.DB) {
// SetChConnForTest sets the package-level native ClickHouse connection for testing.
func SetChConnForTest(c driver.Conn) {
ChConn = c
}
}
+1 -8
View File
@@ -15,7 +15,6 @@ import (
"github.com/ClickHouse/clickhouse-go/v2"
"github.com/Rain-kl/Wavelet/internal/config"
"github.com/pressly/goose/v3"
"github.com/pressly/goose/v3/database"
)
const (
@@ -64,17 +63,11 @@ func MigrateClickHouse() {
log.Fatalf("[ClickHouse] get sub fs failed: %v\n", err)
}
store, err := database.NewStore(database.DialectClickHouse, clickhouseGooseVersionTable)
if err != nil {
closeClickHouseDB(sqlDB)
log.Fatalf("[ClickHouse] create goose store failed: %v\n", err)
}
provider, err := goose.NewProvider(
"clickhouse",
sqlDB,
subFS,
goose.WithStore(store),
goose.WithTableName(clickhouseGooseVersionTable),
goose.WithDisableGlobalRegistry(true),
)
if err != nil {
+14
View File
@@ -42,6 +42,20 @@ func gooseDialect() string {
return dialectPostgres
}
func tableExistsSQL(dialect string) string {
if dialect == dialectSqlite {
return "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=?"
}
return "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public' AND table_name = $1"
}
func tablesWithPrefixSQL(dialect string) string {
if dialect == dialectSqlite {
return "SELECT name FROM sqlite_master WHERE type='table' AND name LIKE ?"
}
return "SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_name LIKE $1"
}
func migrationDir() string {
if !config.Config.Database.Enabled {
return "goose/sqlite"