diff --git a/CHANGELOG.md b/CHANGELOG.md index 85f1105..021ac5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +#### 0.2.6 (2022-03-29) + # [](https://github.com/uptrace/go-clickhouse/compare/v0.2.4...v) (2022-03-29) diff --git a/README.md b/README.md index cd11353..7de9b75 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,11 @@ [![Documentation](https://img.shields.io/badge/ch-documentation-informational)](https://clickhouse.uptrace.dev/) [![Chat](https://discordapp.com/api/guilds/752070105847955518/widget.png)](https://discord.gg/rWtp5Aj) +> go-clickhouse is brought to you by :star: +> [**uptrace/uptrace**](https://github.com/uptrace/uptrace). Uptrace is an open source and blazingly +> fast [distributed tracing tool](https://get.uptrace.dev/compare/distributed-tracing-tools.html) +> powered by OpenTelemetry and ClickHouse. Give it a star as well! + This client uses native protocol to communicate with ClickHouse server and requires Go 1.18+ in order to use generics. This is not a database/sql driver, but the API is compatible. @@ -113,3 +118,9 @@ func main() { fmt.Println(dest) } ``` + +## See also + +- [Golang ORM](https://github.com/uptrace/bun) for PostgreSQL, MySQL, MSSQL, and SQLite +- [Golang PostgreSQL](https://bun.uptrace.dev/postgres/) +- [Golang HTTP router](https://github.com/uptrace/bunrouter) diff --git a/chmigrate/migration.go b/chmigrate/migration.go index c5c01ac..533e48e 100644 --- a/chmigrate/migration.go +++ b/chmigrate/migration.go @@ -17,6 +17,7 @@ type Migration struct { ch.CHModel `ch:"engine:CollapsingMergeTree(sign)"` Name string `ch:",pk"` + Comment string `ch:"-"` GroupID int64 MigratedAt time.Time Sign int8 @@ -26,7 +27,7 @@ type Migration struct { } func (m *Migration) String() string { - return m.Name + return fmt.Sprintf("%s_%s", m.Name, m.Comment) } func (m *Migration) IsApplied() bool { @@ -128,7 +129,7 @@ func (ms MigrationSlice) String() string { if i > 0 { sb.WriteString(", ") } - sb.WriteString(ms[i].Name) + sb.WriteString(ms[i].String()) } return sb.String() diff --git a/chmigrate/migrations.go b/chmigrate/migrations.go index 396e1a6..84bb3ed 100644 --- a/chmigrate/migrations.go +++ b/chmigrate/migrations.go @@ -50,15 +50,16 @@ func (m *Migrations) MustRegister(up, down MigrationFunc) { func (m *Migrations) Register(up, down MigrationFunc) error { fpath := migrationFile() - name, err := extractMigrationName(fpath) + name, comment, err := extractMigrationName(fpath) if err != nil { return err } m.Add(Migration{ - Name: name, - Up: up, - Down: down, + Name: name, + Comment: comment, + Up: up, + Down: down, }) return nil @@ -89,7 +90,7 @@ func (m *Migrations) Discover(fsys fs.FS) error { return nil } - name, err := extractMigrationName(path) + name, comment, err := extractMigrationName(path) if err != nil { return err } @@ -98,6 +99,8 @@ func (m *Migrations) Discover(fsys fs.FS) error { if err != nil { return err } + + migration.Comment = comment migrationFunc := NewSQLMigrationFunc(fsys, path) if strings.HasSuffix(path, ".up.sql") { @@ -154,15 +157,15 @@ func migrationFile() string { return "" } -var fnameRE = regexp.MustCompile(`^(\d{14})_[0-9a-z_\-]+\.`) +var fnameRE = regexp.MustCompile(`^(\d{14})_([0-9a-z_\-]+)\.`) -func extractMigrationName(fpath string) (string, error) { +func extractMigrationName(fpath string) (string, string, error) { fname := filepath.Base(fpath) matches := fnameRE.FindStringSubmatch(fname) if matches == nil { - return "", fmt.Errorf("chmigrate: unsupported migration name format: %q", fname) + return "", "", fmt.Errorf("chmigrate: unsupported migration name format: %q", fname) } - return matches[1], nil + return matches[1], matches[2], nil } diff --git a/chmigrate/migrator.go b/chmigrate/migrator.go index f2e9c7d..2513135 100644 --- a/chmigrate/migrator.go +++ b/chmigrate/migrator.go @@ -352,7 +352,7 @@ func (m *Migrator) Lock(ctx context.Context) error { if _, err := m.db.ExecContext( ctx, "ALTER TABLE ? ADD COLUMN ? Int8", - ch.Safe(m.locksTable), ch.Safe("col1"), + ch.Safe(m.locksTable), ch.Safe("lock"), ); err != nil { return fmt.Errorf("chmigrate: migrations table is already locked (%w)", err) } @@ -363,7 +363,7 @@ func (m *Migrator) Unlock(ctx context.Context) error { if _, err := m.db.ExecContext( ctx, "ALTER TABLE ? DROP COLUMN ?", - ch.Safe(m.locksTable), ch.Safe("col1"), + ch.Safe(m.locksTable), ch.Safe("lock"), ); err != nil && !strings.Contains(err.Error(), "Cannot find column") { return fmt.Errorf("chmigrate: migrations table is already unlocked (%w)", err) }