1
0
mirror of https://github.com/uptrace/go-clickhouse.git synced 2025-08-08 22:16:32 +02:00

chore: don't lock migrations by default

This commit is contained in:
Vladimir Mihailenco
2022-11-09 10:11:14 +02:00
parent 117fffe8ed
commit 3874d74090
5 changed files with 19 additions and 13 deletions

View File

@ -1 +1 @@
DROP VIEW "hello_world"
DROP VIEW "view_name"

View File

@ -1 +1 @@
DROP VIEW IF EXISTS hello_world
DROP VIEW IF EXISTS view_name

View File

@ -1 +1 @@
CREATE VIEW "view_name"TO "dest_table" AS SELECT "col1", col1 AS alias FROM src_table AS alias
CREATE MATERIALIZED VIEW IF NOT EXISTS "view_name" TO "dest_table" AS SELECT "col1", col1 AS alias FROM src_table AS alias WHERE (foo = bar) GROUP BY "group1", group2, group3 ORDER BY order2, order3

View File

@ -155,11 +155,6 @@ func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*Migra
return nil, err
}
if err := m.Lock(ctx); err != nil {
return nil, err
}
defer m.Unlock(ctx) //nolint:errcheck
migrations, lastGroupID, err := m.migrationsWithStatus(ctx)
if err != nil {
return nil, err
@ -214,11 +209,6 @@ func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*Migr
return nil, err
}
if err := m.Lock(ctx); err != nil {
return nil, err
}
defer m.Unlock(ctx) //nolint:errcheck
migrations, err := m.MigrationsWithStatus(ctx)
if err != nil {
return nil, err

View File

@ -49,15 +49,23 @@ func newDBCommand(db *ch.DB, migrator *chmigrate.Migrator) *cli.Command {
Name: "migrate",
Usage: "migrate database",
Action: func(c *cli.Context) error {
if err := migrator.Lock(c.Context); err != nil {
return err
}
defer migrator.Unlock(c.Context) //nolint:errcheck
group, err := migrator.Migrate(c.Context)
if err != nil {
return err
}
if group.IsZero() {
fmt.Printf("there are no new migrations to run (database is up to date)\n")
return nil
}
fmt.Printf("migrated to %s\n", group)
return nil
},
},
@ -65,15 +73,23 @@ func newDBCommand(db *ch.DB, migrator *chmigrate.Migrator) *cli.Command {
Name: "rollback",
Usage: "rollback the last migration group",
Action: func(c *cli.Context) error {
if err := migrator.Lock(c.Context); err != nil {
return err
}
defer migrator.Unlock(c.Context) //nolint:errcheck
group, err := migrator.Rollback(c.Context)
if err != nil {
return err
}
if group.IsZero() {
fmt.Printf("there are no groups to roll back\n")
return nil
}
fmt.Printf("rolled back %s\n", group)
return nil
},
},