diff --git a/internal/infrastructure/postgres/migrations/0057_repost_open_chat_states.sql b/internal/infrastructure/postgres/migrations/0057_repost_open_chat_states.sql new file mode 100644 index 000000000..1e1741611 --- /dev/null +++ b/internal/infrastructure/postgres/migrations/0057_repost_open_chat_states.sql @@ -0,0 +1,11 @@ +-- 0056 read the old posted flag as "the current status was posted", but a +-- task flagged by its approval request and now holding an open pull request +-- was never told about the PR. Tasks in a reportable non-final state post it +-- once. + +-- +goose Up +UPDATE tasks SET outcome_posted_status = '' +WHERE origin <> '' AND status IN ('waiting_approval', 'pr_open'); + +-- +goose Down +SELECT 1; diff --git a/internal/infrastructure/postgres/postgresdb/tasks.sql.go b/internal/infrastructure/postgres/postgresdb/tasks.sql.go index 7b0a5a709..14eddc697 100644 --- a/internal/infrastructure/postgres/postgresdb/tasks.sql.go +++ b/internal/infrastructure/postgres/postgresdb/tasks.sql.go @@ -750,17 +750,19 @@ func (q *Queries) LockTaskStatus(ctx context.Context, id int64) (string, error) } const markOutcomePosted = `-- name: MarkOutcomePosted :exec -UPDATE tasks SET outcome_posted_status = $2 WHERE id = $1 +UPDATE tasks SET outcome_posted_status = COALESCE(NULLIF($1::text, ''), status) WHERE id = $2 ` type MarkOutcomePostedParams struct { - ID int64 - OutcomePostedStatus string + Posted string + ID int64 } -// Records the status whose state reached the task's conversation. +// Records the status whose state reached the task's conversation. A caller +// that names none (an older archied) marks the current status, so a mixed +// deploy cannot leave a posted state looking unposted forever. func (q *Queries) MarkOutcomePosted(ctx context.Context, arg MarkOutcomePostedParams) error { - _, err := q.db.Exec(ctx, markOutcomePosted, arg.ID, arg.OutcomePostedStatus) + _, err := q.db.Exec(ctx, markOutcomePosted, arg.Posted, arg.ID) return err } diff --git a/internal/infrastructure/postgres/queries/tasks.sql b/internal/infrastructure/postgres/queries/tasks.sql index dcab2ed99..f02badb4d 100644 --- a/internal/infrastructure/postgres/queries/tasks.sql +++ b/internal/infrastructure/postgres/queries/tasks.sql @@ -112,8 +112,10 @@ ORDER BY id LIMIT 50; -- name: MarkOutcomePosted :exec --- Records the status whose state reached the task's conversation. -UPDATE tasks SET outcome_posted_status = $2 WHERE id = $1; +-- Records the status whose state reached the task's conversation. A caller +-- that names none (an older archied) marks the current status, so a mixed +-- deploy cannot leave a posted state looking unposted forever. +UPDATE tasks SET outcome_posted_status = COALESCE(NULLIF(sqlc.arg(posted)::text, ''), status) WHERE id = sqlc.arg(id); -- name: StampTaskBinding :exec -- The capture's signature result is spelled as the access context spells it. diff --git a/internal/infrastructure/postgres/store.go b/internal/infrastructure/postgres/store.go index 2ac2f9129..8ceac436b 100644 --- a/internal/infrastructure/postgres/store.go +++ b/internal/infrastructure/postgres/store.go @@ -957,7 +957,7 @@ func (s *Store) UnpostedOutcomes(ctx context.Context) ([]*workflow.Task, error) // MarkOutcomePosted records that the task's state at status reached its // conversation. func (s *Store) MarkOutcomePosted(ctx context.Context, taskID int64, status string) error { - if err := s.queries().MarkOutcomePosted(ctx, postgresdb.MarkOutcomePostedParams{ID: taskID, OutcomePostedStatus: status}); err != nil { + if err := s.queries().MarkOutcomePosted(ctx, postgresdb.MarkOutcomePostedParams{ID: taskID, Posted: status}); err != nil { return fmt.Errorf("store: mark outcome posted: %w", err) } return nil