BEGIN;

DROP INDEX IF EXISTS idx_daily_checklists_unique_non_rejected;
DROP INDEX IF EXISTS idx_daily_checklists_deleted_at;
DROP INDEX IF EXISTS idx_daily_checklists_deleted_by;

ALTER TABLE daily_checklists
    DROP CONSTRAINT IF EXISTS fk_daily_checklists_deleted_by;

ALTER TABLE daily_checklists
    DROP COLUMN IF EXISTS deleted_at,
    DROP COLUMN IF EXISTS deleted_by;

ALTER TABLE daily_checklists
    DROP CONSTRAINT IF EXISTS daily_checklists_date_kandang_category_key;

CREATE UNIQUE INDEX IF NOT EXISTS idx_daily_checklists_unique_non_rejected
    ON daily_checklists (date, kandang_id, category)
    WHERE (status IS NULL OR status <> 'REJECTED');

COMMIT;
