Skip to main content

kmp_embedded/
migration.rs

1//! Store-migration compatibility API, composed over the embedded adapter.
2//!
3//! The live CLI does not expose a migration command because SQLite format 2
4//! is the only supported layout. These functions remain for downstream Rust
5//! API compatibility and always preserve unsupported sources.
6
7use std::path::Path;
8
9use kmp_adapter_embedded::{EmbeddedKernelStore, StorageEngine, StoreMigrationReceipt};
10use kmp_domain::PortError;
11
12pub async fn migrate_data_dir(
13    source_dir: &Path,
14    destination_dir: &Path,
15) -> Result<StoreMigrationReceipt, PortError> {
16    migrate_data_dir_to(source_dir, destination_dir, StorageEngine::Sqlite).await
17}
18
19pub async fn migrate_data_dir_to(
20    source_dir: &Path,
21    destination_dir: &Path,
22    destination_engine: StorageEngine,
23) -> Result<StoreMigrationReceipt, PortError> {
24    let (_store, receipt) = EmbeddedKernelStore::migrate_data_dir_to(
25        source_dir,
26        destination_dir,
27        destination_engine,
28        kmp_application::projection_mutations_for_context_event,
29    )
30    .await?;
31    Ok(receipt)
32}
33
34pub async fn open_or_migrate_data_dir(
35    source_dir: &Path,
36    destination_dir: &Path,
37) -> Result<Option<StoreMigrationReceipt>, PortError> {
38    let (_store, receipt) = EmbeddedKernelStore::open_or_migrate_data_dir(
39        source_dir,
40        destination_dir,
41        kmp_application::projection_mutations_for_context_event,
42    )
43    .await?;
44    Ok(receipt)
45}