-- Recreate CrewActionType: add explicit return/decline/delete audit types and
-- drop the unused GATE_FAILED value (see Crewing audit-trail consistency cleanup,
-- spec §11). One recreate adds + removes in a single migration.
BEGIN;
CREATE TYPE "CrewActionType_new" AS ENUM (
  'REQUISITION_RAISED',
  'REQUISITION_ADVANCED',
  'REQUISITION_FILLED',
  'REQUISITION_CANCELLED',
  'RELIEF_REQUESTED',
  'RELIEF_CONVERTED',
  'RELIEF_CANCELLED',
  'CANDIDATE_ADDED',
  'CANDIDATE_UPDATED',
  'APPLICATION_CREATED',
  'GATE_PASSED',
  'REFERENCE_RECORDED',
  'SALARY_AGREED',
  'SALARY_APPROVED',
  'SALARY_RETURNED',
  'CANDIDATE_PROPOSED',
  'INTERVIEW_RECORDED',
  'WAIVER_REQUESTED',
  'WAIVER_APPROVED',
  'WAIVER_DECLINED',
  'CANDIDATE_SELECTED',
  'SELECTION_RETURNED',
  'APPLICATION_REJECTED',
  'CREW_ONBOARDED',
  'DOCUMENT_UPLOADED',
  'RECORD_UPDATED',
  'RECORD_DELETED',
  'PPE_ISSUED',
  'PPE_RETURNED',
  'EXPERIENCE_ADDED',
  'LEAVE_APPLIED',
  'LEAVE_DECIDED',
  'ATTENDANCE_RECORDED',
  'CREW_SIGNED_OFF',
  'RECORD_VERIFIED',
  'RECORD_REJECTED',
  'APPRAISAL_SUBMITTED',
  'APPRAISAL_VERIFIED',
  'APPRAISAL_APPROVED',
  'APPRAISAL_REJECTED'
);
ALTER TABLE "CrewAction" ALTER COLUMN "actionType" TYPE "CrewActionType_new" USING ("actionType"::text::"CrewActionType_new");
ALTER TYPE "CrewActionType" RENAME TO "CrewActionType_old";
ALTER TYPE "CrewActionType_new" RENAME TO "CrewActionType";
DROP TYPE "CrewActionType_old";
COMMIT;
