Compare commits

..

9 Commits

Author SHA1 Message Date
75aac41362 version: 1.0.80 2026-03-20 06:48:19 -04:00
dbcef42401 merger fixes 2026-03-20 06:48:08 -04:00
b6c5561d2f version: 1.0.79 2026-03-20 05:58:53 -04:00
e01b778d68 jsob and test array handling improved in merger 2026-03-20 05:58:43 -04:00
6eb134c0d6 test checkpoint 2026-03-20 05:17:28 -04:00
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
5 changed files with 607 additions and 248 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,75 @@
], ],
"lookup_fields": [], "lookup_fields": [],
"historical": true, "historical": true,
"notify": true,
"relationship": false
},
{
"name": "attachment",
"schemas": [
{
"$id": "attachment",
"$ref": "entity",
"properties": {
"flags": {
"type": "array",
"items": {
"type": "string"
}
},
"metadata": {
"type": "object",
"additionalProperties": true
}
}
}
],
"hierarchy": [
"attachment",
"entity"
],
"fields": [
"id",
"type",
"flags",
"metadata",
"created_at",
"created_by",
"modified_at",
"modified_by",
"archived"
],
"grouped_fields": {
"attachment": [
"id",
"type",
"flags",
"metadata"
],
"entity": [
"id",
"type",
"created_at",
"created_by",
"modified_at",
"modified_by",
"archived"
]
},
"field_types": {
"id": "uuid",
"type": "text",
"flags": "_text",
"metadata": "jsonb",
"created_at": "timestamptz",
"created_by": "uuid",
"modified_at": "timestamptz",
"modified_by": "uuid",
"archived": "boolean"
},
"lookup_fields": [],
"historical": true,
"notify": true,
"relationship": false "relationship": false
} }
] ]
@ -785,7 +863,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -793,6 +872,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"first_name\":\"IncompleteFirst\",", " \"first_name\":\"IncompleteFirst\",",
" \"last_name\":\"IncompleteLast\",", " \"last_name\":\"IncompleteLast\",",
@ -816,8 +896,13 @@
" \"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 +957,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -881,6 +967,9 @@
")", ")",
"VALUES (", "VALUES (",
" '{", " '{",
" \"contact_id\":\"old-contact\"",
" }',",
" '{",
" \"contact_id\":\"abc-contact\",", " \"contact_id\":\"abc-contact\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" }',", " }',",
@ -893,10 +982,6 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"changes\":{",
" \"contact_id\":\"abc-contact\",",
" \"type\":\"person\"",
" },",
" \"complete\":{", " \"complete\":{",
" \"contact_id\":\"abc-contact\",", " \"contact_id\":\"abc-contact\",",
" \"date_of_birth\":\"1990-01-01T00:00:00Z\",", " \"date_of_birth\":\"1990-01-01T00:00:00Z\",",
@ -907,8 +992,15 @@
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"pronouns\":\"they/them\",", " \"pronouns\":\"they/them\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" },",
" \"new\":{",
" \"contact_id\":\"abc-contact\",",
" \"type\":\"person\"",
" },",
" \"old\":{",
" \"contact_id\":\"old-contact\"",
" }", " }",
"}')" " }')"
] ]
] ]
} }
@ -959,7 +1051,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -968,6 +1061,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,11 +1078,6 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"changes\":{",
" \"first_name\":\"NewFirst\",",
" \"last_name\":\"NewLast\",",
" \"type\":\"person\"",
" },",
" \"complete\":{", " \"complete\":{",
" \"first_name\":\"NewFirst\",", " \"first_name\":\"NewFirst\",",
" \"id\":\"11111111-1111-1111-1111-111111111111\",", " \"id\":\"11111111-1111-1111-1111-111111111111\",",
@ -993,8 +1085,17 @@
" \"modified_at\":\"2026-03-10T00:00:00Z\",", " \"modified_at\":\"2026-03-10T00:00:00Z\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"type\":\"person\"", " \"type\":\"person\"",
" },",
" \"new\":{",
" \"first_name\":\"NewFirst\",",
" \"last_name\":\"NewLast\",",
" \"type\":\"person\"",
" },",
" \"old\":{",
" \"first_name\":\"OldFirst\",",
" \"last_name\":\"OldLast\"",
" }", " }",
"}')" " }')"
] ]
] ]
} }
@ -1079,7 +1180,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1087,6 +1189,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\",",
@ -1114,8 +1217,15 @@
" \"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 +1302,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1200,6 +1311,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 +1359,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1255,6 +1368,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"customer_id\":\"{{uuid:customer_id}}\",", " \"customer_id\":\"{{uuid:customer_id}}\",",
" \"total\":100.0,", " \"total\":100.0,",
@ -1278,8 +1392,13 @@
" \"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', '{",
@ -1293,8 +1412,14 @@
" \"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 +1513,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1396,6 +1522,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"order_id\":\"abc\",", " \"order_id\":\"abc\",",
" \"price\":99.0,", " \"price\":99.0,",
@ -1411,7 +1538,8 @@
], ],
[ [
"INSERT INTO agreego.change (", "INSERT INTO agreego.change (",
" changes,", " \"old\",",
" \"new\",",
" entity_id,", " entity_id,",
" id,", " id,",
" kind,", " kind,",
@ -1419,6 +1547,7 @@
" modified_by", " modified_by",
")", ")",
"VALUES (", "VALUES (",
" NULL,",
" '{", " '{",
" \"total\":99.0,", " \"total\":99.0,",
" \"type\":\"order\"", " \"type\":\"order\"",
@ -1440,8 +1569,12 @@
" \"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', '{",
@ -1455,8 +1588,14 @@
" \"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 +1711,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 +1767,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 +1817,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 +1876,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 +1926,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 +1985,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 +2011,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\",",
@ -1890,8 +2043,13 @@
" \"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', '{",
@ -1907,8 +2065,16 @@
" \"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', '{",
@ -1920,8 +2086,12 @@
" \"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', '{",
@ -1937,8 +2107,16 @@
" \"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', '{",
@ -1950,8 +2128,12 @@
" \"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', '{",
@ -1967,8 +2149,16 @@
" \"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', '{",
@ -1980,8 +2170,12 @@
" \"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 +2217,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,8 +2238,6 @@
], ],
[ [
"SELECT pg_notify('entity', '{", "SELECT pg_notify('entity', '{",
" \"changes\":{",
" \"archived\":true,\"type\":\"person\"},",
" \"complete\":{", " \"complete\":{",
" \"archived\":true,", " \"archived\":true,",
" \"first_name\":\"ArchivedFirst\",", " \"first_name\":\"ArchivedFirst\",",
@ -2050,8 +2246,110 @@
" \"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\":{",
" \"archived\":true,",
" \"type\":\"person\"",
" },",
" \"old\":{",
" \"archived\":false",
" }", " }",
"}')" " }')"
]
]
}
},
{
"description": "Insert attachment displaying side-by-side array literal and jsonb formatting translations",
"action": "merge",
"data": {
"type": "attachment",
"flags": [
"urgent",
"reviewed"
],
"metadata": {
"size": 1024,
"source": "upload"
}
},
"expect": {
"success": true,
"sql": [
[
"INSERT INTO agreego.\"entity\" (",
" \"created_at\",",
" \"created_by\",",
" \"id\",",
" \"modified_at\",",
" \"modified_by\",",
" \"type\"",
")",
"VALUES (",
" '{{timestamp}}',",
" '00000000-0000-0000-0000-000000000000',",
" '{{uuid:attachment_id}}',",
" '{{timestamp}}',",
" '00000000-0000-0000-0000-000000000000',",
" 'attachment'",
")"
],
[
"INSERT INTO agreego.\"attachment\" (",
" \"flags\",",
" \"id\",",
" \"metadata\",",
" \"type\"",
")",
"VALUES (",
" '{\"urgent\",\"reviewed\"}',",
" '{{uuid:attachment_id}}',",
" '{\"size\":1024,\"source\":\"upload\"}',",
" 'attachment'",
")"
],
[
"INSERT INTO agreego.change (",
" \"old\",",
" \"new\",",
" entity_id,",
" id,",
" kind,",
" modified_at,",
" modified_by",
")",
"VALUES (",
" NULL,",
" '{",
" \"flags\":[\"urgent\",\"reviewed\"],",
" \"metadata\":{\"size\":1024,\"source\":\"upload\"},",
" \"type\":\"attachment\"",
" }',",
" '{{uuid:attachment_id}}',",
" '{{uuid}}',",
" 'create',",
" '{{timestamp}}',",
" '00000000-0000-0000-0000-000000000000'",
")"
],
[
"SELECT pg_notify('entity', '{",
" \"complete\":{",
" \"created_at\":\"{{timestamp}}\",",
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"flags\":[\"urgent\",\"reviewed\"],",
" \"id\":\"{{uuid:attachment_id}}\",",
" \"metadata\":{\"size\":1024,\"source\":\"upload\"},",
" \"modified_at\":\"{{timestamp}}\",",
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
" \"type\":\"attachment\"",
" },",
" \"new\":{",
" \"flags\":[\"urgent\",\"reviewed\"],",
" \"metadata\":{\"size\":1024,\"source\":\"upload\"},",
" \"type\":\"attachment\"",
" }",
" }')"
] ]
] ]
} }

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;
@ -175,7 +176,7 @@ impl Merger {
// Attempt to extract relative object type name // Attempt to extract relative object type name
let relative_type_name = match relative.get("type").and_then(|v| v.as_str()) { let relative_type_name = match relative.get("type").and_then(|v| v.as_str()) {
Some(t) => t, Some(t) => t.to_string(),
None => continue, None => continue,
}; };
@ -184,7 +185,7 @@ impl Merger {
// Call central Database O(1) graph logic // Call central Database O(1) graph logic
let relative_relation = self.db.get_relation( let relative_relation = self.db.get_relation(
&type_def.name, &type_def.name,
relative_type_name, &relative_type_name,
&relation_name, &relation_name,
Some(&relative_keys), Some(&relative_keys),
); );
@ -199,11 +200,16 @@ impl Merger {
} }
} }
let merged_relative = match self.merge_internal(Value::Object(relative), notifications)? { let mut merged_relative = match self.merge_internal(Value::Object(relative), notifications)? {
Value::Object(m) => m, Value::Object(m) => m,
_ => continue, _ => continue,
}; };
merged_relative.insert(
"type".to_string(),
Value::String(relative_type_name),
);
Self::apply_entity_relation( Self::apply_entity_relation(
&mut entity_fields, &mut entity_fields,
&relation.source_columns, &relation.source_columns,
@ -321,8 +327,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(),
@ -620,11 +627,7 @@ impl Merger {
for key in &sorted_keys { for key in &sorted_keys {
columns.push(format!("\"{}\"", key)); columns.push(format!("\"{}\"", key));
let val = entity_pairs.get(key).unwrap(); let val = entity_pairs.get(key).unwrap();
if val.as_str() == Some("") { values.push(Self::format_sql_value(val, key, entity_type));
values.push("NULL".to_string());
} else {
values.push(Self::quote_literal(val));
}
} }
if columns.is_empty() { if columns.is_empty() {
@ -658,7 +661,11 @@ impl Merger {
if val.as_str() == Some("") { if val.as_str() == Some("") {
set_clauses.push(format!("\"{}\" = NULL", key)); set_clauses.push(format!("\"{}\" = NULL", key));
} else { } else {
set_clauses.push(format!("\"{}\" = {}", key, Self::quote_literal(val))); set_clauses.push(format!(
"\"{}\" = {}",
key,
Self::format_sql_value(val, key, entity_type)
));
} }
} }
@ -680,6 +687,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 +702,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 +716,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 +733,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,15 +753,27 @@ 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 mut notify_sql = None;
if type_obj.historical {
let change_sql = format!( let change_sql = format!(
"INSERT INTO agreego.change (changes, entity_id, id, kind, modified_at, modified_by) VALUES ({}, {}, {}, {}, {}, {})", "INSERT INTO agreego.change (\"old\", \"new\", entity_id, id, kind, modified_at, modified_by) VALUES ({}, {}, {}, {}, {}, {}, {})",
Self::quote_literal(&Value::Object(changes)), Self::quote_literal(&old_val_obj),
Self::quote_literal(&new_val_obj),
Self::quote_literal(id_str), Self::quote_literal(id_str),
Self::quote_literal(&Value::String(uuid::Uuid::new_v4().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(change_kind.to_string())),
@ -759,17 +781,20 @@ impl Merger {
Self::quote_literal(&Value::String(user_id.to_string())) 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 self
.db .db
.execute(&change_sql, None) .execute(&change_sql, None)
.map_err(|e| format!("Executor Error in change: {:?}", e))?; .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( fn compare_entities(
@ -821,6 +846,34 @@ impl Merger {
} }
} }
fn format_sql_value(val: &Value, key: &str, entity_type: &Type) -> String {
if val.as_str() == Some("") {
return "NULL".to_string();
}
let mut is_pg_array = false;
if let Some(field_types_map) = entity_type.field_types.as_ref().and_then(|v| v.as_object()) {
if let Some(t_val) = field_types_map.get(key) {
if let Some(t_str) = t_val.as_str() {
if t_str.starts_with('_') {
is_pg_array = true;
}
}
}
}
if is_pg_array && val.is_array() {
let mut s = val.to_string();
if s.starts_with('[') && s.ends_with(']') {
s.replace_range(0..1, "{");
s.replace_range(s.len() - 1..s.len(), "}");
}
Self::quote_literal(&Value::String(s))
} else {
Self::quote_literal(val)
}
}
fn quote_literal(val: &Value) -> String { fn quote_literal(val: &Value) -> String {
match val { match val {
Value::Null => "NULL".to_string(), Value::Null => "NULL".to_string(),

View File

@ -8536,3 +8536,9 @@ fn test_merger_0_7() {
let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR")); let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 7).unwrap(); crate::tests::runner::run_test_case(&path, 0, 7).unwrap();
} }
#[test]
fn test_merger_0_8() {
let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 8).unwrap();
}

View File

@ -1 +1 @@
1.0.76 1.0.80