YZFIRGIEBHYDZQEX6NPU5N76FQB3KDDPCOYMWNQIYIUD7NJMT2ZQC }return nil}// ValidateLocationBelongsToDataset checks that a location belongs to a specific dataset// Returns error if location doesn't exist or belongs to a different datasetfunc ValidateLocationBelongsToDataset(db *sql.DB, locationID, datasetID string) error {var locationDatasetID stringerr := db.QueryRow("SELECT dataset_id FROM location WHERE id = ? AND active = true", locationID).Scan(&locationDatasetID)if err == sql.ErrNoRows {return fmt.Errorf("location not found or inactive: %s", locationID)}if err != nil {return fmt.Errorf("failed to query location: %w", err)}if locationDatasetID != datasetID {return fmt.Errorf("location %s does not belong to dataset %s", locationID, datasetID)
// ValidateClusterBelongsToLocation checks that a cluster belongs to a specific location// Returns error if cluster doesn't exist or belongs to a different locationfunc ValidateClusterBelongsToLocation(db *sql.DB, clusterID, locationID string) error {var clusterLocationID stringerr := db.QueryRow("SELECT location_id FROM cluster WHERE id = ? AND active = true", clusterID).Scan(&clusterLocationID)if err == sql.ErrNoRows {return fmt.Errorf("cluster not found or inactive: %s", clusterID)}if err != nil {return fmt.Errorf("failed to query cluster: %w", err)}if clusterLocationID != locationID {return fmt.Errorf("cluster %s does not belong to location %s", clusterID, locationID)}return nil}
// Phase 1.5: Validate all location_ids belong to the datasetlogger.Log("Validating location_ids belong to dataset...")readDB, err := db.OpenReadOnlyDB(dbPath)if err != nil {logger.Log("ERROR: Failed to open database: %v", err)output.Errors = []string{fmt.Sprintf("failed to open database: %v", err)}output.ProcessingTime = time.Since(startTime).String()return output, fmt.Errorf("failed to open database: %w", err)}locationErrors := bulkValidateLocationsBelongToDataset(readDB, locations, input.DatasetID)readDB.Close()
if len(locationErrors) > 0 {for _, locErr := range locationErrors {logger.Log("ERROR: %s", locErr)}output.Errors = locationErrorsoutput.ProcessingTime = time.Since(startTime).String()return output, fmt.Errorf("location validation failed: %d location(s) do not belong to dataset %s", len(locationErrors), input.DatasetID)}logger.Log("Location validation complete")
// Collect unique location_idsuniqueLocations := make(map[string]bool)for _, loc := range locations {uniqueLocations[loc.LocationID] = true}// Validate each unique location_idfor locationID := range uniqueLocations {if err := utils.ValidateLocationBelongsToDataset(dbConn, locationID, datasetID); err != nil {errors = append(errors, err.Error())}}return errors}