Closed DarkAtra closed 4 months ago
This might do the trick:
Subject: [PATCH] bug: migration from 3.x to 4.x with MVStore module fails
---
Index: nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java
--- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java (revision 03fd0f7cc41c6ba1f6cbf13a56ccbf08700a2b7d)
+++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java (revision 9f1f34ecb9e3d48a68fb53c6be7da3f7eaaf20e9)
@@ -190,7 +190,13 @@
Document document = Document.createDocument();
for (Map.Entry<String, Object> entry : value.entrySet()) {
Object val = entry.getValue();
- Object migratedVal = migrateValue(val);
+
+ Object migratedVal;
+ if (DOC_ID.equals(entry.getKey())) {
+ migratedVal = Long.toString((long) val);
+ } else {
+ migratedVal = migrateValue(val);
+ }
document.put(entry.getKey(), migratedVal);
}
return document;
Thanks for reporting this issue and providing the solution as well. This fix will be in 4.3.0-SNAPSHOT in a while.
The wiki states that
However, it seems like it fails to migrate document ids correctly. Version 3.x uses a Long to represent the internal document
_id
. In version 4.x this code changed to use a String instead. When using version 4.x to read a database that was created with version 3.x the following exception occurs when updating a document:Test case (includes a v3 database): https://github.com/DarkAtra/nitrite-java/blob/bug/id-migration-for-old-documents-fails/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java#L449-L479
Steps to reproduce:
update
to persist the changesIs this expected? If so, what would be the best way for me to update existing documents so that they function correctly with version 4.x of nitrite?