mirror of
https://github.com/uptrace/go-clickhouse.git
synced 2025-06-08 23:26:11 +02:00
chore: update readme
This commit is contained in:
parent
577b338610
commit
4360cd8da9
@ -1,3 +1,5 @@
|
||||
#### 0.2.6 (2022-03-29)
|
||||
|
||||
# [](https://github.com/uptrace/go-clickhouse/compare/v0.2.4...v) (2022-03-29)
|
||||
|
||||
|
||||
|
11
README.md
11
README.md
@ -5,6 +5,11 @@
|
||||
[](https://clickhouse.uptrace.dev/)
|
||||
[](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)
|
||||
|
@ -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()
|
||||
|
@ -50,13 +50,14 @@ 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,
|
||||
Comment: comment,
|
||||
Up: up,
|
||||
Down: down,
|
||||
})
|
||||
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user