DO $$
BEGIN
  IF NOT EXISTS (
    SELECT 1
    FROM pg_type
    WHERE typname = 'organization_member_status_enum'
  ) THEN
    CREATE TYPE organization_member_status_enum AS ENUM ('PENDING', 'ACTIVE');
  END IF;
END $$;

ALTER TABLE organization_members
ADD COLUMN IF NOT EXISTS status organization_member_status_enum;

UPDATE organization_members
SET status = 'ACTIVE'
WHERE status IS NULL;

ALTER TABLE organization_members
ALTER COLUMN status SET DEFAULT 'ACTIVE';

ALTER TABLE organization_members
ALTER COLUMN status SET NOT NULL;
