-- Migration 213: allow smart-sync to mark invoice error finder issues as resolved

DO $$
BEGIN
    IF EXISTS (
        SELECT 1
        FROM pg_constraint
        WHERE conname = 'invoice_error_finder_issues_status_check'
    ) THEN
        ALTER TABLE invoice_error_finder_issues
            DROP CONSTRAINT invoice_error_finder_issues_status_check;
    END IF;
END $$;

ALTER TABLE invoice_error_finder_issues
    ADD CONSTRAINT invoice_error_finder_issues_status_check
    CHECK (status IN (
        'open',
        'investigating',
        'approved_change',
        'error_found',
        'ready_to_invoice',
        'invoiced',
        'ignored',
        'resolved'
    ));
