MCPcopy Create free account
hub / github.com/bytebase/bytebase / CreatePlanCheckRun

Method CreatePlanCheckRun

backend/store/plan_check_run.go:57–90  ·  view source on GitHub ↗

CreatePlanCheckRun creates or replaces the plan check run for a plan. Always creates with AVAILABLE status for HA-safe scheduling.

(ctx context.Context, create *PlanCheckRunMessage)

Source from the content-addressed store, hash-verified

55// CreatePlanCheckRun creates or replaces the plan check run for a plan.
56// Always creates with AVAILABLE status for HA-safe scheduling.
57func (s *Store) CreatePlanCheckRun(ctx context.Context, create *PlanCheckRunMessage) error {
58 result, err := protojson.Marshal(create.Result)
59 if err != nil {
60 return errors.Wrapf(err, "failed to marshal result")
61 }
62
63 tx, err := s.GetDB().BeginTx(ctx, nil)
64 if err != nil {
65 return errors.Wrapf(err, "failed to begin tx")
66 }
67 defer tx.Rollback()
68
69 nextID, err := nextProjectID(ctx, tx, "plan_check_run", create.ProjectID)
70 if err != nil {
71 return err
72 }
73
74 query := `
75 INSERT INTO plan_check_run (id, project, plan_id, status, result)
76 VALUES ($1, $2, $3, $4, $5)
77 ON CONFLICT (project, plan_id) DO UPDATE SET
78 status = EXCLUDED.status,
79 result = EXCLUDED.result,
80 updated_at = now()
81 `
82 if _, err := tx.ExecContext(ctx, query, nextID, create.ProjectID, create.PlanUID, PlanCheckRunStatusAvailable, result); err != nil {
83 return errors.Wrapf(err, "failed to upsert plan check run")
84 }
85
86 if err := tx.Commit(); err != nil {
87 return errors.Wrapf(err, "failed to commit tx")
88 }
89 return nil
90}
91
92// ListPlanCheckRuns returns a list of plan check runs based on find.
93func (s *Store) ListPlanCheckRuns(ctx context.Context, find *FindPlanCheckRunMessage) ([]*PlanCheckRunMessage, error) {

Callers 3

CreatePlanMethod · 0.80
UpdatePlanMethod · 0.80
RunPlanChecksMethod · 0.80

Calls 2

GetDBMethod · 0.95
nextProjectIDFunction · 0.85

Tested by

no test coverage detected