Skip to content

Commit

Permalink
fix: don't lock migrations when running Migrate and Rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Nov 9, 2022
1 parent b808afb commit 69a7354
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 10 additions & 0 deletions example/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func newDBCommand(migrator *migrate.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
Expand All @@ -74,6 +79,11 @@ func newDBCommand(migrator *migrate.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
Expand Down
10 changes: 0 additions & 10 deletions migrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,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
Expand Down Expand Up @@ -188,11 +183,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
Expand Down

0 comments on commit 69a7354

Please sign in to comment.