diff --git a/cmd/debug.go b/cmd/debug.go index 27c105ff..bba81af6 100644 --- a/cmd/debug.go +++ b/cmd/debug.go @@ -115,6 +115,9 @@ var specCmd = &cobra.Command{ envVariables = map[string]string{} } + spec, err := collector.ServiceRequirementsToSpec(proj.Name, envVariables, serviceRequirements, batchRequirements) + tui.CheckErr(err) + migrationImageContexts, err := collector.GetMigrationImageBuildContexts(serviceRequirements, batchRequirements, fs) tui.CheckErr(err) // Build images from contexts and provide updates on the builds @@ -147,9 +150,6 @@ var specCmd = &cobra.Command{ outputFile = "./nitric-spec.json" } - spec, err := collector.ServiceRequirementsToSpec(proj.Name, envVariables, serviceRequirements, batchRequirements) - tui.CheckErr(err) - marshaler := protojson.MarshalOptions{ Multiline: true, Indent: " ", diff --git a/cmd/stack.go b/cmd/stack.go index 3cea1eda..ded5b072 100644 --- a/cmd/stack.go +++ b/cmd/stack.go @@ -240,6 +240,9 @@ var stackUpdateCmd = &cobra.Command{ envVariables["NITRIC_BETA_PROVIDERS"] = "true" } + spec, err := collector.ServiceRequirementsToSpec(proj.Name, envVariables, serviceRequirements, batchRequirements) + tui.CheckErr(err) + migrationImageContexts, err := collector.GetMigrationImageBuildContexts(serviceRequirements, batchRequirements, fs) tui.CheckErr(err) // Build images from contexts and provide updates on the builds @@ -267,9 +270,6 @@ var stackUpdateCmd = &cobra.Command{ } } - spec, err := collector.ServiceRequirementsToSpec(proj.Name, envVariables, serviceRequirements, batchRequirements) - tui.CheckErr(err) - providerStdout := make(chan string) // Step 4. Start the deployment provider server diff --git a/pkg/collector/spec.go b/pkg/collector/spec.go index 6ea10d2d..e094e4d6 100644 --- a/pkg/collector/spec.go +++ b/pkg/collector/spec.go @@ -271,16 +271,44 @@ func GetMigrationImageBuildContexts(allServiceRequirements []*ServiceRequirement return imageBuildContexts, nil } +func checkConflictingMigrations(allDatabases []map[string]*resourcespb.SqlDatabaseResource, resource map[string]*resourcespb.SqlDatabaseResource) error { + for _, dbs := range allDatabases { + for databaseName, dbConfig := range resource { + if existing, exists := dbs[databaseName]; exists { + if dbConfig.Migrations == nil { + continue + } + + if existing.Migrations.GetMigrationsPath() != dbConfig.Migrations.GetMigrationsPath() { + return fmt.Errorf("database '%s' has conflicting migrations paths; they must be identical", databaseName) + } + } + } + } + + return nil +} + func buildDatabaseRequirements(allServiceRequirements []*ServiceRequirements, allBatchRequirements []*BatchRequirements, projectErrors *ProjectErrors) ([]*deploymentspb.Resource, error) { resources := []*deploymentspb.Resource{} allDatabases := []map[string]*resourcespb.SqlDatabaseResource{} for _, serviceRequirements := range allServiceRequirements { + err := checkConflictingMigrations(allDatabases, serviceRequirements.sqlDatabases) + if err != nil { + return nil, err + } + allDatabases = append(allDatabases, serviceRequirements.sqlDatabases) } for _, batchRequirements := range allBatchRequirements { + err := checkConflictingMigrations(allDatabases, batchRequirements.sqlDatabases) + if err != nil { + return nil, err + } + allDatabases = append(allDatabases, batchRequirements.sqlDatabases) }