buildCELVariablesForDatabaseChange builds CEL variables for DATABASE_CHANGE issues. This includes DDL and DML operations.
(ctx context.Context, stores *store.Store, issue *store.IssueMessage)
| 553 | // buildCELVariablesForDatabaseChange builds CEL variables for DATABASE_CHANGE issues. |
| 554 | // This includes DDL and DML operations. |
| 555 | func buildCELVariablesForDatabaseChange(ctx context.Context, stores *store.Store, issue *store.IssueMessage) ([]map[string]any, bool, error) { |
| 556 | if issue.PlanUID == nil { |
| 557 | return nil, false, errors.Errorf("expected plan UID in issue %v", issue.UID) |
| 558 | } |
| 559 | plan, err := stores.GetPlan(ctx, &store.FindPlanMessage{ProjectID: issue.ProjectID, UID: issue.PlanUID}) |
| 560 | if err != nil { |
| 561 | return nil, false, errors.Wrapf(err, "failed to get plan %v", *issue.PlanUID) |
| 562 | } |
| 563 | if plan == nil { |
| 564 | return nil, false, errors.Errorf("plan %v not found", *issue.PlanUID) |
| 565 | } |
| 566 | |
| 567 | planCheckRun, err := stores.GetPlanCheckRun(ctx, issue.ProjectID, plan.UID) |
| 568 | if err != nil { |
| 569 | return nil, false, errors.Wrapf(err, "failed to get plan check run for plan %v", plan.UID) |
| 570 | } |
| 571 | |
| 572 | // Wait for plan check to complete if available or running. |
| 573 | if isPlanCheckRunPendingApprovalEvaluation(planCheckRun) { |
| 574 | return nil, false, nil // Not ready yet, retry later |
| 575 | } |
| 576 | |
| 577 | // Unfold database groups and get all targets |
| 578 | targets, err := unfoldSpecTargets(ctx, stores, plan.Config.GetSpecs(), issue.ProjectID) |
| 579 | if err != nil { |
| 580 | return nil, false, errors.Wrap(err, "failed to unfold spec targets") |
| 581 | } |
| 582 | |
| 583 | statementSummaryResults := map[statementSummaryKey]*storepb.PlanCheckRunResult_Result{} |
| 584 | if planCheckRun != nil { |
| 585 | statementSummaryResults = buildStatementSummaryResultMap(planCheckRun.Result.GetResults()) |
| 586 | } |
| 587 | |
| 588 | var celVarsList []map[string]any |
| 589 | for _, target := range targets { |
| 590 | taskStatement := "" |
| 591 | if target.sheetSha256 != "" { |
| 592 | sheet, err := stores.GetSheetFull(ctx, target.sheetSha256) |
| 593 | if err != nil { |
| 594 | return nil, true, errors.Wrapf(err, "failed to get statement in sheet %v", target.sheetSha256) |
| 595 | } |
| 596 | if sheet == nil { |
| 597 | return nil, true, errors.Errorf("sheet %v not found", target.sheetSha256) |
| 598 | } |
| 599 | taskStatement = sheet.Statement |
| 600 | } |
| 601 | |
| 602 | environmentID := "" |
| 603 | if target.database.EffectiveEnvironmentID != nil { |
| 604 | environmentID = *target.database.EffectiveEnvironmentID |
| 605 | } |
| 606 | |
| 607 | // Base CEL variables |
| 608 | celVars := map[string]any{ |
| 609 | common.CELAttributeResourceEnvironmentID: environmentID, |
| 610 | common.CELAttributeResourceProjectID: issue.ProjectID, |
| 611 | common.CELAttributeResourceInstanceID: target.database.InstanceID, |
| 612 | common.CELAttributeResourceDatabaseName: target.database.DatabaseName, |
no test coverage detected