diff --git a/internal/controller/atlasschema_controller.go b/internal/controller/atlasschema_controller.go index 67cf52c..d60f4b0 100644 --- a/internal/controller/atlasschema_controller.go +++ b/internal/controller/atlasschema_controller.go @@ -146,6 +146,15 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request) return err }) } + if !data.hasDevURL() && data.URL != nil { + // The user has not specified an URL for dev-db, + // spin up a dev-db and get the connection string. + data.DevURL, err = r.devDB.devURL(ctx, res, *data.URL) + if err != nil { + res.SetNotReady("GettingDevDB", err.Error()) + return result(err) + } + } // Create a working directory for the Atlas CLI // The working directory contains the atlas.hcl config. wd, err := atlasexec.NewWorkingDir(opts...) @@ -174,6 +183,7 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request) // Calculate the hash of the current schema. hash, err := cli.SchemaInspect(ctx, &atlasexec.SchemaInspectParams{ Env: data.EnvName, + URL: "env://schema.src", Format: `{{ .Hash | base64url }}`, Vars: data.Vars, }) @@ -193,15 +203,6 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request) // Starting area to handle the heavy jobs. // Below this line is the main logic of the controller. // ==================================================== - if !data.hasDevURL() && data.URL != nil { - // The user has not specified an URL for dev-db, - // spin up a dev-db and get the connection string. - data.DevURL, err = r.devDB.devURL(ctx, res, *data.URL) - if err != nil { - res.SetNotReady("GettingDevDB", err.Error()) - return result(err) - } - } var whoami *atlasexec.WhoAmI switch whoami, err = cli.WhoAmI(ctx); { case errors.Is(err, atlasexec.ErrRequireLogin): diff --git a/internal/controller/atlasschema_controller_test.go b/internal/controller/atlasschema_controller_test.go index 54ca3a7..08b1c40 100644 --- a/internal/controller/atlasschema_controller_test.go +++ b/internal/controller/atlasschema_controller_test.go @@ -500,6 +500,9 @@ func TestConfigTemplate(t *testing.T) { err := data.render(&buf) require.NoError(t, err) expected := `env "kubernetes" { + schema { + src = "file://schema.sql" + } url = "mysql://root:password@localhost:3306/test" dev = "mysql://root:password@localhost:3306/dev" schemas = ["foo", "bar"] @@ -573,6 +576,9 @@ env "kubernetes" { dev = "mysql://root:password@localhost:3306/dev" schemas = ["foo", "bar"] url = "mysql://root:password@localhost:3306/test" + schema { + src = "file://schema.sql" + } } ` require.EqualValues(t, expected, buf.String()) @@ -599,6 +605,9 @@ env { dev = "mysql://root:password@localhost:3306/dev" schemas = ["foo", "bar"] url = "mysql://root:password@localhost:3306/test" + schema { + src = "file://schema.sql" + } }` require.EqualValues(t, expected, buf.String()) }