DO $$
BEGIN
  IF NOT EXISTS (
    SELECT 1
    FROM pg_enum e
    JOIN pg_type t ON t.oid = e.enumtypid
    WHERE t.typname = 'membership_plan_tier_enum'
      AND e.enumlabel = 'YOUTH'
  ) THEN
    ALTER TYPE membership_plan_tier_enum ADD VALUE 'YOUTH';
  END IF;

  IF NOT EXISTS (
    SELECT 1
    FROM pg_enum e
    JOIN pg_type t ON t.oid = e.enumtypid
    WHERE t.typname = 'membership_plan_tier_enum'
      AND e.enumlabel = 'COMMUNITY'
  ) THEN
    ALTER TYPE membership_plan_tier_enum ADD VALUE 'COMMUNITY';
  END IF;

  IF NOT EXISTS (
    SELECT 1
    FROM pg_enum e
    JOIN pg_type t ON t.oid = e.enumtypid
    WHERE t.typname = 'membership_plan_tier_enum'
      AND e.enumlabel = 'EDUCATION'
  ) THEN
    ALTER TYPE membership_plan_tier_enum ADD VALUE 'EDUCATION';
  END IF;

  IF NOT EXISTS (
    SELECT 1
    FROM pg_enum e
    JOIN pg_type t ON t.oid = e.enumtypid
    WHERE t.typname = 'membership_plan_tier_enum'
      AND e.enumlabel = 'GRASSROOT'
  ) THEN
    ALTER TYPE membership_plan_tier_enum ADD VALUE 'GRASSROOT';
  END IF;

  IF NOT EXISTS (
    SELECT 1
    FROM pg_enum e
    JOIN pg_type t ON t.oid = e.enumtypid
    WHERE t.typname = 'membership_plan_tier_enum'
      AND e.enumlabel = 'WORKER'
  ) THEN
    ALTER TYPE membership_plan_tier_enum ADD VALUE 'WORKER';
  END IF;

  IF NOT EXISTS (
    SELECT 1
    FROM pg_enum e
    JOIN pg_type t ON t.oid = e.enumtypid
    WHERE t.typname = 'membership_plan_tier_enum'
      AND e.enumlabel = 'IMPACT'
  ) THEN
    ALTER TYPE membership_plan_tier_enum ADD VALUE 'IMPACT';
  END IF;

  IF NOT EXISTS (
    SELECT 1
    FROM pg_enum e
    JOIN pg_type t ON t.oid = e.enumtypid
    WHERE t.typname = 'membership_plan_tier_enum'
      AND e.enumlabel = 'SPONSOR'
  ) THEN
    ALTER TYPE membership_plan_tier_enum ADD VALUE 'SPONSOR';
  END IF;
END $$;

DROP INDEX IF EXISTS membership_plans_non_org_type_tier_uidx;
DROP INDEX IF EXISTS membership_plans_org_type_tier_uidx;
DROP INDEX IF EXISTS membership_plans_org_legacy_tier_uidx;
