Skip to content

Commit

Permalink
chore: wait for db migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Dec 21, 2023
1 parent 841f039 commit 7c5d2cb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
"os"
"path"
"strings"
"time"

embeddedpostgres "github.com/fergusstrange/embedded-postgres"
"github.com/flanksource/commons/logger"
"github.com/flanksource/duty"
"github.com/flanksource/duty/migrate"
"github.com/flanksource/duty/models"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/samber/lo"
"gorm.io/gorm"
"gorm.io/plugin/prometheus"
)
Expand Down Expand Up @@ -121,8 +124,14 @@ func Init() error {
if err := duty.Migrate(ConnectionString, opts); err != nil {
return err
}
} else {
_, _, err := lo.AttemptWithDelay(5, 5*time.Second, func(i int, d time.Duration) error {
return Gorm.Limit(1).Find(&[]models.Agent{}).Error
})
if err != nil {
logger.Fatalf("Database migrations not run: %v", err)
}
}

return nil
}

Expand Down

0 comments on commit 7c5d2cb

Please sign in to comment.