[tx] Don't treat :db/doc as defining a schema attribute. (#784) r=grisha
This commit is contained in:
commit
e9cddd63e4
3 changed files with 21 additions and 18 deletions
16
db/src/db.rs
16
db/src/db.rs
|
@ -1498,6 +1498,22 @@ mod tests {
|
||||||
[200 :db.schema/attribute 101]]");
|
[200 :db.schema/attribute 101]]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_db_doc_is_not_schema() {
|
||||||
|
let mut conn = TestConn::default();
|
||||||
|
|
||||||
|
// Neither transaction below is defining a new attribute. That is, it's fine to use :db/doc
|
||||||
|
// to describe any entity in the system, not just attributes. And in particular, including
|
||||||
|
// :db/doc shouldn't make the transactor consider the entity a schema attribute.
|
||||||
|
assert_transact!(conn, r#"
|
||||||
|
[{:db/doc "test"}]
|
||||||
|
"#);
|
||||||
|
|
||||||
|
assert_transact!(conn, r#"
|
||||||
|
[{:db/ident :test/id :db/doc "test"}]
|
||||||
|
"#);
|
||||||
|
}
|
||||||
|
|
||||||
// Unique is required!
|
// Unique is required!
|
||||||
#[test]
|
#[test]
|
||||||
fn test_upsert_issue_538() {
|
fn test_upsert_issue_538() {
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub const DB_SCHEMA_CORE: Entid = 40;
|
||||||
/// Return `false` if the given attribute will not change the metadata: recognized idents, schema,
|
/// Return `false` if the given attribute will not change the metadata: recognized idents, schema,
|
||||||
/// partitions in the partition map.
|
/// partitions in the partition map.
|
||||||
pub fn might_update_metadata(attribute: Entid) -> bool {
|
pub fn might_update_metadata(attribute: Entid) -> bool {
|
||||||
if attribute > DB_DOC {
|
if attribute >= DB_DOC {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
match attribute {
|
match attribute {
|
||||||
|
@ -69,7 +69,6 @@ pub fn might_update_metadata(attribute: Entid) -> bool {
|
||||||
DB_IDENT |
|
DB_IDENT |
|
||||||
// Schema.
|
// Schema.
|
||||||
DB_CARDINALITY |
|
DB_CARDINALITY |
|
||||||
DB_DOC |
|
|
||||||
DB_FULLTEXT |
|
DB_FULLTEXT |
|
||||||
DB_INDEX |
|
DB_INDEX |
|
||||||
DB_IS_COMPONENT |
|
DB_IS_COMPONENT |
|
||||||
|
@ -89,9 +88,8 @@ lazy_static! {
|
||||||
|
|
||||||
/// Attributes that are "schema related". These might change the "schema" materialized view.
|
/// Attributes that are "schema related". These might change the "schema" materialized view.
|
||||||
pub static ref SCHEMA_SQL_LIST: String = {
|
pub static ref SCHEMA_SQL_LIST: String = {
|
||||||
format!("({}, {}, {}, {}, {}, {}, {})",
|
format!("({}, {}, {}, {}, {}, {})",
|
||||||
DB_CARDINALITY,
|
DB_CARDINALITY,
|
||||||
DB_DOC,
|
|
||||||
DB_FULLTEXT,
|
DB_FULLTEXT,
|
||||||
DB_INDEX,
|
DB_INDEX,
|
||||||
DB_IS_COMPONENT,
|
DB_IS_COMPONENT,
|
||||||
|
@ -101,9 +99,8 @@ lazy_static! {
|
||||||
|
|
||||||
/// Attributes that are "metadata" related. These might change one of the materialized views.
|
/// Attributes that are "metadata" related. These might change one of the materialized views.
|
||||||
pub static ref METADATA_SQL_LIST: String = {
|
pub static ref METADATA_SQL_LIST: String = {
|
||||||
format!("({}, {}, {}, {}, {}, {}, {}, {})",
|
format!("({}, {}, {}, {}, {}, {}, {})",
|
||||||
DB_CARDINALITY,
|
DB_CARDINALITY,
|
||||||
DB_DOC,
|
|
||||||
DB_FULLTEXT,
|
DB_FULLTEXT,
|
||||||
DB_IDENT,
|
DB_IDENT,
|
||||||
DB_INDEX,
|
DB_INDEX,
|
||||||
|
|
|
@ -121,11 +121,8 @@ pub fn update_attribute_map_from_entid_triples<A, R>(attribute_map: &mut Attribu
|
||||||
for (entid, attr, ref value) in retractions.into_iter() {
|
for (entid, attr, ref value) in retractions.into_iter() {
|
||||||
let builder = builders.entry(entid).or_insert_with(|| attribute_builder_to_modify(entid, attribute_map));
|
let builder = builders.entry(entid).or_insert_with(|| attribute_builder_to_modify(entid, attribute_map));
|
||||||
match attr {
|
match attr {
|
||||||
// You can only retract :db/unique, :db/doc, :db/isComponent; all others
|
// You can only retract :db/unique, :db/isComponent; all others must be altered instead
|
||||||
// must be altered instead of retracted, or are not allowed to change.
|
// of retracted, or are not allowed to change.
|
||||||
entids::DB_DOC => {
|
|
||||||
// Nothing to do here; we don't keep docstrings inside `Attribute`s.
|
|
||||||
},
|
|
||||||
entids::DB_IS_COMPONENT => {
|
entids::DB_IS_COMPONENT => {
|
||||||
match value {
|
match value {
|
||||||
&TypedValue::Boolean(v) if builder.component == Some(v) => {
|
&TypedValue::Boolean(v) if builder.component == Some(v) => {
|
||||||
|
@ -166,13 +163,6 @@ pub fn update_attribute_map_from_entid_triples<A, R>(attribute_map: &mut Attribu
|
||||||
|
|
||||||
// TODO: improve error messages throughout.
|
// TODO: improve error messages throughout.
|
||||||
match attr {
|
match attr {
|
||||||
entids::DB_DOC => {
|
|
||||||
match *value {
|
|
||||||
TypedValue::String(_) => {},
|
|
||||||
_ => bail!(DbErrorKind::BadSchemaAssertion(format!("Expected [... :db/doc \"string value\"] but got [... :db/doc {:?}] for entid {} and attribute {}", value, entid, attr)))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
entids::DB_VALUE_TYPE => {
|
entids::DB_VALUE_TYPE => {
|
||||||
match *value {
|
match *value {
|
||||||
TypedValue::Ref(entids::DB_TYPE_BOOLEAN) => { builder.value_type(ValueType::Boolean); },
|
TypedValue::Ref(entids::DB_TYPE_BOOLEAN) => { builder.value_type(ValueType::Boolean); },
|
||||||
|
|
Loading…
Reference in a new issue