private Map<String, Set<Integer>> getVolumesToMigrate(final Connection connection) throws Exception {
        final Map<String, Set<Integer>> indexUuidToVolumeIdListMap = new HashMap<>();

        // Add all current index volumes associated with an index.
        try (final PreparedStatement preparedStatement = connection.prepareStatement(
                "SELECT " +
                        "IDX_UUID, " +
                        "FK_VOL_ID " +
                        "FROM " +
                        "OLD_IDX_VOL")) {

            try (final ResultSet resultSet = preparedStatement.executeQuery()) {
                while (resultSet.next()) {
                    final String indexUuid = resultSet.getString(1);
                    final int volId = resultSet.getInt(2);
                    indexUuidToVolumeIdListMap.computeIfAbsent(indexUuid, k -> new HashSet<>())
                            .add(volId);
                }
            }
        }

        // Add any historic index volumes.

        // NOTE ois.FK_IDX_ID is renamed in V07_00_00_017__IDX_SHRD.sql to OLD_IDX_ID
        // There is no FK constraint on OLD_IDX_ID so it is possible we may ignore shards with no
        // corresponding idx, but there was an FK in V07_00_00_017__IDX_SHRD.sql so as long as we have
        // not deleted idxc recs since then we are ok.
        final String indexShardVolsSql =
                "SELECT DISTINCT " +
                        "  oi.UUID, " +
                        "  ois.FK_VOL_ID " +
                        "FROM " +
                        "OLD_IDX_SHRD ois " +
                        "JOIN OLD_IDX oi ON (oi.ID = ois.OLD_IDX_ID) ";
        try (final PreparedStatement preparedStatement = connection.prepareStatement(indexShardVolsSql)) {

            try (final ResultSet resultSet = preparedStatement.executeQuery()) {
                while (resultSet.next()) {
                    final String indexUuid = resultSet.getString(1);
                    final int volId = resultSet.getInt(2);
                    indexUuidToVolumeIdListMap.computeIfAbsent(indexUuid, k -> new HashSet<>())
                            .add(volId);
                }
            }
        }

        return indexUuidToVolumeIdListMap;
    }
@return A map of index UUIDs to lists of the volumes they use. We'll need both, hence the map.
stroom-legacy/stroom-legacy-db-migration/src/main/java/stroom/legacy/db/migration/V07_00_00_1502__Index.java