Skip to content

Commit 099c2f2

Browse files
ybelMekktommytroen
andcommitted
fix: callback func on startedleading for migrations
Co-authored-by: Tommy Trøen <[email protected]>
1 parent e5cb967 commit 099c2f2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/database/database.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ func migrateDatabaseSchema(ctx context.Context, driver, dsn string, log logrus.F
113113
}
114114
}()
115115

116+
leaderelection.RegisterOnStartedLeading(func(ctx context.Context) {
117+
err = goose.Up(db, "migrations")
118+
if err != nil {
119+
log.WithError(err).Fatal("running database migration")
120+
}
121+
})
122+
116123
for {
117124
select {
118125
case <-ctx.Done():
@@ -133,7 +140,6 @@ func migrateDatabaseSchema(ctx context.Context, driver, dsn string, log logrus.F
133140
log.Info("not leader, skipping database migration")
134141
return nil
135142
}
136-
return goose.Up(db, "migrations")
137143
}
138144
}
139145
}

0 commit comments

Comments
 (0)