Skip to content

Commit

Permalink
improve bbgo db migration process
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jan 18, 2024
1 parent 4b7bd45 commit 174f28c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/service/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,22 @@ func (s *DatabaseService) Upgrade(ctx context.Context) error {
rh := rockhopper.New(s.Driver, dialect, s.DB.DB, rockhopper.TableName)

migrations = migrations.FilterPackage([]string{"main"}).SortAndConnect()
if len(migrations) == 0 {
return nil
}

_, lastAppliedMigration, err := rh.FindLastAppliedMigration(ctx, migrations)
if err != nil {
return err
}

if lastAppliedMigration != nil {
return rockhopper.Up(ctx, rh, lastAppliedMigration.Next, 0)
}

return rockhopper.Align(ctx, rh, 20231123125402, migrations)
// TODO: use align in the next major version
// return rockhopper.Align(ctx, rh, 20231123125402, migrations)
return rockhopper.Up(ctx, rh, migrations.Head(), 0)
}

func ReformatMysqlDSN(dsn string) (string, error) {
Expand Down

0 comments on commit 174f28c

Please sign in to comment.