2019-10-18 13:05:28 +02:00
|
|
|
use crate::update::{next_update_id, Update};
|
|
|
|
use crate::{error::UnsupportedOperation, store, MResult};
|
2019-10-07 17:48:26 +02:00
|
|
|
use meilidb_schema::Schema;
|
|
|
|
|
|
|
|
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,
|
2019-10-18 13:05:28 +02:00
|
|
|
) -> MResult<()> {
|
2019-10-07 17:48:26 +02:00
|
|
|
if let Some(_) = main_store.schema(writer)? {
|
2019-10-18 13:05:28 +02:00
|
|
|
return Err(UnsupportedOperation::SchemaAlreadyExists.into());
|
2019-10-07 17:48:26 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 13:05:28 +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,
|
2019-10-18 13:05:28 +02:00
|
|
|
) -> MResult<u64> {
|
2019-10-08 17:24:11 +02:00
|
|
|
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)
|
|
|
|
}
|