-- A chat task's conversation is told about each state worth reporting (an -- approval request, an open pull request, a final outcome). Recording which -- status was posted, rather than whether anything was, makes every status -- change due for posting without each write path having to reset a flag. -- +goose Up ALTER TABLE tasks ADD COLUMN outcome_posted_status text NOT NULL DEFAULT ''; UPDATE tasks SET outcome_posted_status = status WHERE outcome_posted; DROP INDEX IF EXISTS idx_tasks_outcome_unposted; ALTER TABLE tasks DROP COLUMN outcome_posted; CREATE INDEX idx_tasks_outcome_unposted ON tasks (id) WHERE origin <> '' AND outcome_posted_status <> status; -- +goose Down DROP INDEX IF EXISTS idx_tasks_outcome_unposted; ALTER TABLE tasks ADD COLUMN outcome_posted boolean NOT NULL DEFAULT false; UPDATE tasks SET outcome_posted = outcome_posted_status = status; ALTER TABLE tasks DROP COLUMN outcome_posted_status; CREATE INDEX idx_tasks_outcome_unposted ON tasks (id) WHERE origin <> '' AND NOT outcome_posted;