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