test pgrx no fixes
This commit is contained in:
@ -19,7 +19,7 @@
|
|||||||
{
|
{
|
||||||
"id": "22222222-2222-2222-2222-222222222222",
|
"id": "22222222-2222-2222-2222-222222222222",
|
||||||
"type": "relation",
|
"type": "relation",
|
||||||
"constraint": "fk_order_customer",
|
"constraint": "fk_order_customer_person",
|
||||||
"source_type": "order",
|
"source_type": "order",
|
||||||
"source_columns": [
|
"source_columns": [
|
||||||
"customer_id"
|
"customer_id"
|
||||||
@ -41,8 +41,7 @@
|
|||||||
"destination_type": "order",
|
"destination_type": "order",
|
||||||
"destination_columns": [
|
"destination_columns": [
|
||||||
"id"
|
"id"
|
||||||
],
|
]
|
||||||
"prefix": "lines"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "44444444-4444-4444-4444-444444444444",
|
"id": "44444444-4444-4444-4444-444444444444",
|
||||||
|
|||||||
@ -71,7 +71,7 @@
|
|||||||
{
|
{
|
||||||
"id": "22222222-2222-2222-2222-222222222222",
|
"id": "22222222-2222-2222-2222-222222222222",
|
||||||
"type": "relation",
|
"type": "relation",
|
||||||
"constraint": "fk_order_customer",
|
"constraint": "fk_order_customer_person",
|
||||||
"source_type": "order",
|
"source_type": "order",
|
||||||
"source_columns": [
|
"source_columns": [
|
||||||
"customer_id"
|
"customer_id"
|
||||||
@ -79,7 +79,8 @@
|
|||||||
"destination_type": "person",
|
"destination_type": "person",
|
||||||
"destination_columns": [
|
"destination_columns": [
|
||||||
"id"
|
"id"
|
||||||
]
|
],
|
||||||
|
"prefix": "customer"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "22222222-2222-2222-2222-222222222227",
|
"id": "22222222-2222-2222-2222-222222222227",
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
pub mod cache;
|
pub mod cache;
|
||||||
|
|
||||||
use crate::database::r#type::Type;
|
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
|
use crate::database::r#type::Type;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -50,15 +50,21 @@ impl Merger {
|
|||||||
let mut final_cause = None;
|
let mut final_cause = None;
|
||||||
|
|
||||||
if let Ok(Value::Object(map)) = serde_json::from_str::<Value>(&msg) {
|
if let Ok(Value::Object(map)) = serde_json::from_str::<Value>(&msg) {
|
||||||
if let (Some(Value::String(e_msg)), Some(Value::String(e_code))) = (map.get("error"), map.get("code")) {
|
if let (Some(Value::String(e_msg)), Some(Value::String(e_code))) =
|
||||||
|
(map.get("error"), map.get("code"))
|
||||||
|
{
|
||||||
final_message = e_msg.clone();
|
final_message = e_msg.clone();
|
||||||
final_code = e_code.clone();
|
final_code = e_code.clone();
|
||||||
let mut cause_parts = Vec::new();
|
let mut cause_parts = Vec::new();
|
||||||
if let Some(Value::String(d)) = map.get("detail") {
|
if let Some(Value::String(d)) = map.get("detail") {
|
||||||
if !d.is_empty() { cause_parts.push(d.clone()); }
|
if !d.is_empty() {
|
||||||
|
cause_parts.push(d.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(Value::String(h)) = map.get("hint") {
|
if let Some(Value::String(h)) = map.get("hint") {
|
||||||
if !h.is_empty() { cause_parts.push(h.clone()); }
|
if !h.is_empty() {
|
||||||
|
cause_parts.push(h.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !cause_parts.is_empty() {
|
if !cause_parts.is_empty() {
|
||||||
final_cause = Some(cause_parts.join("\n"));
|
final_cause = Some(cause_parts.join("\n"));
|
||||||
@ -186,7 +192,7 @@ 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();
|
||||||
|
|
||||||
for (k, v) in obj {
|
for (k, v) in obj.clone() {
|
||||||
// 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" {
|
||||||
entity_fields.insert(k.clone(), v.clone());
|
entity_fields.insert(k.clone(), v.clone());
|
||||||
@ -253,7 +259,11 @@ impl Merger {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(compiled_edges) = schema.obj.compiled_edges.get() {
|
if let Some(compiled_edges) = schema.obj.compiled_edges.get() {
|
||||||
println!("Compiled Edges keys for relation {}: {:?}", relation_name, compiled_edges.keys().collect::<Vec<_>>());
|
println!(
|
||||||
|
"Compiled Edges keys for relation {}: {:?}",
|
||||||
|
relation_name,
|
||||||
|
compiled_edges.keys().collect::<Vec<_>>()
|
||||||
|
);
|
||||||
if let Some(edge) = compiled_edges.get(&relation_name) {
|
if let Some(edge) = compiled_edges.get(&relation_name) {
|
||||||
println!("FOUND EDGE {} -> {:?}", relation_name, edge.constraint);
|
println!("FOUND EDGE {} -> {:?}", relation_name, edge.constraint);
|
||||||
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
||||||
@ -266,15 +276,16 @@ impl Merger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut merged_relative = match self.merge_internal(rel_schema.clone(), Value::Object(relative), notifications)? {
|
let mut merged_relative = match self.merge_internal(
|
||||||
|
rel_schema.clone(),
|
||||||
|
Value::Object(relative),
|
||||||
|
notifications,
|
||||||
|
)? {
|
||||||
Value::Object(m) => m,
|
Value::Object(m) => m,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
merged_relative.insert(
|
merged_relative.insert("type".to_string(), Value::String(relative_type_name));
|
||||||
"type".to_string(),
|
|
||||||
Value::String(relative_type_name),
|
|
||||||
);
|
|
||||||
|
|
||||||
Self::apply_entity_relation(
|
Self::apply_entity_relation(
|
||||||
&mut entity_fields,
|
&mut entity_fields,
|
||||||
@ -297,7 +308,11 @@ impl Merger {
|
|||||||
&entity_fields,
|
&entity_fields,
|
||||||
);
|
);
|
||||||
|
|
||||||
let merged_relative = match self.merge_internal(rel_schema.clone(), Value::Object(relative), notifications)? {
|
let merged_relative = match self.merge_internal(
|
||||||
|
rel_schema.clone(),
|
||||||
|
Value::Object(relative),
|
||||||
|
notifications,
|
||||||
|
)? {
|
||||||
Value::Object(m) => m,
|
Value::Object(m) => m,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
@ -318,6 +333,20 @@ impl Merger {
|
|||||||
entity_replaces = replaces;
|
entity_replaces = replaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
if type_name == "contact" || type_name == "person" {
|
||||||
|
pgrx::notice!("=== DEBUG {} PAYLOAD ===", type_name);
|
||||||
|
pgrx::notice!("1. Incoming obj iteration: {:?}", obj);
|
||||||
|
pgrx::notice!("2. Final mapped entity_fields: {:?}", entity_fields);
|
||||||
|
pgrx::notice!(
|
||||||
|
"3. TypeDef fields check: {:?}",
|
||||||
|
type_def.fields.contains(&"source_id".to_string())
|
||||||
|
);
|
||||||
|
if !entity_fields.contains_key("source_id") {
|
||||||
|
pgrx::notice!("CRITICAL ERROR: source_id was dropped during mapping loop!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.merge_entity_fields(
|
self.merge_entity_fields(
|
||||||
entity_change_kind.as_deref().unwrap_or(""),
|
entity_change_kind.as_deref().unwrap_or(""),
|
||||||
&type_name,
|
&type_name,
|
||||||
@ -360,7 +389,9 @@ impl Merger {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let mut item_schema = rel_schema.clone();
|
let mut item_schema = rel_schema.clone();
|
||||||
if let Some(crate::database::schema::SchemaTypeOrArray::Single(t)) = &rel_schema.obj.type_ {
|
if let Some(crate::database::schema::SchemaTypeOrArray::Single(t)) =
|
||||||
|
&rel_schema.obj.type_
|
||||||
|
{
|
||||||
if t == "array" {
|
if t == "array" {
|
||||||
if let Some(items_def) = &rel_schema.obj.items {
|
if let Some(items_def) = &rel_schema.obj.items {
|
||||||
item_schema = items_def.clone();
|
item_schema = items_def.clone();
|
||||||
@ -368,8 +399,11 @@ impl Merger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let merged_relative =
|
let merged_relative = match self.merge_internal(
|
||||||
match self.merge_internal(item_schema, Value::Object(relative_item), notifications)? {
|
item_schema,
|
||||||
|
Value::Object(relative_item),
|
||||||
|
notifications,
|
||||||
|
)? {
|
||||||
Value::Object(m) => m,
|
Value::Object(m) => m,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
@ -548,7 +582,12 @@ impl Merger {
|
|||||||
entity_fields = new_fields;
|
entity_fields = new_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((entity_fields, entity_change_kind, entity_fetched, replaces_id))
|
Ok((
|
||||||
|
entity_fields,
|
||||||
|
entity_change_kind,
|
||||||
|
entity_fetched,
|
||||||
|
replaces_id,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_entity(
|
fn fetch_entity(
|
||||||
@ -735,9 +774,7 @@ impl Merger {
|
|||||||
columns.join(", "),
|
columns.join(", "),
|
||||||
values.join(", ")
|
values.join(", ")
|
||||||
);
|
);
|
||||||
self
|
self.db.execute(&sql, None)?;
|
||||||
.db
|
|
||||||
.execute(&sql, None)?;
|
|
||||||
} else if change_kind == "update" || change_kind == "delete" {
|
} else if change_kind == "update" || change_kind == "delete" {
|
||||||
entity_pairs.remove("id");
|
entity_pairs.remove("id");
|
||||||
entity_pairs.remove("type");
|
entity_pairs.remove("type");
|
||||||
@ -769,9 +806,7 @@ impl Merger {
|
|||||||
set_clauses.join(", "),
|
set_clauses.join(", "),
|
||||||
Self::quote_literal(&Value::String(id_str.to_string()))
|
Self::quote_literal(&Value::String(id_str.to_string()))
|
||||||
);
|
);
|
||||||
self
|
self.db.execute(&sql, None)?;
|
||||||
.db
|
|
||||||
.execute(&sql, None)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user