MeiliSearch/meilidb-core/src/update/schema_update.rs

32 lines
877 B
Rust
Raw Normal View History

2019-10-18 13:05:28 +02:00
use crate::update::{next_update_id, Update};
use crate::{error::UnsupportedOperation, store, MResult};
use meilidb_schema::Schema;
pub fn apply_schema_update(
2019-10-16 17:05:24 +02:00
writer: &mut zlmdb::RwTxn,
main_store: store::Main,
new_schema: &Schema,
2019-10-18 13:05:28 +02:00
) -> MResult<()> {
2019-10-18 13:21:41 +02:00
if main_store.schema(writer)?.is_some() {
2019-10-18 13:05:28 +02:00
return Err(UnsupportedOperation::SchemaAlreadyExists.into());
}
2019-10-18 13:05:28 +02:00
main_store
.put_schema(writer, new_schema)
.map_err(Into::into)
}
pub fn push_schema_update(
2019-10-16 17:05:24 +02:00
writer: &mut zlmdb::RwTxn,
updates_store: store::Updates,
updates_results_store: store::UpdatesResults,
schema: Schema,
2019-10-18 13:05:28 +02:00
) -> MResult<u64> {
let last_update_id = next_update_id(writer, updates_store, updates_results_store)?;
let update = Update::Schema(schema);
2019-10-08 17:31:07 +02:00
updates_store.put_update(writer, last_update_id, &update)?;
Ok(last_update_id)
}