private void copyIndexShards(final Connection connection,
                                 final Map<String, VolumeGroup> indexUuidToVolumeGroupMap,
                                 final Map<Integer, OldVolume> oldVolumes) {
        final String selectSql = "" +
                "SELECT " +
                "s.ID, " +
                "n.NAME, " +
                "s.FK_VOL_ID, " +
                "s.OLD_IDX_ID, " +
                "s.IDX_UUID, " +
                "s.CMT_DOC_CT, " +
                "s.CMT_DUR_MS, " +
                "s.CMT_MS, " +
                "s.DOC_CT, " +
                "s.FILE_SZ, " +
                "s.STAT, " +
                "s.IDX_VER, " +
                "s.PART, " +
                "s.PART_FROM_MS, " +
                "s.PART_TO_MS " +
                "FROM OLD_IDX_SHRD s " +
                "INNER JOIN OLD_ND n ON(n.ID = s.FK_ND_ID)";

        final String insertSql = "" +
                "INSERT INTO index_shard (" +
                "id, " +
                "node_name, " +
                "fk_volume_id, " +
                "index_uuid, " +
                "commit_document_count, " +
                "commit_duration_ms, " +
                "commit_ms, " +
                "document_count, " +
                "file_size, " +
                "status, " +
                "index_version, " +
                "partition_name, " +
                "partition_from_ms, " +
                "partition_to_ms) " +
                "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

        try (final PreparedStatement insert = connection.prepareStatement(insertSql)) {
            try (final PreparedStatement select = connection.prepareStatement(selectSql)) {
                try (final ResultSet resultSet = select.executeQuery()) {
                    while (resultSet.next()) {
                        final Long id = DbUtil.getLong(resultSet, 1);
                        final String nodeName = resultSet.getString(2);
                        final Integer volumeId = DbUtil.getInteger(resultSet, 3);
                        final Integer oldIndexId = DbUtil.getInteger(resultSet, 4);
                        final String indexUuid = resultSet.getString(5);
                        final Integer commitDocumentCount = DbUtil.getInteger(resultSet, 6);
                        final Long commitDurationMs = DbUtil.getLong(resultSet, 7);
                        final Long commitMs = DbUtil.getLong(resultSet, 8);
                        final Integer documentCount = DbUtil.getInteger(resultSet, 9);
                        final Long fileSize = DbUtil.getLong(resultSet, 10);
                        final Byte status = DbUtil.getByte(resultSet, 11);
                        final String indexVersion = resultSet.getString(12);
                        final String part = resultSet.getString(13);
                        final Long partFrom = DbUtil.getLong(resultSet, 14);
                        final Long partTo = DbUtil.getLong(resultSet, 15);

                        // Get target volume id.
                        final OldVolume oldVolume = oldVolumes.get(volumeId);
                        Objects.requireNonNull(oldVolume,
                                "oldVolume should not be null for volumeId " + volumeId);

                        final VolumeGroup volumeGroup = indexUuidToVolumeGroupMap.get(indexUuid);
                        Objects.requireNonNull(volumeGroup,
                                "volumeGroup should not be null for indexUuid " + indexUuid);

                        final Integer newVolumeId = volumeGroup.oldToNewVolumeIdMapping.get(volumeId);
                        Objects.requireNonNull(newVolumeId,
                                "newVolumeId should not be null for volumeId " + volumeId);

                        // Move shard.
                        moveShard(oldVolume.path, oldIndexId, indexUuid);

                        try {
                            DbUtil.setLong(insert, 1, id);
                            insert.setString(2, nodeName);
                            DbUtil.setInteger(insert, 3, newVolumeId);
                            insert.setString(4, indexUuid);
                            DbUtil.setInteger(insert, 5, commitDocumentCount);
                            DbUtil.setLong(insert, 6, commitDurationMs);
                            DbUtil.setLong(insert, 7, commitMs);
                            DbUtil.setInteger(insert, 8, documentCount);
                            DbUtil.setLong(insert, 9, fileSize);
                            DbUtil.setByte(insert, 10, status);
                            insert.setString(11, indexVersion);
                            insert.setString(12, part);
                            DbUtil.setLong(insert, 13, partFrom);
                            DbUtil.setLong(insert, 14, partTo);
                            insert.executeUpdate();
                        } catch (final SQLException e) {
                            throw new RuntimeException("Error creating index shard with id " + id +
                                    " and uuid " + indexUuid +
                                    ": " + e.getMessage(), e);
                        }
                    }
                }
            }
        } catch (final SQLException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
@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