private void migrateIndexDocs(final Connection connection,
                                  final Map<String, VolumeGroup> indexUuidToVolumeGroupMap) throws Exception {
        final IndexSerialiser serialiser = new IndexSerialiser(new Serialiser2FactoryImpl());

        final String selectSql = "" +
                "SELECT" +
                "  CRT_MS," +
                "  CRT_USER," +
                "  UPD_MS," +
                "  UPD_USER," +
                "  NAME," +
                "  UUID," +
                "  DESCRIP," +
                "  MAX_DOC," +
                "  MAX_SHRD," +
                "  PART_BY," +
                "  PART_SZ," +
                "  RETEN_DAY_AGE," +
                "  FLDS " +
                "FROM OLD_IDX";

        final String insertSql = "" +
                " INSERT INTO doc (" +
                " type," +
                " uuid," +
                " name," +
                " ext," +
                " data)" +
                " 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 crtMs = DbUtil.getLong(resultSet, 1);
                        final String crtUser = resultSet.getString(2);
                        final Long updMs = DbUtil.getLong(resultSet, 3);
                        final String updUser = resultSet.getString(4);
                        final String name = resultSet.getString(5);
                        final String uuid = resultSet.getString(6);
                        final String descrip = resultSet.getString(7);
                        final Integer maxDoc = DbUtil.getInteger(resultSet, 8);
                        final Integer maxShrd = DbUtil.getInteger(resultSet, 9);
                        final Byte partBy = DbUtil.getByte(resultSet, 10);
                        final Integer partSz = DbUtil.getInteger(resultSet, 11);
                        final Integer retenDayAge = DbUtil.getInteger(resultSet, 12);
                        final String fields = resultSet.getString(13);

                        final PartitionBy newPartitionBy = partBy == null
                                ? null
                                : Optional.ofNullable(
                                        Index.PartitionBy.PRIMITIVE_VALUE_CONVERTER.fromPrimitiveValue(partBy))
                                        .map(legacyPartitionBy ->
                                                LuceneIndexDoc.PartitionBy.valueOf(legacyPartitionBy.name()))
                                        .orElse(null);

                        final LuceneIndexDoc document = new LuceneIndexDoc();
                        document.setType(LuceneIndexDoc.TYPE);
                        document.setUuid(uuid);
                        document.setName(name);
                        document.setVersion(UUID.randomUUID().toString());
                        document.setCreateTimeMs(crtMs);
                        document.setUpdateTimeMs(updMs);
                        document.setCreateUser(crtUser);
                        document.setUpdateUser(updUser);
                        document.setDescription(descrip);
                        if (maxDoc != null) {
                            document.setMaxDocsPerShard(maxDoc);
                        }
                        if (maxShrd != null) {
                            document.setShardsPerPartition(maxShrd);
                        }
                        document.setPartitionBy(newPartitionBy);
                        if (partSz != null) {
                            document.setPartitionSize(partSz);
                        }
                        document.setRetentionDayAge(retenDayAge);
                        document.setFields(MappingUtil.map(LegacyXmlSerialiser.getIndexFieldsFromLegacyXml(fields)));
                        Optional.ofNullable(indexUuidToVolumeGroupMap.get(uuid))
                                .map(VolumeGroup::getName)
                                .ifPresent(document::setVolumeGroupName);

                        final Map<String, byte[]> dataMap = serialiser.write(document);

                        // Add the records.
                        dataMap.forEach((k, v) -> {
                            try {
                                insert.setString(1, LuceneIndexDoc.TYPE);
                                insert.setString(2, uuid);
                                insert.setString(3, name);
                                insert.setString(4, k);
                                insert.setBytes(5, v);
                                insert.executeUpdate();
                            } 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