fixed immutability effects in merger
This commit is contained in:
@ -6,8 +6,8 @@ pub mod cache;
|
|||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use crate::database::r#type::Type;
|
use crate::database::r#type::Type;
|
||||||
use crate::drop::{Drop, Error, ErrorDetails};
|
use crate::drop::{Drop, Error, ErrorDetails};
|
||||||
use serde_json::Value;
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
use serde_json::Value;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Merger {
|
pub struct Merger {
|
||||||
@ -31,9 +31,10 @@ impl Merger {
|
|||||||
None => {
|
None => {
|
||||||
return Drop::with_errors(vec![Error {
|
return Drop::with_errors(vec![Error {
|
||||||
code: "SCHEMA_NOT_FOUND".to_string(),
|
code: "SCHEMA_NOT_FOUND".to_string(),
|
||||||
values: Some(IndexMap::from([
|
values: Some(IndexMap::from([(
|
||||||
("schema".to_string(), schema_id.to_string()),
|
"schema".to_string(),
|
||||||
])),
|
schema_id.to_string(),
|
||||||
|
)])),
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
path: None,
|
path: None,
|
||||||
cause: None,
|
cause: None,
|
||||||
@ -56,9 +57,7 @@ impl Merger {
|
|||||||
if let Err(e) = self.db.execute(¬ify_sql, None) {
|
if let Err(e) = self.db.execute(¬ify_sql, None) {
|
||||||
return Drop::with_errors(vec![Error {
|
return Drop::with_errors(vec![Error {
|
||||||
code: "MERGE_FAILED".to_string(),
|
code: "MERGE_FAILED".to_string(),
|
||||||
values: Some(IndexMap::from([
|
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||||
("error".to_string(), e.clone()),
|
|
||||||
])),
|
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
path: None,
|
path: None,
|
||||||
cause: Some(e),
|
cause: Some(e),
|
||||||
@ -121,9 +120,15 @@ impl Merger {
|
|||||||
} else {
|
} else {
|
||||||
return Err(Error {
|
return Err(Error {
|
||||||
code: "TARGET_SCHEMA_NOT_FOUND".to_string(),
|
code: "TARGET_SCHEMA_NOT_FOUND".to_string(),
|
||||||
values: Some(IndexMap::from([("target_id".to_string(), target_id.clone())])),
|
values: Some(IndexMap::from([(
|
||||||
|
"target_id".to_string(),
|
||||||
|
target_id.clone(),
|
||||||
|
)])),
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
cause: Some(format!("Polymorphic mapped target '{}' not found in database registry", target_id)),
|
cause: Some(format!(
|
||||||
|
"Polymorphic mapped target '{}' not found in database registry",
|
||||||
|
target_id
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -141,7 +146,10 @@ impl Merger {
|
|||||||
code: "ONE_OF_INDEX_NOT_FOUND".to_string(),
|
code: "ONE_OF_INDEX_NOT_FOUND".to_string(),
|
||||||
values: Some(IndexMap::from([("index".to_string(), idx.to_string())])),
|
values: Some(IndexMap::from([("index".to_string(), idx.to_string())])),
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
cause: Some(format!("Polymorphic index target '{}' not found in local oneOf array", idx)),
|
cause: Some(format!(
|
||||||
|
"Polymorphic index target '{}' not found in local oneOf array",
|
||||||
|
idx
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -164,7 +172,10 @@ impl Merger {
|
|||||||
("value".to_string(), v.to_string()),
|
("value".to_string(), v.to_string()),
|
||||||
])),
|
])),
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
cause: Some(format!("Polymorphic discriminator {}='{}' matched no compiled options", disc, v)),
|
cause: Some(format!(
|
||||||
|
"Polymorphic discriminator {}='{}' matched no compiled options",
|
||||||
|
disc, v
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -172,9 +183,15 @@ impl Merger {
|
|||||||
} else {
|
} else {
|
||||||
return Err(Error {
|
return Err(Error {
|
||||||
code: "MISSING_DISCRIMINATOR".to_string(),
|
code: "MISSING_DISCRIMINATOR".to_string(),
|
||||||
values: Some(IndexMap::from([("discriminator".to_string(), disc.to_string())])),
|
values: Some(IndexMap::from([(
|
||||||
|
"discriminator".to_string(),
|
||||||
|
disc.to_string(),
|
||||||
|
)])),
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
cause: Some(format!("Polymorphic merging failed: missing required discriminator '{}'", disc)),
|
cause: Some(format!(
|
||||||
|
"Polymorphic merging failed: missing required discriminator '{}'",
|
||||||
|
disc
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -281,8 +298,6 @@ impl Merger {
|
|||||||
let mut entity_objects = std::collections::BTreeMap::new();
|
let mut entity_objects = std::collections::BTreeMap::new();
|
||||||
let mut entity_arrays = std::collections::BTreeMap::new();
|
let mut entity_arrays = std::collections::BTreeMap::new();
|
||||||
|
|
||||||
let is_external = self.db.executor.punc_external().unwrap_or(false);
|
|
||||||
|
|
||||||
for (k, v) in obj {
|
for (k, v) in obj {
|
||||||
// Always retain system and unmapped core fields natively implicitly mapped to the Postgres tables
|
// Always retain system and unmapped core fields natively implicitly mapped to the Postgres tables
|
||||||
if k == "id" || k == "type" || k == "created" {
|
if k == "id" || k == "type" || k == "created" {
|
||||||
@ -291,12 +306,6 @@ impl Merger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(prop_schema) = compiled_props.get(&k) {
|
if let Some(prop_schema) = compiled_props.get(&k) {
|
||||||
if prop_schema.is_immutable(is_external) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut is_edge = false;
|
let mut is_edge = false;
|
||||||
if let Some(edges) = schema.obj.compiled_edges.get() {
|
if let Some(edges) = schema.obj.compiled_edges.get() {
|
||||||
if edges.contains_key(&k) {
|
if edges.contains_key(&k) {
|
||||||
@ -373,7 +382,10 @@ impl Merger {
|
|||||||
if let Some(deps) = &schema.obj.dependencies {
|
if let Some(deps) = &schema.obj.dependencies {
|
||||||
if let Some(crate::database::object::Dependency::Props(req_props)) = deps.get("created") {
|
if let Some(crate::database::object::Dependency::Props(req_props)) = deps.get("created") {
|
||||||
for req in req_props {
|
for req in req_props {
|
||||||
if !entity_fields.contains_key(req) && !entity_objects.contains_key(req) && !entity_arrays.contains_key(req) {
|
if !entity_fields.contains_key(req)
|
||||||
|
&& !entity_objects.contains_key(req)
|
||||||
|
&& !entity_arrays.contains_key(req)
|
||||||
|
{
|
||||||
return Err(Error {
|
return Err(Error {
|
||||||
code: "REQUIRED_FIELD_MISSING".to_string(),
|
code: "REQUIRED_FIELD_MISSING".to_string(),
|
||||||
values: Some(IndexMap::from([
|
values: Some(IndexMap::from([
|
||||||
@ -382,7 +394,10 @@ impl Merger {
|
|||||||
])),
|
])),
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
path: Some(req.to_string()),
|
path: Some(req.to_string()),
|
||||||
cause: Some(format!("Missing required creation field '{}' for entity {}", req, type_name)),
|
cause: Some(format!(
|
||||||
|
"Missing required creation field '{}' for entity {}",
|
||||||
|
req, type_name
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -829,9 +844,15 @@ impl Merger {
|
|||||||
if table.len() > 1 {
|
if table.len() > 1 {
|
||||||
Err(Error {
|
Err(Error {
|
||||||
code: "TOO_MANY_LOOKUP_ROWS".to_string(),
|
code: "TOO_MANY_LOOKUP_ROWS".to_string(),
|
||||||
values: Some(IndexMap::from([("entity_type".to_string(), entity_type_name.to_string())])),
|
values: Some(IndexMap::from([(
|
||||||
|
"entity_type".to_string(),
|
||||||
|
entity_type_name.to_string(),
|
||||||
|
)])),
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
cause: Some(format!("Lookup for {} found too many existing rows", entity_type_name)),
|
cause: Some(format!(
|
||||||
|
"Lookup for {} found too many existing rows",
|
||||||
|
entity_type_name
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -904,9 +925,15 @@ impl Merger {
|
|||||||
_ => {
|
_ => {
|
||||||
return Err(Error {
|
return Err(Error {
|
||||||
code: "MISSING_GROUPED_FIELDS".to_string(),
|
code: "MISSING_GROUPED_FIELDS".to_string(),
|
||||||
values: Some(IndexMap::from([("type".to_string(), entity_type_name.to_string())])),
|
values: Some(IndexMap::from([(
|
||||||
|
"type".to_string(),
|
||||||
|
entity_type_name.to_string(),
|
||||||
|
)])),
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
cause: Some(format!("Grouped fields missing for type {}", entity_type_name)),
|
cause: Some(format!(
|
||||||
|
"Grouped fields missing for type {}",
|
||||||
|
entity_type_name
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user