Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(storage): add config record upgrade logic

Steven Enamakel678e1f3711a7
diff --git a/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs b/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs
index 80329457d8..3a27acac15 100644
--- a/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs
@@ -7,7 +7,7 @@
use tinystoragedrivers::CollectionSpec;
-use crate::storage::schema_support::key_of;
+use crate::storage::schema_support::{key_of, map_legacy_collection, LegacyTargetRecord};
/// The v2 collection holding one config document per scope.
pub(crate) const CONFIG_COLLECTION: &str = "config.documents";
@@ -18,6 +18,25 @@ pub(crate) fn collection_specs() -> Vec<CollectionSpec> {
vec![CollectionSpec::new(CONFIG_COLLECTION)]
}
+/// Converts the previous per-scope config document into its owner collection.
+pub(crate) fn upgrade_records(
+ records: Vec<crate::storage::import::Record>,
+) -> anyhow::Result<Vec<crate::storage::import::Record>> {
+ map_legacy_collection(records, LEGACY_CONFIG_COLLECTION, |batch| {
+ batch
+ .into_iter()
+ .map(|record| {
+ Ok(LegacyTargetRecord::new(
+ CONFIG_COLLECTION,
+ key_of(&record.id)?,
+ record.body,
+ )
+ .created_ms(record.meta.created_ms))
+ })
+ .collect()
+ })
+}
+
/// The document id of the config of `scope`.
///
/// # Errors
diff --git a/crates/openhuman-core/src/storage/schema_support.rs b/crates/openhuman-core/src/storage/schema_support.rs
index e35b7ab8d0..a39a5a46cb 100644
--- a/crates/openhuman-core/src/storage/schema_support.rs
+++ b/crates/openhuman-core/src/storage/schema_support.rs
@@ -14,13 +14,7 @@ use crate::storage::import::Record;
pub(crate) struct LegacySourceRecord {
pub id: String,
pub body: Value,
- pub meta: LegacySourceMeta,
-}
-
-/// Metadata carried into an owner conversion from the source reader.
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub(crate) struct LegacySourceMeta {
- pub created_ms: i64,
+ pub meta: tinystoragedrivers::Meta,
}
/// Target row emitted by a typed owner import conversion.
@@ -65,8 +59,9 @@ where
source.push(LegacySourceRecord {
id: record.id,
body: record.doc,
- meta: LegacySourceMeta {
+ meta: tinystoragedrivers::Meta {
created_ms: record.created_ms.unwrap_or_default(),
+ ..tinystoragedrivers::Meta::unknown()
},
});
} else {