diff --git a/internal/platform/pg/pg.go b/internal/platform/pg/pg.go index 3b841e71f..f0ca93be1 100644 --- a/internal/platform/pg/pg.go +++ b/internal/platform/pg/pg.go @@ -78,6 +78,10 @@ func grantRuntime(ctx context.Context, db *sqlx.DB, runtimeURL string, schemas [ for _, stmt := range []string{ "GRANT USAGE ON SCHEMA " + name + " TO " + role, "GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA " + name + " TO " + role, + // A table keyed by a serial draws from a sequence, which is its + // own grant: a module whose insert draws on one would fail DML it + // is otherwise allowed. + "GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA " + name + " TO " + role, } { if _, err := db.ExecContext(ctx, stmt); err != nil { return fmt.Errorf("grant runtime role on %s: %w", schema, err) diff --git a/modules/runs/internal/store/store.go b/modules/runs/internal/store/store.go index 16a3cf9de..caabd3731 100644 --- a/modules/runs/internal/store/store.go +++ b/modules/runs/internal/store/store.go @@ -130,7 +130,7 @@ func (s *Store) RenewLease(ctx context.Context, id, token uuid.UUID, ttl time.Du func (s *Store) Steps(ctx context.Context, id uuid.UUID) ([]Step, error) { var steps []Step if err := s.db.SelectContext(ctx, &steps, ` - SELECT run_id, seq, name, outcome, output, error FROM runs.steps + SELECT run_id, seq, name, outcome, coalesce(output, 'null') AS output, error FROM runs.steps WHERE run_id = $1 ORDER BY seq`, id); err != nil { return nil, fmt.Errorf("load steps: %w", err) } @@ -260,7 +260,9 @@ type Summary struct { FinishedAt sql.NullTime `db:"finished_at"` } -// Detail is a run with its input and result. +// Detail is a run with its input and result. A run that failed has no result, +// which the row holds as NULL and every reader gets as JSON null, as a step +// with no output does. type Detail struct { Summary Input jsontext.Value `db:"input"` @@ -289,7 +291,8 @@ func (s *Store) Recent(ctx context.Context, orgID string, limit int) ([]Summary, func (s *Store) Detail(ctx context.Context, orgID string, id uuid.UUID) (Detail, bool, error) { var d Detail err := s.db.GetContext(ctx, &d, ` - SELECT id, workflow, state, attempts, error, created_at, finished_at, input, result + SELECT id, workflow, state, attempts, error, created_at, finished_at, input, + coalesce(result, 'null') AS result FROM runs.runs WHERE org_id = $1 AND id = $2`, orgID, id) if errors.Is(err, sql.ErrNoRows) { return Detail{}, false, nil @@ -304,7 +307,7 @@ func (s *Store) Detail(ctx context.Context, orgID string, id uuid.UUID) (Detail, func (s *Store) RecordedSteps(ctx context.Context, id uuid.UUID) ([]Recorded, error) { var out []Recorded if err := s.db.SelectContext(ctx, &out, ` - SELECT run_id, seq, name, outcome, output, error, recorded_at FROM runs.steps + SELECT run_id, seq, name, outcome, coalesce(output, 'null') AS output, error, recorded_at FROM runs.steps WHERE run_id = $1 ORDER BY seq`, id); err != nil { return nil, fmt.Errorf("load steps: %w", err) }