Răsfoiți Sursa

Add _version to client get/find, fix migration max_versions parsing

- Add _version metadata field to get() and find() client responses
- Parse max_versions from migration JSON in migration_runner
- Update maxVersions on existing collections in createCollection()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Void User 5 luni în urmă
părinte
comite
c98d43e632

+ 12 - 6
client/src/client.cpp

@@ -117,7 +117,12 @@ public:
         }
         }
 
 
         auto json = nlohmann::json::parse(response.document().data());
         auto json = nlohmann::json::parse(response.document().data());
-        json["_id"] = response.document().id();  // Include document ID in returned data
+        json["_id"] = response.document().id();
+        json["_version"] = response.document().version();
+        json["_created_at"] = response.document().created_at();
+        json["_updated_at"] = response.document().updated_at();
+        json["_created_by"] = response.document().created_by();
+        json["_updated_by"] = response.document().updated_by();
         return json;
         return json;
     }
     }
 
 
@@ -279,11 +284,12 @@ public:
         results.reserve(response.documents_size());
         results.reserve(response.documents_size());
         for (const auto& doc : response.documents()) {
         for (const auto& doc : response.documents()) {
             auto json = nlohmann::json::parse(doc.data());
             auto json = nlohmann::json::parse(doc.data());
-            json["_id"] = doc.id();  // Include document ID in returned data
-            json["_created_at"] = doc.created_at();  // Creation timestamp (ms)
-            json["_updated_at"] = doc.updated_at();  // Last update timestamp (ms)
-            json["_created_by"] = doc.created_by();  // User ID who created
-            json["_updated_by"] = doc.updated_by();  // User ID who last updated
+            json["_id"] = doc.id();
+            json["_version"] = doc.version();
+            json["_created_at"] = doc.created_at();
+            json["_updated_at"] = doc.updated_at();
+            json["_created_by"] = doc.created_by();
+            json["_updated_by"] = doc.updated_by();
             results.push_back(json);
             results.push_back(json);
         }
         }
 
 

+ 8 - 1
service/src/memory_store.cpp

@@ -52,7 +52,14 @@ void MemoryStore::setPersistCallback(PersistCallback callback) {
 bool MemoryStore::createCollection(const std::string& name, const CollectionOptions& options) {
 bool MemoryStore::createCollection(const std::string& name, const CollectionOptions& options) {
     std::unique_lock<std::shared_mutex> lock(globalMutex_);
     std::unique_lock<std::shared_mutex> lock(globalMutex_);
 
 
-    if (collections_.find(name) != collections_.end()) {
+    auto it = collections_.find(name);
+    if (it != collections_.end()) {
+        // Update maxVersions on existing collection if specified
+        if (options.maxVersions > 0 && it->second->options.maxVersions != options.maxVersions) {
+            it->second->options.maxVersions = options.maxVersions;
+            it->second->updatedAt = currentTimeMs();
+            spdlog::info("Updated maxVersions for collection '{}' to {}", name, options.maxVersions);
+        }
         return false;  // Already exists
         return false;  // Already exists
     }
     }
 
 

+ 1 - 0
service/src/migrations/migration_runner.cpp

@@ -206,6 +206,7 @@ bool MigrationRunner::applyOperation(const nlohmann::json& operation) {
                 }
                 }
             }
             }
             options.defaultTtlSeconds = opts.value("default_ttl_seconds", 0U);
             options.defaultTtlSeconds = opts.value("default_ttl_seconds", 0U);
+            options.maxVersions = opts.value("max_versions", 0U);
         }
         }
 
 
         bool created = store_.createCollection(collection, options);
         bool created = store_.createCollection(collection, options);