//! writes nothing on purpose. the bump makes an older build refuse the db at open instead of
//! failing every metadata read. don't drop it as a no-op
use fjall::OwnedWriteBatch;
use miette::Result;
use crate::db::Db;
pub(super) fn repo_metadata_refetch(_db: &Db, _batch: &mut OwnedWriteBatch) -> Result<bool> {
Ok(true)
}
#[cfg(all(test, feature = "indexer"))]
mod tests {
use crate::config::Config;
use crate::db::keys::{self, VERSIONING_KEY};
use crate::db::migration::{LATEST_VERSION, migration_applied_key};
use crate::db::{Db, deser_repo_meta};
use crate::types::v14;
use jacquard_common::types::did::Did;
use miette::{IntoDiagnostic, Result};
use tempfile::tempdir;
#[test]
fn a_v15_database_opens_at_v16_with_its_metadata_rows_untouched() -> Result<()> {
let tmp = tempdir().into_diagnostic()?;
let cfg = Config {
database_path: tmp.path().to_path_buf(),
..Default::default()
};
let did = Did::new_static("did:plc:ewvi7nxzyoun6zhxrhs64oiz").into_diagnostic()?;
let old_row = rmp_serde::to_vec(&v14::RepoMetadata {
tracked: true,
index_id: 7,
retry_count: 2,
relay_inactive: None,
backfilled_rev: None,
})
.into_diagnostic()?;
{
let db = Db::open(&cfg)?;
db.repo_metadata
.insert(keys::repo_metadata_key(&did), &old_row)
.into_diagnostic()?;
let mut batch = db.inner.batch();
batch.remove(&db.counts, migration_applied_key("repo_metadata_refetch"));
batch.insert(&db.counts, VERSIONING_KEY, 15_u64.to_be_bytes());
batch.commit().into_diagnostic()?;
db.persist()?;
}
let db = Db::open(&cfg)?;
let version = db
.counts
.get(VERSIONING_KEY)
.into_diagnostic()?
.expect("schema version");
assert_eq!(
u64::from_be_bytes(version.as_ref().try_into().into_diagnostic()?),
LATEST_VERSION
);
let row = db
.repo_metadata
.get(keys::repo_metadata_key(&did))
.into_diagnostic()?
.expect("metadata row");
assert_eq!(row.as_ref(), old_row.as_slice());
let metadata = deser_repo_meta(&row)?;
assert_eq!(metadata.retry_count, 2);
assert_eq!(metadata.refetch, None);
assert!(!metadata.refetch_deferred);
Ok(())
}
}