historical and notify respected

This commit is contained in:
2026-03-20 04:41:35 -04:00
parent b47a5abd26
commit 77bfa4cd18
3 changed files with 43 additions and 23 deletions

View File

@ -143,7 +143,8 @@
]
},
"lookup_fields": [],
"historical": false,
"historical": true,
"notify": true,
"relationship": false
},
{
@ -191,6 +192,7 @@
},
"lookup_fields": [],
"historical": true,
"notify": true,
"relationship": false
},
{
@ -239,6 +241,7 @@
},
"lookup_fields": [],
"historical": true,
"notify": true,
"relationship": false
},
{
@ -341,6 +344,7 @@
"pronouns"
],
"historical": true,
"notify": true,
"relationship": false
},
{
@ -395,6 +399,7 @@
"id"
],
"historical": true,
"notify": true,
"relationship": false
},
{
@ -452,6 +457,7 @@
},
"lookup_fields": [],
"historical": true,
"notify": true,
"relationship": false
},
{
@ -515,7 +521,8 @@
}
],
"lookup_fields": [],
"historical": true
"historical": true,
"notify": true
},
{
"name": "contact",
@ -588,7 +595,8 @@
}
],
"lookup_fields": [],
"historical": true
"historical": true,
"notify": true
},
{
"name": "phone_number",
@ -646,6 +654,7 @@
],
"lookup_fields": [],
"historical": true,
"notify": true,
"relationship": false
},
{
@ -704,6 +713,7 @@
],
"lookup_fields": [],
"historical": true,
"notify": true,
"relationship": false
}
]

View File

@ -15,6 +15,8 @@ pub struct Type {
#[serde(default)]
pub historical: bool,
#[serde(default)]
pub notify: bool,
#[serde(default)]
pub sensitive: bool,
#[serde(default)]
pub ownable: bool,

View File

@ -3,6 +3,7 @@
pub mod cache;
use crate::database::r#type::Type;
use crate::database::Database;
use serde_json::Value;
use std::sync::Arc;
@ -321,8 +322,9 @@ impl Merger {
}
}
// 7. Perform change tracking
// 7. Perform change tracking dynamically suppressing noise based on type bounds!
let notify_sql = self.merge_entity_change(
type_def,
&entity_fields,
entity_fetched.as_ref(),
entity_change_kind.as_deref(),
@ -680,6 +682,7 @@ impl Merger {
fn merge_entity_change(
&self,
type_obj: &Type,
entity_fields: &serde_json::Map<String, Value>,
entity_fetched: Option<&serde_json::Map<String, Value>>,
entity_change_kind: Option<&str>,
@ -760,6 +763,8 @@ impl Merger {
notification.insert("old".to_string(), old_val_obj.clone());
}
let mut notify_sql = None;
if type_obj.historical {
let change_sql = format!(
"INSERT INTO agreego.change (\"old\", \"new\", entity_id, id, kind, modified_at, modified_by) VALUES ({}, {}, {}, {}, {}, {}, {})",
Self::quote_literal(&old_val_obj),
@ -771,17 +776,20 @@ impl Merger {
Self::quote_literal(&Value::String(user_id.to_string()))
);
let notify_sql = format!(
"SELECT pg_notify('entity', {})",
Self::quote_literal(&Value::String(Value::Object(notification).to_string()))
);
self
.db
.execute(&change_sql, None)
.map_err(|e| format!("Executor Error in change: {:?}", e))?;
}
Ok(Some(notify_sql))
if type_obj.notify {
notify_sql = Some(format!(
"SELECT pg_notify('entity', {})",
Self::quote_literal(&Value::String(Value::Object(notification).to_string()))
));
}
Ok(notify_sql)
}
fn compare_entities(