mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 12:05:05 +08:00
Allow to introduce attributes only at the end of a schema
This commit is contained in:
parent
c4087e2ec2
commit
20319f7974
@ -97,7 +97,7 @@ pub enum UnsupportedOperation {
|
|||||||
SchemaAlreadyExists,
|
SchemaAlreadyExists,
|
||||||
CannotUpdateSchemaIdentifier,
|
CannotUpdateSchemaIdentifier,
|
||||||
CannotReorderSchemaAttribute,
|
CannotReorderSchemaAttribute,
|
||||||
CannotIntroduceNewSchemaAttribute,
|
CanOnlyIntroduceNewSchemaAttributesAtEnd,
|
||||||
CannotRemoveSchemaAttribute,
|
CannotRemoveSchemaAttribute,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,8 +108,8 @@ impl fmt::Display for UnsupportedOperation {
|
|||||||
SchemaAlreadyExists => write!(f, "Cannot update index which already have a schema"),
|
SchemaAlreadyExists => write!(f, "Cannot update index which already have a schema"),
|
||||||
CannotUpdateSchemaIdentifier => write!(f, "Cannot update the identifier of a schema"),
|
CannotUpdateSchemaIdentifier => write!(f, "Cannot update the identifier of a schema"),
|
||||||
CannotReorderSchemaAttribute => write!(f, "Cannot reorder the attributes of a schema"),
|
CannotReorderSchemaAttribute => write!(f, "Cannot reorder the attributes of a schema"),
|
||||||
CannotIntroduceNewSchemaAttribute => {
|
CanOnlyIntroduceNewSchemaAttributesAtEnd => {
|
||||||
write!(f, "Cannot introduce new attributes in a schema")
|
write!(f, "Can only introduce new attributes at end of a schema")
|
||||||
}
|
}
|
||||||
CannotRemoveSchemaAttribute => write!(f, "Cannot remove attributes from a schema"),
|
CannotRemoveSchemaAttribute => write!(f, "Cannot remove attributes from a schema"),
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ pub fn apply_schema_update(
|
|||||||
docs_words_store: store::DocsWords,
|
docs_words_store: store::DocsWords,
|
||||||
) -> MResult<()> {
|
) -> MResult<()> {
|
||||||
use UnsupportedOperation::{
|
use UnsupportedOperation::{
|
||||||
CannotIntroduceNewSchemaAttribute, CannotRemoveSchemaAttribute,
|
CanOnlyIntroduceNewSchemaAttributesAtEnd, CannotRemoveSchemaAttribute,
|
||||||
CannotReorderSchemaAttribute, CannotUpdateSchemaIdentifier,
|
CannotReorderSchemaAttribute, CannotUpdateSchemaIdentifier,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -33,7 +33,12 @@ pub fn apply_schema_update(
|
|||||||
need_full_reindexing = true;
|
need_full_reindexing = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Diff::NewAttr { .. } => return Err(CannotIntroduceNewSchemaAttribute.into()),
|
Diff::NewAttr { pos, .. } => {
|
||||||
|
// new attribute not at the end of the schema
|
||||||
|
if pos < old_schema.number_of_attributes() {
|
||||||
|
return Err(CanOnlyIntroduceNewSchemaAttributesAtEnd.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
Diff::RemovedAttr { .. } => return Err(CannotRemoveSchemaAttribute.into()),
|
Diff::RemovedAttr { .. } => return Err(CannotRemoveSchemaAttribute.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,10 @@ impl Schema {
|
|||||||
attributes
|
attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn number_of_attributes(&self) -> usize {
|
||||||
|
self.inner.attrs.len()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn props(&self, attr: SchemaAttr) -> SchemaProps {
|
pub fn props(&self, attr: SchemaAttr) -> SchemaProps {
|
||||||
let (_, props) = self.inner.props[attr.0 as usize];
|
let (_, props) = self.inner.props[attr.0 as usize];
|
||||||
props
|
props
|
||||||
|
Loading…
Reference in New Issue
Block a user