diff --git a/cmd/operator.go b/cmd/operator.go index 12619400..6b3cf177 100644 --- a/cmd/operator.go +++ b/cmd/operator.go @@ -1,6 +1,7 @@ package cmd import ( + "errors" "fmt" "os" @@ -18,6 +19,7 @@ import ( configsv1 "github.com/flanksource/config-db/api/v1" "github.com/flanksource/config-db/controllers" "github.com/flanksource/config-db/db" + "github.com/flanksource/duty" dutyContext "github.com/flanksource/duty/context" "github.com/go-logr/zapr" "github.com/spf13/cobra" @@ -49,6 +51,12 @@ func run(cmd *cobra.Command, args []string) error { return fmt.Errorf("failed to load properties: %v", err) } + if ok, err := duty.HasMigrationRun(ctx, api.DefaultContext.Pool()); err != nil { + return fmt.Errorf("failed to check if migrations have run: %w", err) + } else if !ok { + return errors.New("migrations haven't run yet") + } + zapLogger := logger.GetZapLogger() if zapLogger == nil { return fmt.Errorf("failed to get zap logger") diff --git a/cmd/root.go b/cmd/root.go index cbdca922..5fd78856 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -59,7 +59,6 @@ var Root = &cobra.Command{ } db.Schema = readFromEnv(db.Schema) db.PGRSTLogLevel = readFromEnv(db.PGRSTLogLevel) - }, } diff --git a/cmd/server.go b/cmd/server.go index 8bdbe7ee..e5c324f5 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "errors" "fmt" "net/url" @@ -10,6 +11,7 @@ import ( v1 "github.com/flanksource/config-db/api/v1" "github.com/flanksource/config-db/db" "github.com/flanksource/config-db/jobs" + "github.com/flanksource/duty" dutyContext "github.com/flanksource/duty/context" "github.com/labstack/echo-contrib/echoprometheus" "github.com/labstack/echo/v4" @@ -26,6 +28,12 @@ var Serve = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { api.DefaultContext = api.NewScrapeContext(db.MustInit()) + if ok, err := duty.HasMigrationRun(cmd.Context(), api.DefaultContext.Pool()); err != nil { + return fmt.Errorf("failed to check if migrations have run: %w", err) + } else if !ok { + return errors.New("migrations haven't run yet") + } + if err := dutyContext.LoadPropertiesFromFile(api.DefaultContext.DutyContext(), propertiesFile); err != nil { return fmt.Errorf("failed to load properties: %v", err) } diff --git a/go.mod b/go.mod index 09d4c344..2045d8ba 100644 --- a/go.mod +++ b/go.mod @@ -296,7 +296,7 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect ) -// replace github.com/flanksource/duty => ../duty +replace github.com/flanksource/duty => ../duty // replace github.com/flanksource/ketall => ../ketall diff --git a/go.sum b/go.sum index c8108a63..3d6d5182 100644 --- a/go.sum +++ b/go.sum @@ -856,8 +856,6 @@ github.com/fergusstrange/embedded-postgres v1.25.0 h1:sa+k2Ycrtz40eCRPOzI7Ry7Ttk github.com/fergusstrange/embedded-postgres v1.25.0/go.mod h1:t/MLs0h9ukYM6FSt99R7InCHs1nW0ordoVCcnzmpTYw= github.com/flanksource/commons v1.22.1 h1:Ycg8r26bx537UTdAEFgngDW1r2j5bX6Lr3NGxLICpiw= github.com/flanksource/commons v1.22.1/go.mod h1:GD5+yGvmYFPIW3WMNN+y1JkeDMJY74e05pQAsRbrvwY= -github.com/flanksource/duty v1.0.445 h1:QsrQUsv971avvPtF9uLMeq/rvarGR475WWsbPzZcBSI= -github.com/flanksource/duty v1.0.445/go.mod h1:eF0Z6vZ2vSO1vy8HDYMc+OkhGWx4Pg5+P16gUuL8+oI= github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc= github.com/flanksource/gomplate/v3 v3.24.2 h1:WZSriw1MaBhzrDV1IOP9eNsupIPxIHy0yTaMOVhCvsk= github.com/flanksource/gomplate/v3 v3.24.2/go.mod h1:94BxYobZqouGdVezuz6LNto5C+yLMG0LnNnM9CUPyoo=