Compare commits

..

4 Commits

Author SHA1 Message Date
7ccc4b7cce version: 1.0.78 2026-03-20 04:41:46 -04:00
77bfa4cd18 historical and notify respected 2026-03-20 04:41:35 -04:00
b47a5abd26 version: 1.0.77 2026-03-20 01:59:56 -04:00
fcd8310ed8 added new and old to changes and pg notify 2026-03-20 01:59:48 -04:00
4 changed files with 396 additions and 239 deletions

View File

@ -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
} }
] ]
@ -785,7 +795,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -793,6 +804,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"first_name\":\"IncompleteFirst\",", " \"first_name\":\"IncompleteFirst\",",
" \"last_name\":\"IncompleteLast\",", " \"last_name\":\"IncompleteLast\",",
@ -807,17 +819,22 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"first_name\":\"IncompleteFirst\",", " \"first_name\":\"IncompleteFirst\",",
" \"id\":\"{{uuid:person_id}}\",", " \"id\":\"{{uuid:person_id}}\",",
" \"last_name\":\"IncompleteLast\",", " \"last_name\":\"IncompleteLast\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" }", " },",
"}')" " \"new\":{",
" \"first_name\":\"IncompleteFirst\",",
" \"last_name\":\"IncompleteLast\",",
" \"type\":\"person\"",
" }",
" }')"
] ]
] ]
} }
@ -872,7 +889,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -881,6 +899,9 @@
")", ")",
"VALUES (", "VALUES (",
" '{", " '{",
" \"contact_id\":\"old-contact\"",
" }',",
" '{",
" \"contact_id\":\"abc-contact\",", " \"contact_id\":\"abc-contact\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" }',", " }',",
@ -893,22 +914,25 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"changes\":{", " \"complete\":{",
" \"contact_id\":\"abc-contact\",", " \"contact_id\":\"abc-contact\",",
" \"type\":\"person\"", " \"date_of_birth\":\"1990-01-01T00:00:00Z\",",
" },", " \"first_name\":\"LookupFirst\",",
" \"complete\":{", " \"id\":\"22222222-2222-2222-2222-222222222222\",",
" \"contact_id\":\"abc-contact\",", " \"last_name\":\"LookupLast\",",
" \"date_of_birth\":\"1990-01-01T00:00:00Z\",", " \"modified_at\":\"2026-03-10T00:00:00Z\",",
" \"first_name\":\"LookupFirst\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"id\":\"22222222-2222-2222-2222-222222222222\",", " \"pronouns\":\"they/them\",",
" \"last_name\":\"LookupLast\",", " \"type\":\"person\"",
" \"modified_at\":\"2026-03-10T00:00:00Z\",", " },",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"new\":{",
" \"pronouns\":\"they/them\",", " \"contact_id\":\"abc-contact\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" }", " },",
"}')" " \"old\":{",
" \"contact_id\":\"old-contact\"",
" }",
" }')"
] ]
] ]
} }
@ -959,7 +983,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -968,6 +993,10 @@
")", ")",
"VALUES (", "VALUES (",
" '{", " '{",
" \"first_name\":\"OldFirst\",",
" \"last_name\":\"OldLast\"",
" }',",
" '{",
" \"first_name\":\"NewFirst\",", " \"first_name\":\"NewFirst\",",
" \"last_name\":\"NewLast\",", " \"last_name\":\"NewLast\",",
" \"type\":\"person\"", " \"type\":\"person\"",
@ -981,20 +1010,24 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"changes\":{", " \"complete\":{",
" \"first_name\":\"NewFirst\",", " \"first_name\":\"NewFirst\",",
" \"last_name\":\"NewLast\",", " \"id\":\"11111111-1111-1111-1111-111111111111\",",
" \"type\":\"person\"", " \"last_name\":\"NewLast\",",
" },", " \"modified_at\":\"2026-03-10T00:00:00Z\",",
" \"complete\":{", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"first_name\":\"NewFirst\",", " \"type\":\"person\"",
" \"id\":\"11111111-1111-1111-1111-111111111111\",", " },",
" \"last_name\":\"NewLast\",", " \"new\":{",
" \"modified_at\":\"2026-03-10T00:00:00Z\",", " \"first_name\":\"NewFirst\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"last_name\":\"NewLast\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" }", " },",
"}')" " \"old\":{",
" \"first_name\":\"OldFirst\",",
" \"last_name\":\"OldLast\"",
" }",
" }')"
] ]
] ]
} }
@ -1079,7 +1112,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1087,6 +1121,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"date_of_birth\":\"1990-01-01T00:00:00Z\",", " \"date_of_birth\":\"1990-01-01T00:00:00Z\",",
" \"first_name\":\"John\",", " \"first_name\":\"John\",",
@ -1103,19 +1138,26 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"date_of_birth\":\"1990-01-01T00:00:00Z\",", " \"date_of_birth\":\"1990-01-01T00:00:00Z\",",
" \"first_name\":\"John\",", " \"first_name\":\"John\",",
" \"id\":\"123\",", " \"id\":\"123\",",
" \"last_name\":\"Doe\",", " \"last_name\":\"Doe\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"pronouns\":\"\",", " \"pronouns\":\"\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" }", " },",
"}')" " \"new\":{",
" \"date_of_birth\":\"1990-01-01T00:00:00Z\",",
" \"first_name\":\"John\",",
" \"last_name\":\"Doe\",",
" \"pronouns\":\"\",",
" \"type\":\"person\"",
" }",
" }')"
] ]
] ]
} }
@ -1192,7 +1234,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1200,6 +1243,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"date_of_birth\":\"2000-01-01\",", " \"date_of_birth\":\"2000-01-01\",",
" \"first_name\":\"Bob\",", " \"first_name\":\"Bob\",",
@ -1247,7 +1291,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1255,6 +1300,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"customer_id\":\"{{uuid:customer_id}}\",", " \"customer_id\":\"{{uuid:customer_id}}\",",
" \"total\":100.0,", " \"total\":100.0,",
@ -1269,32 +1315,43 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"customer_id\":\"{{uuid:customer_id}}\",", " \"customer_id\":\"{{uuid:customer_id}}\",",
" \"id\":\"{{uuid:order_id}}\",", " \"id\":\"{{uuid:order_id}}\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"total\":100.0,", " \"total\":100.0,",
" \"type\":\"order\"", " \"type\":\"order\"",
" }", " },",
"}')" " \"new\":{",
" \"customer_id\":\"{{uuid:customer_id}}\",",
" \"total\":100.0,",
" \"type\":\"order\"",
" }",
" }')"
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"date_of_birth\":\"2000-01-01\",", " \"date_of_birth\":\"2000-01-01\",",
" \"first_name\":\"Bob\",", " \"first_name\":\"Bob\",",
" \"id\":\"{{uuid:customer_id}}\",", " \"id\":\"{{uuid:customer_id}}\",",
" \"last_name\":\"Smith\",", " \"last_name\":\"Smith\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" }", " },",
"}')" " \"new\":{",
" \"date_of_birth\":\"2000-01-01\",",
" \"first_name\":\"Bob\",",
" \"last_name\":\"Smith\",",
" \"type\":\"person\"",
" }",
" }')"
] ]
] ]
} }
@ -1388,7 +1445,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1396,6 +1454,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"order_id\":\"abc\",", " \"order_id\":\"abc\",",
" \"price\":99.0,", " \"price\":99.0,",
@ -1411,7 +1470,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1419,6 +1479,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"total\":99.0,", " \"total\":99.0,",
" \"type\":\"order\"", " \"type\":\"order\"",
@ -1432,31 +1493,41 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"id\":\"abc\",", " \"id\":\"abc\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"total\":99.0,", " \"total\":99.0,",
" \"type\":\"order\"", " \"type\":\"order\"",
" }", " },",
"}')" " \"new\":{",
" \"total\":99.0,",
" \"type\":\"order\"",
" }",
" }')"
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"id\":\"{{uuid:line_id}}\",", " \"id\":\"{{uuid:line_id}}\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"order_id\":\"abc\",", " \"order_id\":\"abc\",",
" \"price\":99.0,", " \"price\":99.0,",
" \"product\":\"Widget\",", " \"product\":\"Widget\",",
" \"type\":\"order_line\"", " \"type\":\"order_line\"",
" }", " },",
"}')" " \"new\":{",
" \"order_id\":\"abc\",",
" \"price\":99.0,",
" \"product\":\"Widget\",",
" \"type\":\"order_line\"",
" }",
" }')"
] ]
] ]
} }
@ -1572,13 +1643,15 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
" modified_at,", " modified_at,",
" modified_by", " modified_by",
") VALUES (", ") VALUES (",
" NULL,",
" '{\"number\":\"555-0001\",\"type\":\"phone_number\"}',", " '{\"number\":\"555-0001\",\"type\":\"phone_number\"}',",
" '{{uuid:phone1_id}}',", " '{{uuid:phone1_id}}',",
" '{{uuid}}',", " '{{uuid}}',",
@ -1626,13 +1699,15 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
" modified_at,", " modified_at,",
" modified_by", " modified_by",
") VALUES (", ") VALUES (",
" NULL,",
" '{", " '{",
" \"is_primary\":true,", " \"is_primary\":true,",
" \"source_id\":\"{{uuid:person_id}}\",", " \"source_id\":\"{{uuid:person_id}}\",",
@ -1674,13 +1749,15 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
" modified_at,", " modified_at,",
" modified_by", " modified_by",
") VALUES (", ") VALUES (",
" NULL,",
" '{", " '{",
" \"number\":\"555-0002\",", " \"number\":\"555-0002\",",
" \"type\":\"phone_number\"", " \"type\":\"phone_number\"",
@ -1731,13 +1808,15 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
" modified_at,", " modified_at,",
" modified_by", " modified_by",
") VALUES (", ") VALUES (",
" NULL,",
" '{", " '{",
" \"is_primary\":false,", " \"is_primary\":false,",
" \"source_id\":\"{{uuid:person_id}}\",", " \"source_id\":\"{{uuid:person_id}}\",",
@ -1779,13 +1858,15 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
" modified_at,", " modified_at,",
" modified_by", " modified_by",
") VALUES (", ") VALUES (",
" NULL,",
" '{", " '{",
" \"address\":\"test@example.com\",", " \"address\":\"test@example.com\",",
" \"type\":\"email_address\"", " \"type\":\"email_address\"",
@ -1836,13 +1917,15 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
" modified_at,", " modified_at,",
" modified_by", " modified_by",
") VALUES (", ") VALUES (",
" NULL,",
" '{", " '{",
" \"is_primary\":false,", " \"is_primary\":false,",
" \"source_id\":\"{{uuid:person_id}}\",", " \"source_id\":\"{{uuid:person_id}}\",",
@ -1860,13 +1943,15 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
" modified_at,", " modified_at,",
" modified_by", " modified_by",
") VALUES (", ") VALUES (",
" NULL,",
" '{", " '{",
" \"first_name\":\"Relation\",", " \"first_name\":\"Relation\",",
" \"last_name\":\"Test\",", " \"last_name\":\"Test\",",
@ -1881,107 +1966,148 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"first_name\":\"Relation\",", " \"first_name\":\"Relation\",",
" \"id\":\"{{uuid:person_id}}\",", " \"id\":\"{{uuid:person_id}}\",",
" \"last_name\":\"Test\",", " \"last_name\":\"Test\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" }", " },",
"}')" " \"new\":{",
" \"first_name\":\"Relation\",",
" \"last_name\":\"Test\",",
" \"type\":\"person\"",
" }",
" }')"
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"id\":\"{{uuid:contact1_id}}\",", " \"id\":\"{{uuid:contact1_id}}\",",
" \"is_primary\":true,", " \"is_primary\":true,",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"source_id\":\"{{uuid:person_id}}\",", " \"source_id\":\"{{uuid:person_id}}\",",
" \"source_type\":\"person\",", " \"source_type\":\"person\",",
" \"target_id\":\"{{uuid:phone1_id}}\",", " \"target_id\":\"{{uuid:phone1_id}}\",",
" \"target_type\":\"phone_number\",", " \"target_type\":\"phone_number\",",
" \"type\":\"contact\"", " \"type\":\"contact\"",
" }", " },",
"}')" " \"new\":{",
" \"is_primary\":true,",
" \"source_id\":\"{{uuid:person_id}}\",",
" \"source_type\":\"person\",",
" \"target_id\":\"{{uuid:phone1_id}}\",",
" \"target_type\":\"phone_number\",",
" \"type\":\"contact\"",
" }",
" }')"
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"id\":\"{{uuid:phone1_id}}\",", " \"id\":\"{{uuid:phone1_id}}\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"number\":\"555-0001\",", " \"number\":\"555-0001\",",
" \"type\":\"phone_number\"", " \"type\":\"phone_number\"",
" }", " },",
"}')" " \"new\":{",
" \"number\":\"555-0001\",",
" \"type\":\"phone_number\"",
" }",
" }')"
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"id\":\"{{uuid:contact2_id}}\",", " \"id\":\"{{uuid:contact2_id}}\",",
" \"is_primary\":false,", " \"is_primary\":false,",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"source_id\":\"{{uuid:person_id}}\",", " \"source_id\":\"{{uuid:person_id}}\",",
" \"source_type\":\"person\",", " \"source_type\":\"person\",",
" \"target_id\":\"{{uuid:phone2_id}}\",", " \"target_id\":\"{{uuid:phone2_id}}\",",
" \"target_type\":\"phone_number\",", " \"target_type\":\"phone_number\",",
" \"type\":\"contact\"", " \"type\":\"contact\"",
" }", " },",
"}')" " \"new\":{",
" \"is_primary\":false,",
" \"source_id\":\"{{uuid:person_id}}\",",
" \"source_type\":\"person\",",
" \"target_id\":\"{{uuid:phone2_id}}\",",
" \"target_type\":\"phone_number\",",
" \"type\":\"contact\"",
" }",
" }')"
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"id\":\"{{uuid:phone2_id}}\",", " \"id\":\"{{uuid:phone2_id}}\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"number\":\"555-0002\",", " \"number\":\"555-0002\",",
" \"type\":\"phone_number\"", " \"type\":\"phone_number\"",
" }", " },",
"}')" " \"new\":{",
" \"number\":\"555-0002\",",
" \"type\":\"phone_number\"",
" }",
" }')"
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"id\":\"{{uuid:contact3_id}}\",", " \"id\":\"{{uuid:contact3_id}}\",",
" \"is_primary\":false,", " \"is_primary\":false,",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"source_id\":\"{{uuid:person_id}}\",", " \"source_id\":\"{{uuid:person_id}}\",",
" \"source_type\":\"person\",", " \"source_type\":\"person\",",
" \"target_id\":\"{{uuid:email1_id}}\",", " \"target_id\":\"{{uuid:email1_id}}\",",
" \"target_type\":\"email_address\",", " \"target_type\":\"email_address\",",
" \"type\":\"contact\"", " \"type\":\"contact\"",
" }", " },",
"}')" " \"new\":{",
" \"is_primary\":false,",
" \"source_id\":\"{{uuid:person_id}}\",",
" \"source_type\":\"person\",",
" \"target_id\":\"{{uuid:email1_id}}\",",
" \"target_type\":\"email_address\",",
" \"type\":\"contact\"",
" }",
" }')"
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"complete\":{", " \"complete\":{",
" \"address\":\"test@example.com\",", " \"address\":\"test@example.com\",",
" \"created_at\":\"{{timestamp}}\",", " \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",", " \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"id\":\"{{uuid:email1_id}}\",", " \"id\":\"{{uuid:email1_id}}\",",
" \"modified_at\":\"{{timestamp}}\",", " \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"type\":\"email_address\"", " \"type\":\"email_address\"",
" }", " },",
"}')" " \"new\":{",
" \"address\":\"test@example.com\",",
" \"type\":\"email_address\"",
" }",
" }')"
] ]
] ]
} }
@ -2023,13 +2149,17 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
" modified_at,", " modified_at,",
" modified_by", " modified_by",
") VALUES (", ") VALUES (",
" '{",
" \"archived\":false",
" }',",
" '{\"archived\":true,\"type\":\"person\"}',", " '{\"archived\":true,\"type\":\"person\"}',",
" 'abc-archived',", " 'abc-archived',",
" '{{uuid}}',", " '{{uuid}}',",
@ -2040,18 +2170,23 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"changes\":{", " \"complete\":{",
" \"archived\":true,\"type\":\"person\"},", " \"archived\":true,",
" \"complete\":{", " \"first_name\":\"ArchivedFirst\",",
" \"archived\":true,", " \"id\":\"abc-archived\",",
" \"first_name\":\"ArchivedFirst\",", " \"last_name\":\"ArchivedLast\",",
" \"id\":\"abc-archived\",", " \"modified_at\":\"{{timestamp}}\",",
" \"last_name\":\"ArchivedLast\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"modified_at\":\"{{timestamp}}\",", " \"type\":\"person\"",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " },",
" \"type\":\"person\"", " \"new\":{",
" }", " \"archived\":true,",
"}')" " \"type\":\"person\"",
" },",
" \"old\":{",
" \"archived\":false",
" }",
" }')"
] ]
] ]
} }

View File

@ -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,

View File

@ -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>,
@ -694,7 +697,8 @@ impl Merger {
let id_str = entity_fields.get("id").unwrap(); let id_str = entity_fields.get("id").unwrap();
let type_name = entity_fields.get("type").unwrap(); let type_name = entity_fields.get("type").unwrap();
let mut changes = serde_json::Map::new(); let mut old_vals = serde_json::Map::new();
let mut new_vals = serde_json::Map::new();
let is_update = change_kind == "update" || change_kind == "delete"; let is_update = change_kind == "update" || change_kind == "delete";
if !is_update { if !is_update {
@ -707,7 +711,7 @@ impl Merger {
]; ];
for (k, v) in entity_fields { for (k, v) in entity_fields {
if !system_keys.contains(k) { if !system_keys.contains(k) {
changes.insert(k.clone(), v.clone()); new_vals.insert(k.clone(), v.clone());
} }
} }
} else { } else {
@ -724,12 +728,13 @@ impl Merger {
if let Some(fetched) = entity_fetched { if let Some(fetched) = entity_fetched {
let old_val = fetched.get(k).unwrap_or(&Value::Null); let old_val = fetched.get(k).unwrap_or(&Value::Null);
if v != old_val { if v != old_val {
changes.insert(k.clone(), v.clone()); new_vals.insert(k.clone(), v.clone());
old_vals.insert(k.clone(), old_val.clone());
} }
} }
} }
} }
changes.insert("type".to_string(), type_name.clone()); new_vals.insert("type".to_string(), type_name.clone());
} }
let mut complete = entity_fields.clone(); let mut complete = entity_fields.clone();
@ -743,33 +748,48 @@ impl Merger {
} }
} }
let new_val_obj = Value::Object(new_vals);
let old_val_obj = if old_vals.is_empty() {
Value::Null
} else {
Value::Object(old_vals)
};
let mut notification = serde_json::Map::new(); let mut notification = serde_json::Map::new();
notification.insert("complete".to_string(), Value::Object(complete)); notification.insert("complete".to_string(), Value::Object(complete));
if is_update { notification.insert("new".to_string(), new_val_obj.clone());
notification.insert("changes".to_string(), Value::Object(changes.clone()));
if old_val_obj != Value::Null {
notification.insert("old".to_string(), old_val_obj.clone());
} }
let change_sql = format!( let mut notify_sql = None;
"INSERT INTO agreego.change (changes, entity_id, id, kind, modified_at, modified_by) VALUES ({}, {}, {}, {}, {}, {})", if type_obj.historical {
Self::quote_literal(&Value::Object(changes)), let change_sql = format!(
Self::quote_literal(id_str), "INSERT INTO agreego.change (\"old\", \"new\", entity_id, id, kind, modified_at, modified_by) VALUES ({}, {}, {}, {}, {}, {}, {})",
Self::quote_literal(&Value::String(uuid::Uuid::new_v4().to_string())), Self::quote_literal(&old_val_obj),
Self::quote_literal(&Value::String(change_kind.to_string())), Self::quote_literal(&new_val_obj),
Self::quote_literal(&Value::String(timestamp.to_string())), Self::quote_literal(id_str),
Self::quote_literal(&Value::String(user_id.to_string())) Self::quote_literal(&Value::String(uuid::Uuid::new_v4().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(

View File

@ -1 +1 @@
1.0.76 1.0.78