-- +goose Up

ALTER TABLE assignments
    ADD COLUMN pass_threshold NUMERIC(5,2) NOT NULL DEFAULT 8.00,
    ADD CONSTRAINT assignments_pass_threshold_range_check
        CHECK (pass_threshold >= 0 AND pass_threshold <= 10);

UPDATE assignments a
SET pass_threshold = COALESCE(
    (
        SELECT MAX(aa.pass_threshold)
        FROM assignment_assignees aa
        WHERE aa.assignment_id = a.id
    ),
    8.00
);

-- +goose Down

ALTER TABLE assignments
    DROP CONSTRAINT IF EXISTS assignments_pass_threshold_range_check,
    DROP COLUMN IF EXISTS pass_threshold;
