You've already forked go-clickhouse
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:
2
ch/testdata/snapshots/TestQuery-11
vendored
2
ch/testdata/snapshots/TestQuery-11
vendored
@ -1 +1 @@
|
|||||||
DROP VIEW "hello_world"
|
DROP VIEW "view_name"
|
||||||
|
2
ch/testdata/snapshots/TestQuery-12
vendored
2
ch/testdata/snapshots/TestQuery-12
vendored
@ -1 +1 @@
|
|||||||
DROP VIEW IF EXISTS hello_world
|
DROP VIEW IF EXISTS view_name
|
||||||
|
2
ch/testdata/snapshots/TestQuery-13
vendored
2
ch/testdata/snapshots/TestQuery-13
vendored
@ -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
|
||||||
|
@ -155,11 +155,6 @@ func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*Migra
|
|||||||
return nil, err
|
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)
|
migrations, lastGroupID, err := m.migrationsWithStatus(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -214,11 +209,6 @@ func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*Migr
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.Lock(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer m.Unlock(ctx) //nolint:errcheck
|
|
||||||
|
|
||||||
migrations, err := m.MigrationsWithStatus(ctx)
|
migrations, err := m.MigrationsWithStatus(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -49,15 +49,23 @@ func newDBCommand(db *ch.DB, migrator *chmigrate.Migrator) *cli.Command {
|
|||||||
Name: "migrate",
|
Name: "migrate",
|
||||||
Usage: "migrate database",
|
Usage: "migrate database",
|
||||||
Action: func(c *cli.Context) error {
|
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)
|
group, err := migrator.Migrate(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.IsZero() {
|
if group.IsZero() {
|
||||||
fmt.Printf("there are no new migrations to run (database is up to date)\n")
|
fmt.Printf("there are no new migrations to run (database is up to date)\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("migrated to %s\n", group)
|
fmt.Printf("migrated to %s\n", group)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -65,15 +73,23 @@ func newDBCommand(db *ch.DB, migrator *chmigrate.Migrator) *cli.Command {
|
|||||||
Name: "rollback",
|
Name: "rollback",
|
||||||
Usage: "rollback the last migration group",
|
Usage: "rollback the last migration group",
|
||||||
Action: func(c *cli.Context) error {
|
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)
|
group, err := migrator.Rollback(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.IsZero() {
|
if group.IsZero() {
|
||||||
fmt.Printf("there are no groups to roll back\n")
|
fmt.Printf("there are no groups to roll back\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("rolled back %s\n", group)
|
fmt.Printf("rolled back %s\n", group)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user