historical and notify respected
This commit is contained in:
@ -143,7 +143,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"lookup_fields": [],
|
"lookup_fields": [],
|
||||||
"historical": false,
|
"historical": true,
|
||||||
|
"notify": true,
|
||||||
"relationship": false
|
"relationship": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -191,6 +192,7 @@
|
|||||||
},
|
},
|
||||||
"lookup_fields": [],
|
"lookup_fields": [],
|
||||||
"historical": true,
|
"historical": true,
|
||||||
|
"notify": true,
|
||||||
"relationship": false
|
"relationship": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -239,6 +241,7 @@
|
|||||||
},
|
},
|
||||||
"lookup_fields": [],
|
"lookup_fields": [],
|
||||||
"historical": true,
|
"historical": true,
|
||||||
|
"notify": true,
|
||||||
"relationship": false
|
"relationship": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -341,6 +344,7 @@
|
|||||||
"pronouns"
|
"pronouns"
|
||||||
],
|
],
|
||||||
"historical": true,
|
"historical": true,
|
||||||
|
"notify": true,
|
||||||
"relationship": false
|
"relationship": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -395,6 +399,7 @@
|
|||||||
"id"
|
"id"
|
||||||
],
|
],
|
||||||
"historical": true,
|
"historical": true,
|
||||||
|
"notify": true,
|
||||||
"relationship": false
|
"relationship": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -452,6 +457,7 @@
|
|||||||
},
|
},
|
||||||
"lookup_fields": [],
|
"lookup_fields": [],
|
||||||
"historical": true,
|
"historical": true,
|
||||||
|
"notify": true,
|
||||||
"relationship": false
|
"relationship": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -515,7 +521,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"lookup_fields": [],
|
"lookup_fields": [],
|
||||||
"historical": true
|
"historical": true,
|
||||||
|
"notify": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "contact",
|
"name": "contact",
|
||||||
@ -588,7 +595,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"lookup_fields": [],
|
"lookup_fields": [],
|
||||||
"historical": true
|
"historical": true,
|
||||||
|
"notify": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phone_number",
|
"name": "phone_number",
|
||||||
@ -646,6 +654,7 @@
|
|||||||
],
|
],
|
||||||
"lookup_fields": [],
|
"lookup_fields": [],
|
||||||
"historical": true,
|
"historical": true,
|
||||||
|
"notify": true,
|
||||||
"relationship": false
|
"relationship": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -704,6 +713,7 @@
|
|||||||
],
|
],
|
||||||
"lookup_fields": [],
|
"lookup_fields": [],
|
||||||
"historical": true,
|
"historical": true,
|
||||||
|
"notify": true,
|
||||||
"relationship": false
|
"relationship": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -15,6 +15,8 @@ pub struct Type {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub historical: bool,
|
pub historical: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
pub notify: bool,
|
||||||
|
#[serde(default)]
|
||||||
pub sensitive: bool,
|
pub sensitive: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub ownable: bool,
|
pub ownable: bool,
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
pub mod cache;
|
pub mod cache;
|
||||||
|
|
||||||
|
use crate::database::r#type::Type;
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::sync::Arc;
|
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(
|
let notify_sql = self.merge_entity_change(
|
||||||
|
type_def,
|
||||||
&entity_fields,
|
&entity_fields,
|
||||||
entity_fetched.as_ref(),
|
entity_fetched.as_ref(),
|
||||||
entity_change_kind.as_deref(),
|
entity_change_kind.as_deref(),
|
||||||
@ -680,6 +682,7 @@ impl Merger {
|
|||||||
|
|
||||||
fn merge_entity_change(
|
fn merge_entity_change(
|
||||||
&self,
|
&self,
|
||||||
|
type_obj: &Type,
|
||||||
entity_fields: &serde_json::Map<String, Value>,
|
entity_fields: &serde_json::Map<String, Value>,
|
||||||
entity_fetched: Option<&serde_json::Map<String, Value>>,
|
entity_fetched: Option<&serde_json::Map<String, Value>>,
|
||||||
entity_change_kind: Option<&str>,
|
entity_change_kind: Option<&str>,
|
||||||
@ -760,28 +763,33 @@ impl Merger {
|
|||||||
notification.insert("old".to_string(), old_val_obj.clone());
|
notification.insert("old".to_string(), old_val_obj.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
let change_sql = format!(
|
let mut notify_sql = None;
|
||||||
"INSERT INTO agreego.change (\"old\", \"new\", entity_id, id, kind, modified_at, modified_by) VALUES ({}, {}, {}, {}, {}, {}, {})",
|
if type_obj.historical {
|
||||||
Self::quote_literal(&old_val_obj),
|
let change_sql = format!(
|
||||||
Self::quote_literal(&new_val_obj),
|
"INSERT INTO agreego.change (\"old\", \"new\", entity_id, id, kind, modified_at, modified_by) VALUES ({}, {}, {}, {}, {}, {}, {})",
|
||||||
Self::quote_literal(id_str),
|
Self::quote_literal(&old_val_obj),
|
||||||
Self::quote_literal(&Value::String(uuid::Uuid::new_v4().to_string())),
|
Self::quote_literal(&new_val_obj),
|
||||||
Self::quote_literal(&Value::String(change_kind.to_string())),
|
Self::quote_literal(id_str),
|
||||||
Self::quote_literal(&Value::String(timestamp.to_string())),
|
Self::quote_literal(&Value::String(uuid::Uuid::new_v4().to_string())),
|
||||||
Self::quote_literal(&Value::String(user_id.to_string()))
|
Self::quote_literal(&Value::String(change_kind.to_string())),
|
||||||
);
|
Self::quote_literal(&Value::String(timestamp.to_string())),
|
||||||
|
Self::quote_literal(&Value::String(user_id.to_string()))
|
||||||
|
);
|
||||||
|
|
||||||
let notify_sql = format!(
|
self
|
||||||
"SELECT pg_notify('entity', {})",
|
.db
|
||||||
Self::quote_literal(&Value::String(Value::Object(notification).to_string()))
|
.execute(&change_sql, None)
|
||||||
);
|
.map_err(|e| format!("Executor Error in change: {:?}", e))?;
|
||||||
|
}
|
||||||
|
|
||||||
self
|
if type_obj.notify {
|
||||||
.db
|
notify_sql = Some(format!(
|
||||||
.execute(&change_sql, None)
|
"SELECT pg_notify('entity', {})",
|
||||||
.map_err(|e| format!("Executor Error in change: {:?}", e))?;
|
Self::quote_literal(&Value::String(Value::Object(notification).to_string()))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Some(notify_sql))
|
Ok(notify_sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_entities(
|
fn compare_entities(
|
||||||
|
|||||||
Reference in New Issue
Block a user