From a3bd79deefd56a1ab035a6910d54c6bd26ec1b9c Mon Sep 17 00:00:00 2001 From: Alex Groleau Date: Wed, 15 Apr 2026 03:08:11 -0400 Subject: [PATCH] jspg stabilized again --- fixtures/database.json | 263 +++ fixtures/merger.json | 2597 ++++++++++++------------ fixtures/queryer.json | 4213 ++++++++++++++++++++------------------- src/database/mod.rs | 67 +- src/database/schema.rs | 70 +- src/queryer/compiler.rs | 15 +- src/tests/fixtures.rs | 6 + 7 files changed, 3852 insertions(+), 3379 deletions(-) diff --git a/fixtures/database.json b/fixtures/database.json index 6a07651..0abf636 100644 --- a/fixtures/database.json +++ b/fixtures/database.json @@ -664,5 +664,268 @@ } } ] + }, + { + "description": "JSONB boundaries", + "database": { + "relations": [ + { + "id": "33333333-3333-3333-3333-333333333333", + "type": "relation", + "constraint": "fk_invoice_line_invoice", + "source_type": "invoice_line", + "source_columns": [ + "invoice_id" + ], + "destination_type": "invoice", + "destination_columns": [ + "id" + ] + } + ], + "types": [ + { + "name": "entity", + "hierarchy": [ + "entity" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ] + }, + "field_types": { + "id": "uuid", + "archived": "boolean", + "created_at": "timestamptz", + "type": "text" + }, + "schemas": { + "entity": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "uuid" + }, + "type": { + "type": "string" + }, + "archived": { + "type": "boolean" + }, + "created_at": { + "type": "string", + "format": "date-time" + }, + "created": { + "type": "boolean" + } + } + } + }, + "fields": [ + "id", + "type", + "archived", + "created_at" + ], + "variations": [ + "entity", + "invoice", + "invoice_line" + ] + }, + { + "name": "invoice", + "schemas": { + "invoice": { + "type": "entity", + "properties": { + "total": { + "type": "number" + }, + "lines": { + "type": "array", + "items": { + "type": "invoice_line" + } + }, + "metadata_line": { + "type": "invoice_line" + }, + "metadata_lines": { + "type": "array", + "items": { + "type": "invoice_line" + } + }, + "metadata_nested_line": { + "type": "object", + "properties": { + "line": { + "type": "invoice_line" + } + } + }, + "metadata_nested_lines": { + "type": "object", + "properties": { + "lines": { + "type": "array", + "items": { + "type": "invoice_line" + } + } + } + } + } + } + }, + "hierarchy": [ + "invoice", + "entity" + ], + "fields": [ + "id", + "type", + "total", + "metadata_line", + "metadata_lines", + "metadata_nested_line", + "metadata_nested_lines", + "created_at", + "created_by", + "modified_at", + "modified_by", + "archived" + ], + "grouped_fields": { + "invoice": [ + "id", + "type", + "total", + "metadata_line", + "metadata_lines", + "metadata_nested_line", + "metadata_nested_lines" + ], + "entity": [ + "id", + "type", + "created_at", + "created_by", + "modified_at", + "modified_by", + "archived" + ] + }, + "lookup_fields": [ + "id" + ], + "historical": true, + "relationship": false, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "total": "numeric", + "metadata_line": "jsonb", + "metadata_lines": "jsonb", + "metadata_nested_line": "jsonb", + "metadata_nested_lines": "jsonb", + "created_at": "timestamptz", + "created_by": "uuid", + "modified_at": "timestamptz", + "modified_by": "uuid" + }, + "variations": [ + "invoice" + ] + }, + { + "name": "invoice_line", + "schemas": { + "invoice_line": { + "type": "entity", + "properties": { + "invoice_id": { + "type": "string" + }, + "price": { + "type": "number" + } + } + } + }, + "hierarchy": [ + "invoice_line", + "entity" + ], + "fields": [ + "id", + "type", + "invoice_id", + "price", + "created_at", + "created_by", + "modified_at", + "modified_by", + "archived" + ], + "grouped_fields": { + "invoice_line": [ + "id", + "type", + "invoice_id", + "price" + ], + "entity": [ + "id", + "type", + "created_at", + "created_by", + "modified_at", + "modified_by", + "archived" + ] + }, + "lookup_fields": [], + "historical": true, + "relationship": false, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "invoice_id": "uuid", + "price": "numeric", + "created_at": "timestamptz", + "created_by": "uuid", + "modified_at": "timestamptz", + "modified_by": "uuid" + }, + "variations": [ + "invoice_line" + ] + } + ] + }, + "tests": [ + { + "description": "Assert no JSONB paths promoted", + "action": "compile", + "expect": { + "success": true, + "schemas": [ + "entity", + "invoice", + "invoice_line" + ] + } + } + ] } ] \ No newline at end of file diff --git a/fixtures/merger.json b/fixtures/merger.json index 276dbe0..25ed43e 100644 --- a/fixtures/merger.json +++ b/fixtures/merger.json @@ -88,6 +88,33 @@ "id" ], "prefix": null + }, + { + "id": "66666666-6666-6666-6666-666666666666", + "type": "relation", + "constraint": "fk_entity_organization", + "source_type": "entity", + "source_columns": [ + "organization_id" + ], + "destination_type": "organization", + "destination_columns": [ + "id" + ], + "prefix": null + }, + { + "id": "33333333-3333-3333-3333-333333333334", + "type": "relation", + "constraint": "fk_invoice_line_invoice", + "source_type": "invoice_line", + "source_columns": [ + "invoice_id" + ], + "destination_type": "invoice", + "destination_columns": [ + "id" + ] } ], "types": [ @@ -157,7 +184,22 @@ "lookup_fields": [], "historical": true, "notify": true, - "relationship": false + "relationship": false, + "variations": [ + "entity", + "organization", + "user", + "person", + "order", + "order_line", + "relationship", + "contact", + "phone_number", + "email_address", + "attachment", + "invoice", + "invoice_line" + ] }, { "name": "organization", @@ -829,6 +871,50 @@ }, { "name": "invoice", + "schemas": { + "invoice": { + "type": "entity", + "properties": { + "total": { + "type": "number" + }, + "lines": { + "type": "array", + "items": { + "type": "invoice_line" + } + }, + "metadata_line": { + "type": "invoice_line" + }, + "metadata_lines": { + "type": "array", + "items": { + "type": "invoice_line" + } + }, + "metadata_nested_line": { + "type": "object", + "properties": { + "line": { + "type": "invoice_line" + } + } + }, + "metadata_nested_lines": { + "type": "object", + "properties": { + "lines": { + "type": "array", + "items": { + "type": "invoice_line" + } + } + } + } + } + } + }, "hierarchy": [ "invoice", "entity" @@ -836,8 +922,11 @@ "fields": [ "id", "type", - "number", - "metadata", + "total", + "metadata_line", + "metadata_lines", + "metadata_nested_line", + "metadata_nested_lines", "created_at", "created_by", "modified_at", @@ -848,8 +937,11 @@ "invoice": [ "id", "type", - "number", - "metadata" + "total", + "metadata_line", + "metadata_lines", + "metadata_nested_line", + "metadata_nested_lines" ], "entity": [ "id", @@ -870,43 +962,84 @@ "id": "uuid", "type": "text", "archived": "boolean", - "number": "text", - "metadata": "jsonb", + "total": "numeric", + "metadata_line": "jsonb", + "metadata_lines": "jsonb", + "metadata_nested_line": "jsonb", + "metadata_nested_lines": "jsonb", "created_at": "timestamptz", "created_by": "uuid", "modified_at": "timestamptz", "modified_by": "uuid" }, + "variations": [ + "invoice" + ] + }, + { + "name": "invoice_line", "schemas": { - "invoice": { + "invoice_line": { "type": "entity", "properties": { - "id": { + "invoice_id": { "type": "string" }, - "number": { - "type": "string" - }, - "metadata": { - "type": "object", - "properties": { - "internal_note": { - "type": "string" - }, - "customer_snapshot": { - "type": "entity" - }, - "related_rules": { - "type": "array", - "items": { - "type": "entity" - } - } - } + "price": { + "type": "number" } } } - } + }, + "hierarchy": [ + "invoice_line", + "entity" + ], + "fields": [ + "id", + "type", + "invoice_id", + "price", + "created_at", + "created_by", + "modified_at", + "modified_by", + "archived" + ], + "grouped_fields": { + "invoice_line": [ + "id", + "type", + "invoice_id", + "price" + ], + "entity": [ + "id", + "type", + "created_at", + "created_by", + "modified_at", + "modified_by", + "archived" + ] + }, + "lookup_fields": [], + "historical": true, + "relationship": false, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "invoice_id": "uuid", + "price": "numeric", + "created_at": "timestamptz", + "created_by": "uuid", + "modified_at": "timestamptz", + "modified_by": "uuid" + }, + "variations": [ + "invoice_line" + ] } ] }, @@ -936,98 +1069,98 @@ "sql": [ [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ")", "VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:person_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'person'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:person_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"organization\" (", - " \"id\",", - " \"type\"", + " \"id\",", + " \"type\"", ")", "VALUES (", - " '{{uuid:person_id}}',", - " 'person'", + " '{{uuid:person_id}}',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"user\" (", - " \"id\",", - " \"type\"", + " \"id\",", + " \"type\"", ")", "VALUES (", - " '{{uuid:person_id}}',", - " 'person'", + " '{{uuid:person_id}}',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"person\" (", - " \"first_name\",", - " \"id\",", - " \"last_name\",", - " \"type\"", + " \"first_name\",", + " \"id\",", + " \"last_name\",", + " \"type\"", ")", "VALUES (", - " 'IncompleteFirst',", - " '{{uuid:person_id}}',", - " 'IncompleteLast',", - " 'person'", + " 'IncompleteFirst',", + " '{{uuid:person_id}}',", + " 'IncompleteLast',", + " 'person'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"first_name\":\"IncompleteFirst\",", - " \"last_name\":\"IncompleteLast\",", - " \"type\":\"person\"", - " }',", - " '{{uuid:person_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"first_name\":\"IncompleteFirst\",", + " \"last_name\":\"IncompleteLast\",", + " \"type\":\"person\"", + " }',", + " '{{uuid:person_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"first_name\":\"IncompleteFirst\",", - " \"id\":\"{{uuid:person_id}}\",", - " \"last_name\":\"IncompleteLast\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"type\":\"person\"", - " },", - " \"new\":{", - " \"first_name\":\"IncompleteFirst\",", - " \"last_name\":\"IncompleteLast\",", - " \"type\":\"person\"", - " }", - " }')" + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"first_name\":\"IncompleteFirst\",", + " \"id\":\"{{uuid:person_id}}\",", + " \"last_name\":\"IncompleteLast\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"type\":\"person\"", + " },", + " \"new\":{", + " \"first_name\":\"IncompleteFirst\",", + " \"last_name\":\"IncompleteLast\",", + " \"type\":\"person\"", + " }", + " }')" ] ] } @@ -1065,73 +1198,73 @@ "LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id", "LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id", "WHERE (", - " \"first_name\" = 'LookupFirst'", - " AND \"last_name\" = 'LookupLast'", - " AND \"date_of_birth\" = '1990-01-01T00:00:00Z'", - " AND \"pronouns\" = 'they/them'", + " \"first_name\" = 'LookupFirst'", + " AND \"last_name\" = 'LookupLast'", + " AND \"date_of_birth\" = '1990-01-01T00:00:00Z'", + " AND \"pronouns\" = 'they/them'", ")" ], [ "UPDATE agreego.\"person\"", "SET", - " \"contact_id\" = 'abc-contact'", + " \"contact_id\" = 'abc-contact'", "WHERE", - " id = '22222222-2222-2222-2222-222222222222'" + " id = '22222222-2222-2222-2222-222222222222'" ], [ "UPDATE agreego.\"entity\"", "SET", - " \"modified_at\" = '2026-03-10T00:00:00Z',", - " \"modified_by\" = '00000000-0000-0000-0000-000000000000'", + " \"modified_at\" = '2026-03-10T00:00:00Z',", + " \"modified_by\" = '00000000-0000-0000-0000-000000000000'", "WHERE", - " id = '22222222-2222-2222-2222-222222222222'" + " id = '22222222-2222-2222-2222-222222222222'" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " '{", - " \"contact_id\":\"old-contact\"", - " }',", - " '{", - " \"contact_id\":\"abc-contact\",", - " \"type\":\"person\"", - " }',", - " '22222222-2222-2222-2222-222222222222',", - " '{{uuid}}',", - " 'update',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " '{", + " \"contact_id\":\"old-contact\"", + " }',", + " '{", + " \"contact_id\":\"abc-contact\",", + " \"type\":\"person\"", + " }',", + " '22222222-2222-2222-2222-222222222222',", + " '{{uuid}}',", + " 'update',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"contact_id\":\"abc-contact\",", - " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", - " \"first_name\":\"LookupFirst\",", - " \"id\":\"22222222-2222-2222-2222-222222222222\",", - " \"last_name\":\"LookupLast\",", - " \"modified_at\":\"2026-03-10T00:00:00Z\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"pronouns\":\"they/them\",", - " \"type\":\"person\"", - " },", - " \"new\":{", - " \"contact_id\":\"abc-contact\",", - " \"type\":\"person\"", - " },", - " \"old\":{", - " \"contact_id\":\"old-contact\"", - " }", - " }')" + " \"complete\":{", + " \"contact_id\":\"abc-contact\",", + " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", + " \"first_name\":\"LookupFirst\",", + " \"id\":\"22222222-2222-2222-2222-222222222222\",", + " \"last_name\":\"LookupLast\",", + " \"modified_at\":\"2026-03-10T00:00:00Z\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"pronouns\":\"they/them\",", + " \"type\":\"person\"", + " },", + " \"new\":{", + " \"contact_id\":\"abc-contact\",", + " \"type\":\"person\"", + " },", + " \"old\":{", + " \"contact_id\":\"old-contact\"", + " }", + " }')" ] ] } @@ -1170,76 +1303,76 @@ "LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id", "LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id", "WHERE", - " t1.id = '33333333-3333-3333-3333-333333333333'", - " OR (", - " \"first_name\" = 'LookupFirst'", - " AND \"last_name\" = 'LookupLast'", - " AND \"date_of_birth\" = '1990-01-01T00:00:00Z'", - " AND \"pronouns\" = 'they/them'", - " )" + " t1.id = '33333333-3333-3333-3333-333333333333'", + " OR (", + " \"first_name\" = 'LookupFirst'", + " AND \"last_name\" = 'LookupLast'", + " AND \"date_of_birth\" = '1990-01-01T00:00:00Z'", + " AND \"pronouns\" = 'they/them'", + " )" ], [ "UPDATE agreego.\"person\"", "SET", - " \"contact_id\" = 'abc-contact'", + " \"contact_id\" = 'abc-contact'", "WHERE", - " id = '22222222-2222-2222-2222-222222222222'" + " id = '22222222-2222-2222-2222-222222222222'" ], [ "UPDATE agreego.\"entity\"", "SET", - " \"modified_at\" = '2026-03-10T00:00:00Z',", - " \"modified_by\" = '00000000-0000-0000-0000-000000000000'", + " \"modified_at\" = '2026-03-10T00:00:00Z',", + " \"modified_by\" = '00000000-0000-0000-0000-000000000000'", "WHERE", - " id = '22222222-2222-2222-2222-222222222222'" + " id = '22222222-2222-2222-2222-222222222222'" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " '{", - " \"contact_id\":\"old-contact\"", - " }',", - " '{", - " \"contact_id\":\"abc-contact\",", - " \"type\":\"person\"", - " }',", - " '22222222-2222-2222-2222-222222222222',", - " '{{uuid}}',", - " 'update',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " '{", + " \"contact_id\":\"old-contact\"", + " }',", + " '{", + " \"contact_id\":\"abc-contact\",", + " \"type\":\"person\"", + " }',", + " '22222222-2222-2222-2222-222222222222',", + " '{{uuid}}',", + " 'update',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"contact_id\":\"abc-contact\",", - " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", - " \"first_name\":\"LookupFirst\",", - " \"id\":\"22222222-2222-2222-2222-222222222222\",", - " \"last_name\":\"LookupLast\",", - " \"modified_at\":\"2026-03-10T00:00:00Z\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"pronouns\":\"they/them\",", - " \"type\":\"person\"", - " },", - " \"new\":{", - " \"contact_id\":\"abc-contact\",", - " \"type\":\"person\"", - " },", - " \"old\":{", - " \"contact_id\":\"old-contact\"", - " },", - " \"replaces\":\"33333333-3333-3333-3333-333333333333\"", - " }')" + " \"complete\":{", + " \"contact_id\":\"abc-contact\",", + " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", + " \"first_name\":\"LookupFirst\",", + " \"id\":\"22222222-2222-2222-2222-222222222222\",", + " \"last_name\":\"LookupLast\",", + " \"modified_at\":\"2026-03-10T00:00:00Z\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"pronouns\":\"they/them\",", + " \"type\":\"person\"", + " },", + " \"new\":{", + " \"contact_id\":\"abc-contact\",", + " \"type\":\"person\"", + " },", + " \"old\":{", + " \"contact_id\":\"old-contact\"", + " },", + " \"replaces\":\"33333333-3333-3333-3333-333333333333\"", + " }')" ] ] } @@ -1277,32 +1410,32 @@ "LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id", "LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id", "WHERE", - " t1.id = '33333333-3333-3333-3333-333333333333'", - " OR (", - " \"first_name\" = 'LookupFirst'", - " AND \"last_name\" = 'LookupLast'", - " AND \"date_of_birth\" = '1990-01-01T00:00:00Z'", - " AND \"pronouns\" = 'they/them'", - " )" + " t1.id = '33333333-3333-3333-3333-333333333333'", + " OR (", + " \"first_name\" = 'LookupFirst'", + " AND \"last_name\" = 'LookupLast'", + " AND \"date_of_birth\" = '1990-01-01T00:00:00Z'", + " AND \"pronouns\" = 'they/them'", + " )" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"contact_id\":\"old-contact\",", - " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", - " \"first_name\":\"LookupFirst\",", - " \"id\":\"22222222-2222-2222-2222-222222222222\",", - " \"last_name\":\"LookupLast\",", - " \"modified_at\":\"2026-03-10T00:00:00Z\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"pronouns\":\"they/them\",", - " \"type\":\"person\"", - " },", - " \"new\":{", - " \"type\":\"person\"", - " },", - " \"replaces\":\"33333333-3333-3333-3333-333333333333\"", - " }')" + " \"complete\":{", + " \"contact_id\":\"old-contact\",", + " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", + " \"first_name\":\"LookupFirst\",", + " \"id\":\"22222222-2222-2222-2222-222222222222\",", + " \"last_name\":\"LookupLast\",", + " \"modified_at\":\"2026-03-10T00:00:00Z\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"pronouns\":\"they/them\",", + " \"type\":\"person\"", + " },", + " \"new\":{", + " \"type\":\"person\"", + " },", + " \"replaces\":\"33333333-3333-3333-3333-333333333333\"", + " }')" ] ] } @@ -1339,66 +1472,66 @@ [ "UPDATE agreego.\"person\"", "SET", - " \"first_name\" = 'NewFirst',", - " \"last_name\" = 'NewLast'", + " \"first_name\" = 'NewFirst',", + " \"last_name\" = 'NewLast'", "WHERE", - " id = '11111111-1111-1111-1111-111111111111'" + " id = '11111111-1111-1111-1111-111111111111'" ], [ "UPDATE agreego.\"entity\"", "SET", - " \"modified_at\" = '2026-03-10T00:00:00Z',", - " \"modified_by\" = '00000000-0000-0000-0000-000000000000'", + " \"modified_at\" = '2026-03-10T00:00:00Z',", + " \"modified_by\" = '00000000-0000-0000-0000-000000000000'", "WHERE", - " id = '11111111-1111-1111-1111-111111111111'" + " id = '11111111-1111-1111-1111-111111111111'" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " '{", - " \"first_name\":\"OldFirst\",", - " \"last_name\":\"OldLast\"", - " }',", - " '{", - " \"first_name\":\"NewFirst\",", - " \"last_name\":\"NewLast\",", - " \"type\":\"person\"", - " }',", - " '11111111-1111-1111-1111-111111111111',", - " '{{uuid}}',", - " 'update',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " '{", + " \"first_name\":\"OldFirst\",", + " \"last_name\":\"OldLast\"", + " }',", + " '{", + " \"first_name\":\"NewFirst\",", + " \"last_name\":\"NewLast\",", + " \"type\":\"person\"", + " }',", + " '11111111-1111-1111-1111-111111111111',", + " '{{uuid}}',", + " 'update',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"first_name\":\"NewFirst\",", - " \"id\":\"11111111-1111-1111-1111-111111111111\",", - " \"last_name\":\"NewLast\",", - " \"modified_at\":\"2026-03-10T00:00:00Z\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"type\":\"person\"", - " },", - " \"new\":{", - " \"first_name\":\"NewFirst\",", - " \"last_name\":\"NewLast\",", - " \"type\":\"person\"", - " },", - " \"old\":{", - " \"first_name\":\"OldFirst\",", - " \"last_name\":\"OldLast\"", - " }", - " }')" + " \"complete\":{", + " \"first_name\":\"NewFirst\",", + " \"id\":\"11111111-1111-1111-1111-111111111111\",", + " \"last_name\":\"NewLast\",", + " \"modified_at\":\"2026-03-10T00:00:00Z\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"type\":\"person\"", + " },", + " \"new\":{", + " \"first_name\":\"NewFirst\",", + " \"last_name\":\"NewLast\",", + " \"type\":\"person\"", + " },", + " \"old\":{", + " \"first_name\":\"OldFirst\",", + " \"last_name\":\"OldLast\"", + " }", + " }')" ] ] } @@ -1428,108 +1561,108 @@ ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ")", "VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '123',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'person'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '123',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"organization\" (", - " \"id\",", - " \"type\"", + " \"id\",", + " \"type\"", ")", "VALUES (", - " '123',", - " 'person'", + " '123',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"user\" (", - " \"id\",", - " \"type\"", + " \"id\",", + " \"type\"", ")", "VALUES (", - " '123',", - " 'person'", + " '123',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"person\" (", - " \"date_of_birth\",", - " \"first_name\",", - " \"id\",", - " \"last_name\",", - " \"pronouns\",", - " \"type\"", + " \"date_of_birth\",", + " \"first_name\",", + " \"id\",", + " \"last_name\",", + " \"pronouns\",", + " \"type\"", ")", "VALUES (", - " '1990-01-01T00:00:00Z',", - " 'John',", - " '123',", - " 'Doe',", - " NULL,", - " 'person'", + " '1990-01-01T00:00:00Z',", + " 'John',", + " '123',", + " 'Doe',", + " NULL,", + " 'person'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", - " \"first_name\":\"John\",", - " \"last_name\":\"Doe\",", - " \"pronouns\":\"\",", - " \"type\":\"person\"", - " }',", - " '123',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", + " \"first_name\":\"John\",", + " \"last_name\":\"Doe\",", + " \"pronouns\":\"\",", + " \"type\":\"person\"", + " }',", + " '123',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", - " \"first_name\":\"John\",", - " \"id\":\"123\",", - " \"last_name\":\"Doe\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"pronouns\":\"\",", - " \"type\":\"person\"", - " },", - " \"new\":{", - " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", - " \"first_name\":\"John\",", - " \"last_name\":\"Doe\",", - " \"pronouns\":\"\",", - " \"type\":\"person\"", - " }", - " }')" + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", + " \"first_name\":\"John\",", + " \"id\":\"123\",", + " \"last_name\":\"Doe\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"pronouns\":\"\",", + " \"type\":\"person\"", + " },", + " \"new\":{", + " \"date_of_birth\":\"1990-01-01T00:00:00Z\",", + " \"first_name\":\"John\",", + " \"last_name\":\"Doe\",", + " \"pronouns\":\"\",", + " \"type\":\"person\"", + " }", + " }')" ] ] } @@ -1553,178 +1686,178 @@ "sql": [ [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ")", "VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:customer_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'person'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:customer_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"organization\" (", - " \"id\",", - " \"type\"", + " \"id\",", + " \"type\"", ")", "VALUES (", - " '{{uuid:customer_id}}',", - " 'person'", + " '{{uuid:customer_id}}',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"user\" (", - " \"id\",", - " \"type\"", + " \"id\",", + " \"type\"", ")", "VALUES (", - " '{{uuid:customer_id}}',", - " 'person'", + " '{{uuid:customer_id}}',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"person\" (", - " \"date_of_birth\",", - " \"first_name\",", - " \"id\",", - " \"last_name\",", - " \"type\"", + " \"date_of_birth\",", + " \"first_name\",", + " \"id\",", + " \"last_name\",", + " \"type\"", ")", "VALUES (", - " '2000-01-01',", - " 'Bob',", - " '{{uuid:customer_id}}',", - " 'Smith',", - " 'person'", + " '2000-01-01',", + " 'Bob',", + " '{{uuid:customer_id}}',", + " 'Smith',", + " 'person'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"date_of_birth\":\"2000-01-01\",", - " \"first_name\":\"Bob\",", - " \"last_name\":\"Smith\",", - " \"type\":\"person\"", - " }',", - " '{{uuid:customer_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"date_of_birth\":\"2000-01-01\",", + " \"first_name\":\"Bob\",", + " \"last_name\":\"Smith\",", + " \"type\":\"person\"", + " }',", + " '{{uuid:customer_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ")", "VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:order_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'order'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:order_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'order'", ")" ], [ "INSERT INTO agreego.\"order\" (", - " \"customer_id\",", - " \"id\",", - " \"total\",", - " \"type\"", + " \"customer_id\",", + " \"id\",", + " \"total\",", + " \"type\"", ")", "VALUES (", - " '{{uuid:customer_id}}',", - " '{{uuid:order_id}}',", - " 100,", - " 'order'", + " '{{uuid:customer_id}}',", + " '{{uuid:order_id}}',", + " 100,", + " 'order'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"customer_id\":\"{{uuid:customer_id}}\",", - " \"total\":100.0,", - " \"type\":\"order\"", - " }',", - " '{{uuid:order_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"customer_id\":\"{{uuid:customer_id}}\",", + " \"total\":100.0,", + " \"type\":\"order\"", + " }',", + " '{{uuid:order_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"customer_id\":\"{{uuid:customer_id}}\",", - " \"id\":\"{{uuid:order_id}}\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"total\":100.0,", - " \"type\":\"order\"", - " },", - " \"new\":{", - " \"customer_id\":\"{{uuid:customer_id}}\",", - " \"total\":100.0,", - " \"type\":\"order\"", - " }", - " }')" + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"customer_id\":\"{{uuid:customer_id}}\",", + " \"id\":\"{{uuid:order_id}}\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"total\":100.0,", + " \"type\":\"order\"", + " },", + " \"new\":{", + " \"customer_id\":\"{{uuid:customer_id}}\",", + " \"total\":100.0,", + " \"type\":\"order\"", + " }", + " }')" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"date_of_birth\":\"2000-01-01\",", - " \"first_name\":\"Bob\",", - " \"id\":\"{{uuid:customer_id}}\",", - " \"last_name\":\"Smith\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"type\":\"person\"", - " },", - " \"new\":{", - " \"date_of_birth\":\"2000-01-01\",", - " \"first_name\":\"Bob\",", - " \"last_name\":\"Smith\",", - " \"type\":\"person\"", - " }", - " }')" + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"date_of_birth\":\"2000-01-01\",", + " \"first_name\":\"Bob\",", + " \"id\":\"{{uuid:customer_id}}\",", + " \"last_name\":\"Smith\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"type\":\"person\"", + " },", + " \"new\":{", + " \"date_of_birth\":\"2000-01-01\",", + " \"first_name\":\"Bob\",", + " \"last_name\":\"Smith\",", + " \"type\":\"person\"", + " }", + " }')" ] ] } @@ -1756,152 +1889,152 @@ ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ")", "VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'abc',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'order'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'abc',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'order'", ")" ], [ "INSERT INTO agreego.\"order\" (", - " \"id\",", - " \"total\",", - " \"type\"", + " \"id\",", + " \"total\",", + " \"type\"", ")", "VALUES (", - " 'abc',", - " 99,", - " 'order'", + " 'abc',", + " 99,", + " 'order'", ")" ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ")", "VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:line_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'order_line'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:line_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'order_line'", ")" ], [ "INSERT INTO agreego.\"order_line\" (", - " \"id\",", - " \"order_id\",", - " \"price\",", - " \"product\",", - " \"type\")", + " \"id\",", + " \"order_id\",", + " \"price\",", + " \"product\",", + " \"type\")", "VALUES (", - " '{{uuid:line_id}}',", - " 'abc',", - " 99,", - " 'Widget',", - " 'order_line'", + " '{{uuid:line_id}}',", + " 'abc',", + " 99,", + " 'Widget',", + " 'order_line'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"order_id\":\"abc\",", - " \"price\":99.0,", - " \"product\":\"Widget\",", - " \"type\":\"order_line\"", - " }',", - " '{{uuid:line_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " }',", + " '{{uuid:line_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"total\":99.0,", - " \"type\":\"order\"", - " }',", - " 'abc',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"total\":99.0,", + " \"type\":\"order\"", + " }',", + " 'abc',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"abc\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"total\":99.0,", - " \"type\":\"order\"", - " },", - " \"new\":{", - " \"total\":99.0,", - " \"type\":\"order\"", - " }", - " }')" + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"abc\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"total\":99.0,", + " \"type\":\"order\"", + " },", + " \"new\":{", + " \"total\":99.0,", + " \"type\":\"order\"", + " }", + " }')" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"{{uuid:line_id}}\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"order_id\":\"abc\",", - " \"price\":99.0,", - " \"product\":\"Widget\",", - " \"type\":\"order_line\"", - " },", - " \"new\":{", - " \"order_id\":\"abc\",", - " \"price\":99.0,", - " \"product\":\"Widget\",", - " \"type\":\"order_line\"", - " }", - " }')" + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"{{uuid:line_id}}\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " },", + " \"new\":{", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " }", + " }')" ] ] } @@ -1948,545 +2081,545 @@ "sql": [ [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ") VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:person_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'person'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:person_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"organization\" (", - " \"id\",", - " \"type\"", + " \"id\",", + " \"type\"", ") VALUES (", - " '{{uuid:person_id}}',", - " 'person'", + " '{{uuid:person_id}}',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"user\" (", - " \"id\",", - " \"type\"", + " \"id\",", + " \"type\"", ") VALUES (", - " '{{uuid:person_id}}',", - " 'person'", + " '{{uuid:person_id}}',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"person\" (", - " \"first_name\",", - " \"id\",", - " \"last_name\",", - " \"type\"", + " \"first_name\",", + " \"id\",", + " \"last_name\",", + " \"type\"", ") VALUES (", - " 'Relation',", - " '{{uuid:person_id}}',", - " 'Test',", - " 'person'", + " 'Relation',", + " '{{uuid:person_id}}',", + " 'Test',", + " 'person'", ")" ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ") VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:phone1_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'phone_number'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:phone1_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'phone_number'", ")" ], [ "INSERT INTO agreego.\"phone_number\" (", - " \"number\"", + " \"number\"", ") VALUES (", - " '555-0001'", + " '555-0001'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ") VALUES (", - " NULL,", - " '{", - " \"number\":\"555-0001\",", - " \"type\":\"phone_number\"", - " }',", - " '{{uuid:phone1_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"number\":\"555-0001\",", + " \"type\":\"phone_number\"", + " }',", + " '{{uuid:phone1_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ") VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:contact1_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'contact'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:contact1_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'contact'", ")" ], [ "INSERT INTO agreego.\"relationship\" (", - " \"source_id\",", - " \"source_type\",", - " \"target_id\",", - " \"target_type\"", + " \"source_id\",", + " \"source_type\",", + " \"target_id\",", + " \"target_type\"", ") VALUES (", - " '{{uuid:person_id}}',", - " 'person',", - " '{{uuid:phone1_id}}',", - " 'phone_number'", + " '{{uuid:person_id}}',", + " 'person',", + " '{{uuid:phone1_id}}',", + " 'phone_number'", ")" ], [ "INSERT INTO agreego.\"contact\" (", - " \"is_primary\"", + " \"is_primary\"", ") VALUES (", - " true", + " true", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ") VALUES (", - " NULL,", - " '{", - " \"is_primary\":true,", - " \"source_id\":\"{{uuid:person_id}}\",", - " \"source_type\":\"person\",", - " \"target_id\":\"{{uuid:phone1_id}}\",", - " \"target_type\":\"phone_number\",", - " \"type\":\"contact\"", - " }',", - " '{{uuid:contact1_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"is_primary\":true,", + " \"source_id\":\"{{uuid:person_id}}\",", + " \"source_type\":\"person\",", + " \"target_id\":\"{{uuid:phone1_id}}\",", + " \"target_type\":\"phone_number\",", + " \"type\":\"contact\"", + " }',", + " '{{uuid:contact1_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ") VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:email1_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'email_address'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:email1_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'email_address'", ")" ], [ "INSERT INTO agreego.\"email_address\" (", - " \"address\"", + " \"address\"", ") VALUES (", - " 'test@example.com'", + " 'test@example.com'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ") VALUES (", - " NULL,", - " '{", - " \"address\":\"test@example.com\",", - " \"type\":\"email_address\"", - " }',", - " '{{uuid:email1_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"address\":\"test@example.com\",", + " \"type\":\"email_address\"", + " }',", + " '{{uuid:email1_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ") VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:contact2_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'contact'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:contact2_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'contact'", ")" ], [ "INSERT INTO agreego.\"relationship\" (", - " \"source_id\",", - " \"source_type\",", - " \"target_id\",", - " \"target_type\"", + " \"source_id\",", + " \"source_type\",", + " \"target_id\",", + " \"target_type\"", ") VALUES (", - " '{{uuid:person_id}}',", - " 'person',", - " '{{uuid:email1_id}}',", - " 'email_address'", + " '{{uuid:person_id}}',", + " 'person',", + " '{{uuid:email1_id}}',", + " 'email_address'", ")" ], [ "INSERT INTO agreego.\"contact\" (", - " \"is_primary\"", + " \"is_primary\"", ") VALUES (", - " false", + " false", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ") VALUES (", - " NULL,", - " '{", - " \"is_primary\":false,", - " \"source_id\":\"{{uuid:person_id}}\",", - " \"source_type\":\"person\",", - " \"target_id\":\"{{uuid:email1_id}}\",", - " \"target_type\":\"email_address\",", - " \"type\":\"contact\"", - " }',", - " '{{uuid:contact2_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"is_primary\":false,", + " \"source_id\":\"{{uuid:person_id}}\",", + " \"source_type\":\"person\",", + " \"target_id\":\"{{uuid:email1_id}}\",", + " \"target_type\":\"email_address\",", + " \"type\":\"contact\"", + " }',", + " '{{uuid:contact2_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ") VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:email2_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'email_address'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:email2_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'email_address'", ")" ], [ "INSERT INTO agreego.\"email_address\" (", - " \"address\"", + " \"address\"", ") VALUES (", - " 'test2@example.com'", + " 'test2@example.com'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ") VALUES (", - " NULL,", - " '{", - " \"address\":\"test2@example.com\",", - " \"type\":\"email_address\"", - " }',", - " '{{uuid:email2_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"address\":\"test2@example.com\",", + " \"type\":\"email_address\"", + " }',", + " '{{uuid:email2_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ") VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:contact3_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'contact'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:contact3_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'contact'", ")" ], [ "INSERT INTO agreego.\"relationship\" (", - " \"source_id\",", - " \"source_type\",", - " \"target_id\",", - " \"target_type\"", + " \"source_id\",", + " \"source_type\",", + " \"target_id\",", + " \"target_type\"", ") VALUES (", - " '{{uuid:person_id}}',", - " 'person',", - " '{{uuid:email2_id}}',", - " 'email_address'", + " '{{uuid:person_id}}',", + " 'person',", + " '{{uuid:email2_id}}',", + " 'email_address'", ")" ], [ "INSERT INTO agreego.\"contact\" (", - " \"is_primary\"", + " \"is_primary\"", ") VALUES (", - " false", + " false", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ") VALUES (", - " NULL,", - " '{", - " \"is_primary\":false,", - " \"source_id\":\"{{uuid:person_id}}\",", - " \"source_type\":\"person\",", - " \"target_id\":\"{{uuid:email2_id}}\",", - " \"target_type\":\"email_address\",", - " \"type\":\"contact\"", - " }',", - " '{{uuid:contact3_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"is_primary\":false,", + " \"source_id\":\"{{uuid:person_id}}\",", + " \"source_type\":\"person\",", + " \"target_id\":\"{{uuid:email2_id}}\",", + " \"target_type\":\"email_address\",", + " \"type\":\"contact\"", + " }',", + " '{{uuid:contact3_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ") VALUES (", - " NULL,", - " '{", - " \"first_name\":\"Relation\",", - " \"last_name\":\"Test\",", - " \"type\":\"person\"", - " }',", - " '{{uuid:person_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"first_name\":\"Relation\",", + " \"last_name\":\"Test\",", + " \"type\":\"person\"", + " }',", + " '{{uuid:person_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"first_name\":\"Relation\",", - " \"id\":\"{{uuid:person_id}}\",", - " \"last_name\":\"Test\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"type\":\"person\"", - " },", - " \"new\":{", - " \"first_name\":\"Relation\",", - " \"last_name\":\"Test\",", - " \"type\":\"person\"", - " }", - " }')" - ], - [ - "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"{{uuid:contact1_id}}\",", - " \"is_primary\":true,", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"source_id\":\"{{uuid:person_id}}\",", - " \"source_type\":\"person\",", - " \"target_id\":\"{{uuid:phone1_id}}\",", - " \"target_type\":\"phone_number\",", - " \"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', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"{{uuid:phone1_id}}\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"number\":\"555-0001\",", - " \"type\":\"phone_number\"", - " },", - " \"new\":{", - " \"number\":\"555-0001\",", - " \"type\":\"phone_number\"", - " }", - " }')" - ], - [ - "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"{{uuid:contact2_id}}\",", - " \"is_primary\":false,", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"source_id\":\"{{uuid:person_id}}\",", - " \"source_type\":\"person\",", - " \"target_id\":\"{{uuid:email1_id}}\",", - " \"target_type\":\"email_address\",", - " \"type\":\"contact\"", - " },", + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"first_name\":\"Relation\",", + " \"id\":\"{{uuid:person_id}}\",", + " \"last_name\":\"Test\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"type\":\"person\"", + " },", " \"new\":{", - " \"is_primary\":false,", - " \"source_id\":\"{{uuid:person_id}}\",", - " \"source_type\":\"person\",", - " \"target_id\":\"{{uuid:email1_id}}\",", - " \"target_type\":\"email_address\",", - " \"type\":\"contact\"", + " \"first_name\":\"Relation\",", + " \"last_name\":\"Test\",", + " \"type\":\"person\"", " }", + " }')" + ], + [ + "SELECT pg_notify('entity', '{", + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"{{uuid:contact1_id}}\",", + " \"is_primary\":true,", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"source_id\":\"{{uuid:person_id}}\",", + " \"source_type\":\"person\",", + " \"target_id\":\"{{uuid:phone1_id}}\",", + " \"target_type\":\"phone_number\",", + " \"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', '{", + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"{{uuid:phone1_id}}\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"number\":\"555-0001\",", + " \"type\":\"phone_number\"", + " },", + " \"new\":{", + " \"number\":\"555-0001\",", + " \"type\":\"phone_number\"", + " }", + " }')" + ], + [ + "SELECT pg_notify('entity', '{", + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"{{uuid:contact2_id}}\",", + " \"is_primary\":false,", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"source_id\":\"{{uuid:person_id}}\",", + " \"source_type\":\"person\",", + " \"target_id\":\"{{uuid:email1_id}}\",", + " \"target_type\":\"email_address\",", + " \"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', '{", - " \"complete\":{", - " \"address\":\"test@example.com\",", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"{{uuid:email1_id}}\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"type\":\"email_address\"", - " },", - " \"new\":{", - " \"address\":\"test@example.com\",", - " \"type\":\"email_address\"", - " }", + " \"complete\":{", + " \"address\":\"test@example.com\",", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"{{uuid:email1_id}}\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"type\":\"email_address\"", + " },", + " \"new\":{", + " \"address\":\"test@example.com\",", + " \"type\":\"email_address\"", + " }", "}')" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"{{uuid:contact3_id}}\",", - " \"is_primary\":false,", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"source_id\":\"{{uuid:person_id}}\",", - " \"source_type\":\"person\",", - " \"target_id\":\"{{uuid:email2_id}}\",", - " \"target_type\":\"email_address\",", - " \"type\":\"contact\"", - " },", - " \"new\":{", - " \"is_primary\":false,", - " \"source_id\":\"{{uuid:person_id}}\",", - " \"source_type\":\"person\",", - " \"target_id\":\"{{uuid:email2_id}}\",", - " \"target_type\":\"email_address\",", - " \"type\":\"contact\"", - " }", + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"{{uuid:contact3_id}}\",", + " \"is_primary\":false,", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"source_id\":\"{{uuid:person_id}}\",", + " \"source_type\":\"person\",", + " \"target_id\":\"{{uuid:email2_id}}\",", + " \"target_type\":\"email_address\",", + " \"type\":\"contact\"", + " },", + " \"new\":{", + " \"is_primary\":false,", + " \"source_id\":\"{{uuid:person_id}}\",", + " \"source_type\":\"person\",", + " \"target_id\":\"{{uuid:email2_id}}\",", + " \"target_type\":\"email_address\",", + " \"type\":\"contact\"", + " }", "}')" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"address\":\"test2@example.com\",", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"{{uuid:email2_id}}\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"type\":\"email_address\"", - " },", - " \"new\":{", - " \"address\":\"test2@example.com\",", - " \"type\":\"email_address\"", - " }", + " \"complete\":{", + " \"address\":\"test2@example.com\",", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"{{uuid:email2_id}}\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"type\":\"email_address\"", + " },", + " \"new\":{", + " \"address\":\"test2@example.com\",", + " \"type\":\"email_address\"", + " }", "}')" ] ] @@ -2523,51 +2656,51 @@ ], [ "UPDATE agreego.\"entity\" SET", - " \"archived\" = true,", - " \"modified_at\" = '{{timestamp}}',", - " \"modified_by\" = '00000000-0000-0000-0000-000000000000'", + " \"archived\" = true,", + " \"modified_at\" = '{{timestamp}}',", + " \"modified_by\" = '00000000-0000-0000-0000-000000000000'", "WHERE id = 'abc-archived'" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ") VALUES (", - " '{", - " \"archived\":false", - " }',", - " '{\"archived\":true,\"type\":\"person\"}',", - " 'abc-archived',", - " '{{uuid}}',", - " 'delete',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " '{", + " \"archived\":false", + " }',", + " '{\"archived\":true,\"type\":\"person\"}',", + " 'abc-archived',", + " '{{uuid}}',", + " 'delete',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"archived\":true,", - " \"first_name\":\"ArchivedFirst\",", - " \"id\":\"abc-archived\",", - " \"last_name\":\"ArchivedLast\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"type\":\"person\"", - " },", - " \"new\":{", - " \"archived\":true,", - " \"type\":\"person\"", - " },", - " \"old\":{", - " \"archived\":false", - " }", - " }')" + " \"complete\":{", + " \"archived\":true,", + " \"first_name\":\"ArchivedFirst\",", + " \"id\":\"abc-archived\",", + " \"last_name\":\"ArchivedLast\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"type\":\"person\"", + " },", + " \"new\":{", + " \"archived\":true,", + " \"type\":\"person\"", + " },", + " \"old\":{", + " \"archived\":false", + " }", + " }')" ] ] } @@ -2594,83 +2727,83 @@ "sql": [ [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"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'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:attachment_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'attachment'", ")" ], [ "INSERT INTO agreego.\"attachment\" (", - " \"flags\",", - " \"id\",", - " \"other_metadata\",", - " \"type\",", - " \"type_metadata\"", + " \"flags\",", + " \"id\",", + " \"other_metadata\",", + " \"type\",", + " \"type_metadata\"", ")", "VALUES (", - " '{\"urgent\",\"reviewed\"}',", - " '{{uuid:attachment_id}}',", - " '{\"other\":\"hello\"}',", - " 'attachment',", - " '{\"type\":\"type_metadata\"}'", + " '{\"urgent\",\"reviewed\"}',", + " '{{uuid:attachment_id}}',", + " '{\"other\":\"hello\"}',", + " 'attachment',", + " '{\"type\":\"type_metadata\"}'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"flags\":[\"urgent\",\"reviewed\"],", - " \"other_metadata\":{\"other\":\"hello\"},", - " \"type\":\"attachment\",", - " \"type_metadata\":{\"type\":\"type_metadata\"}", - " }',", - " '{{uuid:attachment_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"flags\":[\"urgent\",\"reviewed\"],", + " \"other_metadata\":{\"other\":\"hello\"},", + " \"type\":\"attachment\",", + " \"type_metadata\":{\"type\":\"type_metadata\"}", + " }',", + " '{{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}}\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"other_metadata\":{\"other\":\"hello\"},", - " \"type\":\"attachment\",", - " \"type_metadata\":{\"type\":\"type_metadata\"}", - " },", - " \"new\":{", - " \"flags\":[\"urgent\",\"reviewed\"],", - " \"other_metadata\":{\"other\":\"hello\"},", - " \"type\":\"attachment\",", - " \"type_metadata\":{\"type\":\"type_metadata\"}", - " }", - " }')" + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"flags\":[\"urgent\",\"reviewed\"],", + " \"id\":\"{{uuid:attachment_id}}\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"other_metadata\":{\"other\":\"hello\"},", + " \"type\":\"attachment\",", + " \"type_metadata\":{\"type\":\"type_metadata\"}", + " },", + " \"new\":{", + " \"flags\":[\"urgent\",\"reviewed\"],", + " \"other_metadata\":{\"other\":\"hello\"},", + " \"type\":\"attachment\",", + " \"type_metadata\":{\"type\":\"type_metadata\"}", + " }", + " }')" ] ] } @@ -2695,83 +2828,83 @@ "sql": [ [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ")", "VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '{{uuid:line_id}}',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'order_line'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:line_id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'order_line'", ")" ], [ "INSERT INTO agreego.\"order_line\" (", - " \"id\",", - " \"order_id\",", - " \"price\",", - " \"product\",", - " \"type\"", + " \"id\",", + " \"order_id\",", + " \"price\",", + " \"product\",", + " \"type\"", ")", "VALUES (", - " '{{uuid:line_id}}',", - " 'abc',", - " 99,", - " 'Widget',", - " 'order_line'", + " '{{uuid:line_id}}',", + " 'abc',", + " 99,", + " 'Widget',", + " 'order_line'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"order_id\":\"abc\",", - " \"price\":99.0,", - " \"product\":\"Widget\",", - " \"type\":\"order_line\"", - " }',", - " '{{uuid:line_id}}',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " }',", + " '{{uuid:line_id}}',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"{{uuid:line_id}}\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"order_id\":\"abc\",", - " \"price\":99.0,", - " \"product\":\"Widget\",", - " \"type\":\"order_line\"", - " },", - " \"new\":{", - " \"order_id\":\"abc\",", - " \"price\":99.0,", - " \"product\":\"Widget\",", - " \"type\":\"order_line\"", - " }", - " }')" + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"{{uuid:line_id}}\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " },", + " \"new\":{", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " }", + " }')" ] ] } @@ -2803,109 +2936,100 @@ ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ")", "VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '11111111-2222-3333-4444-555555555555',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'order_line'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '11111111-2222-3333-4444-555555555555',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'order_line'", ")" ], [ "INSERT INTO agreego.\"order_line\" (", - " \"id\",", - " \"order_id\",", - " \"price\",", - " \"product\",", - " \"type\"", + " \"id\",", + " \"order_id\",", + " \"price\",", + " \"product\",", + " \"type\"", ")", "VALUES (", - " '11111111-2222-3333-4444-555555555555',", - " 'abc',", - " 99,", - " 'Widget',", - " 'order_line'", + " '11111111-2222-3333-4444-555555555555',", + " 'abc',", + " 99,", + " 'Widget',", + " 'order_line'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"order_id\":\"abc\",", - " \"price\":99.0,", - " \"product\":\"Widget\",", - " \"type\":\"order_line\"", - " }',", - " '11111111-2222-3333-4444-555555555555',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " }',", + " '11111111-2222-3333-4444-555555555555',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ], [ "SELECT pg_notify('entity', '{", - " \"complete\":{", - " \"created_at\":\"{{timestamp}}\",", - " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"id\":\"11111111-2222-3333-4444-555555555555\",", - " \"modified_at\":\"{{timestamp}}\",", - " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", - " \"order_id\":\"abc\",", - " \"price\":99.0,", - " \"product\":\"Widget\",", - " \"type\":\"order_line\"", - " },", - " \"new\":{", - " \"order_id\":\"abc\",", - " \"price\":99.0,", - " \"product\":\"Widget\",", - " \"type\":\"order_line\"", - " }", - " }')" + " \"complete\":{", + " \"created_at\":\"{{timestamp}}\",", + " \"created_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"id\":\"11111111-2222-3333-4444-555555555555\",", + " \"modified_at\":\"{{timestamp}}\",", + " \"modified_by\":\"00000000-0000-0000-0000-000000000000\",", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " },", + " \"new\":{", + " \"order_id\":\"abc\",", + " \"price\":99.0,", + " \"product\":\"Widget\",", + " \"type\":\"order_line\"", + " }", + " }')" ] ] } }, { - "description": "Insert invoice with deep jsonb metadata", + "description": "Insert invoice with JSONB metadata", "action": "merge", "schema_id": "invoice", "data": { "id": "11111111-2222-3333-4444-555555555555", "type": "invoice", "number": "INV-1001", - "metadata": { - "internal_note": "Confidential", - "customer_snapshot": { - "id": "00000000-0000-0000-0000-000000000000", - "type": "person", - "first_name": "John" - }, - "related_rules": [ - { - "id": "11111111-1111-1111-1111-111111111111", - "type": "entity" - } - ] - } + "total": 200.0, + "metadata_line": {"price": 50}, + "metadata_lines": [{"price": 25}], + "metadata_nested_line": {"line": {"price": 75}}, + "metadata_nested_lines": {"lines": [{"price": 100}]} }, "expect": { "success": true, @@ -2918,84 +3042,67 @@ ], [ "INSERT INTO agreego.\"entity\" (", - " \"created_at\",", - " \"created_by\",", - " \"id\",", - " \"modified_at\",", - " \"modified_by\",", - " \"type\"", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", ")", "VALUES (", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " '11111111-2222-3333-4444-555555555555',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000',", - " 'invoice'", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '11111111-2222-3333-4444-555555555555',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'invoice'", ")" ], [ "INSERT INTO agreego.\"invoice\" (", - " \"id\",", - " \"metadata\",", - " \"number\",", - " \"type\"", + " \"id\",", + " \"metadata_line\",", + " \"metadata_lines\",", + " \"metadata_nested_line\",", + " \"metadata_nested_lines\",", + " \"total\",", + " \"type\"", ")", "VALUES (", - " '11111111-2222-3333-4444-555555555555',", - " '{", - " \"customer_snapshot\":{", - " \"first_name\":\"John\",", - " \"id\":\"00000000-0000-0000-0000-000000000000\",", - " \"type\":\"person\"", - " },", - " \"internal_note\":\"Confidential\",", - " \"related_rules\":[", - " {", - " \"id\":\"11111111-1111-1111-1111-111111111111\",", - " \"type\":\"entity\"", - " }", - " ]", - " }',", - " 'INV-1001',", - " 'invoice'", + " '11111111-2222-3333-4444-555555555555',", + " '{\"price\":50}',", + " '[{\"price\":25}]',", + " '{\"line\":{\"price\":75}}',", + " '{\"lines\":[{\"price\":100}]}',", + " 200,", + " 'invoice'", ")" ], [ "INSERT INTO agreego.change (", - " \"old\",", - " \"new\",", - " entity_id,", - " id,", - " kind,", - " modified_at,", - " modified_by", + " \"old\",", + " \"new\",", + " entity_id,", + " id,", + " kind,", + " modified_at,", + " modified_by", ")", "VALUES (", - " NULL,", - " '{", - " \"metadata\":{", - " \"customer_snapshot\":{", - " \"first_name\":\"John\",", - " \"id\":\"00000000-0000-0000-0000-000000000000\",", - " \"type\":\"person\"", - " },", - " \"internal_note\":\"Confidential\",", - " \"related_rules\":[", - " {", - " \"id\":\"11111111-1111-1111-1111-111111111111\",", - " \"type\":\"entity\"", - " }", - " ]", - " },", - " \"number\":\"INV-1001\",", - " \"type\":\"invoice\"", - " }',", - " '11111111-2222-3333-4444-555555555555',", - " '{{uuid}}',", - " 'create',", - " '{{timestamp}}',", - " '00000000-0000-0000-0000-000000000000'", + " NULL,", + " '{", + " \"metadata_line\":{\"price\":50},", + " \"metadata_lines\":[{\"price\":25}],", + " \"metadata_nested_line\":{\"line\":{\"price\":75}},", + " \"metadata_nested_lines\":{\"lines\":[{\"price\":100}]},", + " \"total\":200.0,", + " \"type\":\"invoice\"", + " }',", + " '11111111-2222-3333-4444-555555555555',", + " '{{uuid}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", ")" ] ] diff --git a/fixtures/queryer.json b/fixtures/queryer.json index ce36294..338eaf1 100644 --- a/fixtures/queryer.json +++ b/fixtures/queryer.json @@ -1,2064 +1,2155 @@ [ - { - "description": "Queryer Execution", - "database": { - "puncs": [ - { - "name": "get_organization", - "schemas": { - "get_organization.response": { - "type": "organization" - } - } - }, - { - "name": "get_organizations", - "schemas": { - "get_organizations.response": { - "type": "array", - "items": { - "$family": "organization" - } - } - } - }, - { - "name": "get_light_organization", - "schemas": { - "get_light_organization.response": { - "$family": "light.organization" - } - } - }, - { - "name": "get_full_organization", - "schemas": { - "get_full_organization.response": { - "$family": "full.organization" - } - } - }, - { - "name": "get_orders", - "schemas": { - "get_orders.response": { - "type": "array", - "items": { - "type": "light.order" - } - } - } - }, - { - "name": "get_widgets", - "schemas": { - "get_widgets.response": { - "type": "array", - "items": { - "$family": "widget" - } - } - } - } - ], - "enums": [], - "relations": [ - { - "type": "relation", - "id": "00000000-0000-0000-0000-000000000001", - "constraint": "fk_relationship_source_entity", - "source_type": "relationship", - "source_columns": [ - "source_id", - "source_type" - ], - "destination_type": "entity", - "destination_columns": [ - "id", - "type" - ], - "prefix": "source" - }, - { - "type": "relation", - "id": "00000000-0000-0000-0000-000000000002", - "constraint": "fk_relationship_target_entity", - "source_type": "relationship", - "source_columns": [ - "target_id", - "target_type" - ], - "destination_type": "entity", - "destination_columns": [ - "id", - "type" - ], - "prefix": "target" - }, - { - "id": "22222222-2222-2222-2222-222222222222", - "type": "relation", - "constraint": "fk_order_customer_person", - "source_type": "order", - "source_columns": [ - "customer_id" - ], - "destination_type": "person", - "destination_columns": [ - "id" - ], - "prefix": "customer" - }, - { - "id": "22222222-2222-2222-2222-222222222227", - "type": "relation", - "constraint": "fk_order_counterparty_entity", - "source_type": "order", - "source_columns": [ - "counterparty_id", - "counterparty_type" - ], - "destination_type": "entity", - "destination_columns": [ - "id", - "type" - ], - "prefix": "counterparty" - }, - { - "id": "33333333-3333-3333-3333-333333333333", - "type": "relation", - "constraint": "fk_order_line_order", - "source_type": "order_line", - "source_columns": [ - "order_id" - ], - "destination_type": "order", - "destination_columns": [ - "id" - ] - } - ], - "types": [ - { - "name": "entity", - "hierarchy": [ - "entity" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ] - }, - "field_types": { - "id": "uuid", - "archived": "boolean", - "created_at": "timestamptz", - "type": "text" - }, - "schemas": { - "entity": { - "type": "object", - "properties": { - "id": { - "type": "string", - "format": "uuid" - }, - "type": { - "type": "string" - }, - "archived": { - "type": "boolean" - }, - "created_at": { - "type": "string", - "format": "date-time" - }, - "created": { - "type": "boolean" - } - } - } - }, - "fields": [ - "id", - "type", - "archived", - "created_at" - ], - "variations": [ - "address", - "bot", - "contact", - "email_address", - "entity", - "order", - "order_line", - "organization", - "person", - "phone_number", - "relationship" - ] - }, - { - "name": "organization", - "hierarchy": [ - "organization", - "entity" - ], - "fields": [ - "id", - "type", - "name", - "archived", - "created_at" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ], - "organization": [ - "name" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "name": "text", - "created_at": "timestamptz" - }, - "lookup_fields": [ - "id" - ], - "null_fields": [], - "default_fields": [ - "id", - "type", - "created_at", - "archived" - ], - "variations": [ - "bot", - "organization", - "person" - ], - "schemas": { - "organization": { - "type": "entity", - "properties": { - "name": { - "type": "string" - } - } - } - } - }, - { - "name": "bot", - "hierarchy": [ - "bot", - "organization", - "entity" - ], - "fields": [ - "token", - "id", - "type", - "name", - "archived", - "created_at", - "token", - "role" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ], - "organization": [ - "name" - ], - "bot": [ - "token", - "role" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "name": "text", - "token": "text", - "role": "text", - "created_at": "timestamptz" - }, - "schemas": { - "bot": { - "type": "organization", - "properties": { - "token": { - "type": "string" - }, - "role": { - "type": "string" - } - } - }, - "light.bot": { - "type": "organization", - "properties": { - "token": { - "type": "string" - } - } - } - }, - "variations": [ - "bot" - ] - }, - { - "name": "person", - "hierarchy": [ - "person", - "organization", - "entity" - ], - "fields": [ - "first_name", - "last_name", - "id", - "type", - "name", - "age", - "archived", - "created_at" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ], - "organization": [ - "name" - ], - "person": [ - "first_name", - "last_name", - "age" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "first_name": "text", - "last_name": "text", - "name": "text", - "age": "numeric", - "created_at": "timestamptz" - }, - "schemas": { - "person": { - "type": "organization", - "properties": { - "first_name": { - "type": "string" - }, - "last_name": { - "type": "string" - }, - "age": { - "type": "number" - } - } - }, - "light.person": { - "type": "organization", - "properties": { - "first_name": { - "type": "string" - }, - "last_name": { - "type": "string" - } - } - }, - "full.person": { - "type": "person", - "properties": { - "phone_numbers": { - "type": "array", - "items": { - "type": "contact", - "properties": { - "target": { - "type": "phone_number" - } - } - } - }, - "email_addresses": { - "type": "array", - "items": { - "type": "contact", - "properties": { - "target": { - "type": "email_address" - } - } - } - }, - "addresses": { - "type": "array", - "items": { - "type": "contact", - "properties": { - "target": { - "type": "address" - } - } - } - }, - "contacts": { - "type": "array", - "items": { - "type": "contact", - "properties": { - "target": { - "oneOf": [ - { - "type": "phone_number" - }, - { - "type": "email_address" - }, - { - "type": "address" - } - ] - } - } - } - } - } - } - }, - "variations": [ - "person" - ] - }, - { - "name": "relationship", - "relationship": true, - "hierarchy": [ - "relationship", - "entity" - ], - "fields": [ - "source_id", - "source_type", - "target_id", - "target_type", - "id", - "type", - "archived", - "created_at" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ], - "relationship": [ - "source_id", - "source_type", - "target_id", - "target_type" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "source_id": "uuid", - "source_type": "text", - "target_id": "uuid", - "target_type": "text", - "created_at": "timestamptz" - }, - "schemas": { - "relationship": { - "type": "entity", - "properties": {} - } - }, - "variations": [ - "contact", - "relationship" - ] - }, - { - "name": "contact", - "relationship": true, - "hierarchy": [ - "contact", - "relationship", - "entity" - ], - "fields": [ - "is_primary", - "source_id", - "source_type", - "target_id", - "target_type", - "id", - "type", - "archived", - "created_at" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ], - "relationship": [ - "source_id", - "source_type", - "target_id", - "target_type" - ], - "contact": [ - "is_primary" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "source_id": "uuid", - "source_type": "text", - "target_id": "uuid", - "target_type": "text", - "is_primary": "boolean", - "created_at": "timestamptz" - }, - "schemas": { - "contact": { - "type": "relationship", - "properties": { - "is_primary": { - "type": "boolean" - } - } - } - }, - "variations": [ - "contact" - ] - }, - { - "name": "phone_number", - "hierarchy": [ - "phone_number", - "entity" - ], - "fields": [ - "number", - "id", - "type", - "archived", - "created_at" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ], - "phone_number": [ - "number" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "number": "text", - "created_at": "timestamptz" - }, - "schemas": { - "phone_number": { - "type": "entity", - "properties": { - "number": { - "type": "string" - } - } - } - }, - "variations": [ - "phone_number" - ] - }, - { - "name": "email_address", - "hierarchy": [ - "email_address", - "entity" - ], - "fields": [ - "address", - "id", - "type", - "archived", - "created_at" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ], - "email_address": [ - "address" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "address": "text", - "created_at": "timestamptz" - }, - "schemas": { - "email_address": { - "type": "entity", - "properties": { - "address": { - "type": "string" - } - } - } - }, - "variations": [ - "email_address" - ] - }, - { - "name": "address", - "hierarchy": [ - "address", - "entity" - ], - "fields": [ - "city", - "id", - "type", - "archived", - "created_at" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ], - "address": [ - "city" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "city": "text", - "created_at": "timestamptz" - }, - "schemas": { - "address": { - "type": "entity", - "properties": { - "city": { - "type": "string" - } - } - } - }, - "variations": [ - "address" - ] - }, - { - "name": "order", - "schemas": { - "order": { - "type": "entity", - "properties": { - "total": { - "type": "number" - }, - "customer_id": { - "type": "string" - } - } - }, - "light.order": { - "type": "order", - "properties": { - "customer": { - "type": "person" - } - } - }, - "full.order": { - "type": "order", - "properties": { - "customer": { - "type": "person" - }, - "lines": { - "type": "array", - "items": { - "type": "order_line" - } - } - } - } - }, - "hierarchy": [ - "order", - "entity" - ], - "fields": [ - "id", - "type", - "total", - "customer_id", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived", - "counterparty_id", - "counterparty_type" - ], - "grouped_fields": { - "order": [ - "id", - "type", - "total", - "customer_id", - "counterparty_id", - "counterparty_type" - ], - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [ - "id" - ], - "historical": true, - "relationship": false, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "total": "numeric", - "customer_id": "uuid", - "created_at": "timestamptz", - "created_by": "uuid", - "modified_at": "timestamptz", - "modified_by": "uuid", - "counterparty_id": "uuid", - "counterparty_type": "text" - }, - "variations": [ - "order" - ] - }, - { - "name": "order_line", - "schemas": { - "order_line": { - "type": "entity", - "properties": { - "order_id": { - "type": "string" - }, - "product": { - "type": "string" - }, - "price": { - "type": "number" - } - } - } - }, - "hierarchy": [ - "order_line", - "entity" - ], - "fields": [ - "id", - "type", - "order_id", - "product", - "price", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ], - "grouped_fields": { - "order_line": [ - "id", - "type", - "order_id", - "product", - "price" - ], - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [], - "historical": true, - "relationship": false, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "order_id": "uuid", - "product": "text", - "price": "numeric", - "created_at": "timestamptz", - "created_by": "uuid", - "modified_at": "timestamptz", - "modified_by": "uuid" - }, - "variations": [ - "order_line" - ] - }, - { - "name": "widget", - "hierarchy": [ - "widget", - "entity" - ], - "fields": [ - "id", - "type", - "kind", - "archived", - "created_at" - ], - "grouped_fields": { - "entity": [ - "id", - "type", - "archived", - "created_at" - ], - "widget": [ - "kind" - ] - }, - "field_types": { - "id": "uuid", - "type": "text", - "kind": "text", - "archived": "boolean", - "created_at": "timestamptz" - }, - "variations": [ - "widget" - ], - "schemas": { - "widget": { - "type": "entity", - "properties": { - "kind": { - "type": "string" - } - } - }, - "stock.widget": { - "type": "widget", - "properties": {} - }, - "tasks.widget": { - "type": "widget", - "properties": {} - } - } - }, - { - "name": "invoice", - "hierarchy": [ - "invoice", - "entity" - ], - "fields": [ - "id", - "type", - "number", - "metadata", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ], - "grouped_fields": { - "invoice": [ - "id", - "type", - "number", - "metadata" - ], - "entity": [ - "id", - "type", - "created_at", - "created_by", - "modified_at", - "modified_by", - "archived" - ] - }, - "lookup_fields": [ - "id" - ], - "historical": true, - "relationship": false, - "field_types": { - "id": "uuid", - "type": "text", - "archived": "boolean", - "number": "text", - "metadata": "jsonb", - "created_at": "timestamptz", - "created_by": "uuid", - "modified_at": "timestamptz", - "modified_by": "uuid" - }, - "variations": [ - "invoice" - ], - "schemas": { - "invoice": { - "type": "entity", - "properties": { - "id": { - "type": "string" - }, - "number": { - "type": "string" - }, - "metadata": { - "type": "object", - "properties": { - "internal_note": { - "type": "string" - }, - "customer_snapshot": { - "type": "entity" - }, - "related_rules": { - "type": "array", - "items": { - "type": "entity" - } - } - } - } - } - } - } - } - ] - }, - "tests": [ - { - "description": "Simple entity select", - "action": "query", - "schema_id": "entity", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", - " 'archived', entity_1.archived,", - " 'created_at', entity_1.created_at,", - " 'id', entity_1.id,", - " 'type', entity_1.type)", - "FROM agreego.entity entity_1", - "WHERE NOT entity_1.archived)))" - ] - ] - } - }, - { - "description": "Simple entity select with multiple filters", - "action": "query", - "schema_id": "entity", - "filters": { - "id": { - "$eq": "123e4567-e89b-12d3-a456-426614174000", - "$ne": "123e4567-e89b-12d3-a456-426614174001", - "$in": [ - "123e4567-e89b-12d3-a456-426614174000" - ], - "$nin": [ - "123e4567-e89b-12d3-a456-426614174001" - ] - }, - "created_at": { - "$eq": "2023-01-01T00:00:00Z", - "$ne": "2023-01-02T00:00:00Z", - "$gt": "2022-01-01T00:00:00Z", - "$gte": "2022-01-02T00:00:00Z", - "$lt": "2024-01-01T00:00:00Z", - "$lte": "2024-01-02T00:00:00Z" - }, - "archived": { - "$eq": false, - "$ne": true - } - }, - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", - " 'archived', entity_1.archived,", - " 'created_at', entity_1.created_at,", - " 'id', entity_1.id,", - " 'type', entity_1.type", - ")", - "FROM agreego.entity entity_1", - "WHERE", - " NOT entity_1.archived", - " AND entity_1.archived = ($1#>>'{}')::boolean", - " AND entity_1.archived != ($2#>>'{}')::boolean", - " AND entity_1.created_at = ($3#>>'{}')::timestamptz", - " AND entity_1.created_at > ($4#>>'{}')::timestamptz", - " AND entity_1.created_at >= ($5#>>'{}')::timestamptz", - " AND entity_1.created_at < ($6#>>'{}')::timestamptz", - " AND entity_1.created_at <= ($7#>>'{}')::timestamptz", - " AND entity_1.created_at != ($8#>>'{}')::timestamptz", - " AND entity_1.id = ($9#>>'{}')::uuid", - " AND entity_1.id IN (SELECT value::uuid FROM jsonb_array_elements_text(($10#>>'{}')::jsonb))", - " AND entity_1.id != ($11#>>'{}')::uuid", - " AND entity_1.id NOT IN (SELECT value::uuid FROM jsonb_array_elements_text(($12#>>'{}')::jsonb))", - ")))" - ] - ] - } - }, - { - "description": "Person select on base schema", - "action": "query", - "schema_id": "person", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", - " 'age', person_1.age,", - " 'archived', entity_3.archived,", - " 'created_at', entity_3.created_at,", - " 'first_name', person_1.first_name,", - " 'id', entity_3.id,", - " 'last_name', person_1.last_name,", - " 'name', organization_2.name,", - " 'type', entity_3.type)", - "FROM agreego.person person_1", - "JOIN agreego.organization organization_2 ON organization_2.id = person_1.id", - "JOIN agreego.entity entity_3 ON entity_3.id = organization_2.id", - "WHERE NOT entity_3.archived)))" - ] - ] - } - }, - { - "description": "Person select on full schema", - "action": "query", - "schema_id": "full.person", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", - " 'addresses',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_6.archived,", - " 'created_at', entity_6.created_at,", - " 'id', entity_6.id,", - " 'is_primary', contact_4.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'archived', entity_8.archived,", - " 'city', address_7.city,", - " 'created_at', entity_8.created_at,", - " 'id', entity_8.id,", - " 'type', entity_8.type", - " )", - " FROM agreego.address address_7", - " JOIN agreego.entity entity_8 ON entity_8.id = address_7.id", - " WHERE", - " NOT entity_8.archived", - " AND relationship_5.target_id = entity_8.id),", - " 'type', entity_6.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_4", - " JOIN agreego.relationship relationship_5 ON relationship_5.id = contact_4.id", - " JOIN agreego.entity entity_6 ON entity_6.id = relationship_5.id", - " WHERE", - " NOT entity_6.archived", - " AND relationship_5.target_type = 'address'", - " AND relationship_5.source_id = entity_3.id),", - " 'age', person_1.age,", - " 'archived', entity_3.archived,", - " 'contacts',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_11.archived,", - " 'created_at', entity_11.created_at,", - " 'id', entity_11.id,", - " 'is_primary', contact_9.is_primary,", - " 'target', CASE", - " WHEN entity_11.target_type = 'address' THEN", - " ((SELECT jsonb_build_object(", - " 'archived', entity_13.archived,", - " 'city', address_12.city,", - " 'created_at', entity_13.created_at,", - " 'id', entity_13.id,", - " 'type', entity_13.type", - " )", - " FROM agreego.address address_12", - " JOIN agreego.entity entity_13 ON entity_13.id = address_12.id", - " WHERE", - " NOT entity_13.archived", - " AND relationship_10.target_id = entity_13.id))", - " WHEN entity_11.target_type = 'email_address' THEN", - " ((SELECT jsonb_build_object(", - " 'address', email_address_14.address,", - " 'archived', entity_15.archived,", - " 'created_at', entity_15.created_at,", - " 'id', entity_15.id,", - " 'type', entity_15.type", - " )", - " FROM agreego.email_address email_address_14", - " JOIN agreego.entity entity_15 ON entity_15.id = email_address_14.id", - " WHERE", - " NOT entity_15.archived", - " AND relationship_10.target_id = entity_15.id))", - " WHEN entity_11.target_type = 'phone_number' THEN", - " ((SELECT jsonb_build_object(", - " 'archived', entity_17.archived,", - " 'created_at', entity_17.created_at,", - " 'id', entity_17.id,", - " 'number', phone_number_16.number,", - " 'type', entity_17.type", - " )", - " FROM agreego.phone_number phone_number_16", - " JOIN agreego.entity entity_17 ON entity_17.id = phone_number_16.id", - " WHERE", - " NOT entity_17.archived", - " AND relationship_10.target_id = entity_17.id))", - " ELSE NULL END,", - " 'type', entity_11.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_9", - " JOIN agreego.relationship relationship_10 ON relationship_10.id = contact_9.id", - " JOIN agreego.entity entity_11 ON entity_11.id = relationship_10.id", - " WHERE", - " NOT entity_11.archived", - " AND relationship_10.source_id = entity_3.id),", - " 'created_at', entity_3.created_at,", - " 'email_addresses',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_20.archived,", - " 'created_at', entity_20.created_at,", - " 'id', entity_20.id,", - " 'is_primary', contact_18.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'address', email_address_21.address,", - " 'archived', entity_22.archived,", - " 'created_at', entity_22.created_at,", - " 'id', entity_22.id,", - " 'type', entity_22.type", - " )", - " FROM agreego.email_address email_address_21", - " JOIN agreego.entity entity_22 ON entity_22.id = email_address_21.id", - " WHERE", - " NOT entity_22.archived", - " AND relationship_19.target_id = entity_22.id),", - " 'type', entity_20.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_18", - " JOIN agreego.relationship relationship_19 ON relationship_19.id = contact_18.id", - " JOIN agreego.entity entity_20 ON entity_20.id = relationship_19.id", - " WHERE", - " NOT entity_20.archived", - " AND relationship_19.target_type = 'email_address'", - " AND relationship_19.source_id = entity_3.id),", - " 'first_name', person_1.first_name,", - " 'id', entity_3.id,", - " 'last_name', person_1.last_name,", - " 'name', organization_2.name,", - " 'phone_numbers',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_25.archived,", - " 'created_at', entity_25.created_at,", - " 'id', entity_25.id,", - " 'is_primary', contact_23.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'archived', entity_27.archived,", - " 'created_at', entity_27.created_at,", - " 'id', entity_27.id,", - " 'number', phone_number_26.number,", - " 'type', entity_27.type", - " )", - " FROM agreego.phone_number phone_number_26", - " JOIN agreego.entity entity_27 ON entity_27.id = phone_number_26.id", - " WHERE", - " NOT entity_27.archived", - " AND relationship_24.target_id = entity_27.id),", - " 'type', entity_25.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_23", - " JOIN agreego.relationship relationship_24 ON relationship_24.id = contact_23.id", - " JOIN agreego.entity entity_25 ON entity_25.id = relationship_24.id", - " WHERE", - " NOT entity_25.archived", - " AND relationship_24.target_type = 'phone_number'", - " AND relationship_24.source_id = entity_3.id),", - " 'type', entity_3.type", - ")", - "FROM agreego.person person_1", - "JOIN agreego.organization organization_2 ON organization_2.id = person_1.id", - "JOIN agreego.entity entity_3 ON entity_3.id = organization_2.id", - "WHERE NOT entity_3.archived)))" - ] - ] - } - }, - { - "description": "Person select on full schema with filters", - "action": "query", - "schema_id": "full.person", - "filters": { - "age": { - "$eq": 30, - "$gt": 20, - "$gte": 20, - "$in": [ - 30, - 40 - ], - "$lt": 50, - "$lte": 50, - "$ne": 25, - "$nin": [ - 1, - 2 - ] - }, - "archived": { - "$eq": true, - "$ne": false - }, - "contacts": { - "is_primary": { - "$eq": true - } - }, - "created_at": { - "$eq": "2020-01-01T00:00:00Z", - "$gt": "2019-01-01T00:00:00Z", - "$gte": "2019-01-01T00:00:00Z", - "$lt": "2021-01-01T00:00:00Z", - "$lte": "2021-01-01T00:00:00Z", - "$ne": "2022-01-01T00:00:00Z" - }, - "first_name": { - "$eq": "Jane%", - "$gt": "A", - "$gte": "A", - "$in": [ - "Jane", - "John" - ], - "$lt": "Z", - "$lte": "Z", - "$ne": "Doe", - "$nin": [ - "Bob" - ] - }, - "id": { - "$eq": "00000000-0000-0000-0000-000000000001", - "$in": [ - "00000000-0000-0000-0000-000000000001" - ], - "$ne": "00000000-0000-0000-0000-000000000002", - "$nin": [ - "00000000-0000-0000-0000-000000000002" - ] - }, - "last_name": { - "$eq": "%Doe%", - "$ne": "%Smith%" - }, - "phone_numbers": { - "target": { - "number": { - "$eq": "555-1234" - } - } - } - }, - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", - " 'addresses',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_6.archived,", - " 'created_at', entity_6.created_at,", - " 'id', entity_6.id,", - " 'is_primary', contact_4.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'archived', entity_8.archived,", - " 'city', address_7.city,", - " 'created_at', entity_8.created_at,", - " 'id', entity_8.id,", - " 'type', entity_8.type", - " )", - " FROM agreego.address address_7", - " JOIN agreego.entity entity_8 ON entity_8.id = address_7.id", - " WHERE", - " NOT entity_8.archived", - " AND relationship_5.target_id = entity_8.id),", - " 'type', entity_6.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_4", - " JOIN agreego.relationship relationship_5 ON relationship_5.id = contact_4.id", - " JOIN agreego.entity entity_6 ON entity_6.id = relationship_5.id", - " WHERE", - " NOT entity_6.archived", - " AND relationship_5.target_type = 'address'", - " AND relationship_5.source_id = entity_3.id),", - " 'age', person_1.age,", - " 'archived', entity_3.archived,", - " 'contacts',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_11.archived,", - " 'created_at', entity_11.created_at,", - " 'id', entity_11.id,", - " 'is_primary', contact_9.is_primary,", - " 'target', CASE", - " WHEN entity_11.target_type = 'address' THEN", - " ((SELECT jsonb_build_object(", - " 'archived', entity_13.archived,", - " 'city', address_12.city,", - " 'created_at', entity_13.created_at,", - " 'id', entity_13.id,", - " 'type', entity_13.type", - " )", - " FROM agreego.address address_12", - " JOIN agreego.entity entity_13 ON entity_13.id = address_12.id", - " WHERE", - " NOT entity_13.archived", - " AND relationship_10.target_id = entity_13.id))", - " WHEN entity_11.target_type = 'email_address' THEN", - " ((SELECT jsonb_build_object(", - " 'address', email_address_14.address,", - " 'archived', entity_15.archived,", - " 'created_at', entity_15.created_at,", - " 'id', entity_15.id,", - " 'type', entity_15.type", - " )", - " FROM agreego.email_address email_address_14", - " JOIN agreego.entity entity_15 ON entity_15.id = email_address_14.id", - " WHERE", - " NOT entity_15.archived", - " AND relationship_10.target_id = entity_15.id))", - " WHEN entity_11.target_type = 'phone_number' THEN", - " ((SELECT jsonb_build_object(", - " 'archived', entity_17.archived,", - " 'created_at', entity_17.created_at,", - " 'id', entity_17.id,", - " 'number', phone_number_16.number,", - " 'type', entity_17.type", - " )", - " FROM agreego.phone_number phone_number_16", - " JOIN agreego.entity entity_17 ON entity_17.id = phone_number_16.id", - " WHERE", - " NOT entity_17.archived", - " AND relationship_10.target_id = entity_17.id))", - " ELSE NULL END,", - " 'type', entity_11.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_9", - " JOIN agreego.relationship relationship_10 ON relationship_10.id = contact_9.id", - " JOIN agreego.entity entity_11 ON entity_11.id = relationship_10.id", - " WHERE", - " NOT entity_11.archived", - " AND contact_9.is_primary = ($11#>>'{}')::boolean", - " AND relationship_10.source_id = entity_3.id),", - " 'created_at', entity_3.created_at,", - " 'email_addresses',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_20.archived,", - " 'created_at', entity_20.created_at,", - " 'id', entity_20.id,", - " 'is_primary', contact_18.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'address', email_address_21.address,", - " 'archived', entity_22.archived,", - " 'created_at', entity_22.created_at,", - " 'id', entity_22.id,", - " 'type', entity_22.type", - " )", - " FROM agreego.email_address email_address_21", - " JOIN agreego.entity entity_22 ON entity_22.id = email_address_21.id", - " WHERE", - " NOT entity_22.archived", - " AND relationship_19.target_id = entity_22.id),", - " 'type', entity_20.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_18", - " JOIN agreego.relationship relationship_19 ON relationship_19.id = contact_18.id", - " JOIN agreego.entity entity_20 ON entity_20.id = relationship_19.id", - " WHERE", - " NOT entity_20.archived", - " AND relationship_19.target_type = 'email_address'", - " AND relationship_19.source_id = entity_3.id),", - " 'first_name', person_1.first_name,", - " 'id', entity_3.id,", - " 'last_name', person_1.last_name,", - " 'name', organization_2.name,", - " 'phone_numbers',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_25.archived,", - " 'created_at', entity_25.created_at,", - " 'id', entity_25.id,", - " 'is_primary', contact_23.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'archived', entity_27.archived,", - " 'created_at', entity_27.created_at,", - " 'id', entity_27.id,", - " 'number', phone_number_26.number,", - " 'type', entity_27.type", - " )", - " FROM agreego.phone_number phone_number_26", - " JOIN agreego.entity entity_27 ON entity_27.id = phone_number_26.id", - " WHERE", - " NOT entity_27.archived", - " AND phone_number_26.number ILIKE $32#>>'{}'", - " AND relationship_24.target_id = entity_27.id),", - " 'type', entity_25.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_23", - " JOIN agreego.relationship relationship_24 ON relationship_24.id = contact_23.id", - " JOIN agreego.entity entity_25 ON entity_25.id = relationship_24.id", - " WHERE", - " NOT entity_25.archived", - " AND relationship_24.target_type = 'phone_number'", - " AND relationship_24.source_id = entity_3.id),", - " 'type', entity_3.type", - ")", - "FROM agreego.person person_1", - "JOIN agreego.organization organization_2 ON organization_2.id = person_1.id", - "JOIN agreego.entity entity_3 ON entity_3.id = organization_2.id", - "WHERE", - " NOT entity_3.archived", - " AND person_1.age = ($1#>>'{}')::numeric", - " AND person_1.age > ($2#>>'{}')::numeric", - " AND person_1.age >= ($3#>>'{}')::numeric", - " AND person_1.age IN (SELECT value::numeric FROM jsonb_array_elements_text(($4#>>'{}')::jsonb))", - " AND person_1.age < ($5#>>'{}')::numeric", - " AND person_1.age <= ($6#>>'{}')::numeric", - " AND person_1.age != ($7#>>'{}')::numeric", - " AND person_1.age NOT IN (SELECT value::numeric FROM jsonb_array_elements_text(($8#>>'{}')::jsonb))", - " AND entity_3.archived = ($9#>>'{}')::boolean", - " AND entity_3.archived != ($10#>>'{}')::boolean", - " AND entity_3.created_at = ($12#>>'{}')::timestamptz", - " AND entity_3.created_at > ($13#>>'{}')::timestamptz", - " AND entity_3.created_at >= ($14#>>'{}')::timestamptz", - " AND entity_3.created_at < ($15#>>'{}')::timestamptz", - " AND entity_3.created_at <= ($16#>>'{}')::timestamptz", - " AND entity_3.created_at != ($17#>>'{}')::timestamptz", - " AND person_1.first_name ILIKE $18#>>'{}'", - " AND person_1.first_name > ($19#>>'{}')", - " AND person_1.first_name >= ($20#>>'{}')", - " AND person_1.first_name IN (SELECT value FROM jsonb_array_elements_text(($21#>>'{}')::jsonb))", - " AND person_1.first_name < ($22#>>'{}')", - " AND person_1.first_name <= ($23#>>'{}')", - " AND person_1.first_name NOT ILIKE $24#>>'{}'", - " AND person_1.first_name NOT IN (SELECT value FROM jsonb_array_elements_text(($25#>>'{}')::jsonb))", - " AND entity_3.id = ($26#>>'{}')::uuid", - " AND entity_3.id IN (SELECT value::uuid FROM jsonb_array_elements_text(($27#>>'{}')::jsonb))", - " AND entity_3.id != ($28#>>'{}')::uuid", - " AND entity_3.id NOT IN (SELECT value::uuid FROM jsonb_array_elements_text(($29#>>'{}')::jsonb))", - " AND person_1.last_name ILIKE $30#>>'{}'", - " AND person_1.last_name NOT ILIKE $31#>>'{}')))" - ] - ] - } - }, - { - "description": "Person ad-hoc email addresses select", - "action": "query", - "schema_id": "full.person/email_addresses", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_3.archived,", - " 'created_at', entity_3.created_at,", - " 'id', entity_3.id,", - " 'is_primary', contact_1.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'address', email_address_4.address,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", - " 'id', entity_5.id,", - " 'type', entity_5.type", - " )", - " FROM agreego.email_address email_address_4", - " JOIN agreego.entity entity_5 ON entity_5.id = email_address_4.id", - " WHERE", - " NOT entity_5.archived", - " AND relationship_2.target_id = entity_5.id),", - " 'type', entity_3.type", - ")), '[]'::jsonb)", - "FROM agreego.contact contact_1", - "JOIN agreego.relationship relationship_2 ON relationship_2.id = contact_1.id", - "JOIN agreego.entity entity_3 ON entity_3.id = relationship_2.id", - "WHERE", - " NOT entity_3.archived", - " AND relationship_2.target_type = 'email_address')))" - ] - ] - } - }, - { - "description": "Order select with customer and lines", - "action": "query", - "schema_id": "full.order", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'customer',", - " (SELECT jsonb_build_object(", - " 'age', person_3.age,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", - " 'first_name', person_3.first_name,", - " 'id', entity_5.id,", - " 'last_name', person_3.last_name,", - " 'name', organization_4.name,", - " 'type', entity_5.type", - " )", - " FROM agreego.person person_3", - " JOIN agreego.organization organization_4 ON organization_4.id = person_3.id", - " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", - " WHERE", - " NOT entity_5.archived", - " AND order_1.customer_id = person_3.id),", - " 'customer_id', order_1.customer_id,", - " 'id', entity_2.id,", - " 'lines',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_7.archived,", - " 'created_at', entity_7.created_at,", - " 'id', entity_7.id,", - " 'order_id', order_line_6.order_id,", - " 'price', order_line_6.price,", - " 'product', order_line_6.product,", - " 'type', entity_7.type", - " )), '[]'::jsonb)", - " FROM agreego.order_line order_line_6", - " JOIN agreego.entity entity_7 ON entity_7.id = order_line_6.id", - " WHERE", - " NOT entity_7.archived", - " AND order_line_6.order_id = order_1.id),", - " 'total', order_1.total,", - " 'type', entity_2.type", - ")", - "FROM agreego.order order_1", - "JOIN agreego.entity entity_2 ON entity_2.id = order_1.id", - "WHERE NOT entity_2.archived)))" - ] - ] - } - }, - { - "description": "Organization select via a punc response with ref", - "action": "query", - "schema_id": "get_organization.response", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'id', entity_2.id,", - " 'name', organization_1.name,", - " 'type', entity_2.type", - ")", - "FROM agreego.organization organization_1", - "JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", - "WHERE NOT entity_2.archived)))" - ] - ] - } - }, - { - "description": "Organizations select via a punc response with family", - "action": "query", - "schema_id": "get_organizations.response", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT COALESCE(jsonb_agg(", - " CASE", - " WHEN organization_1.type = 'bot' THEN (", - " (SELECT jsonb_build_object(", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", - " 'id', entity_5.id,", - " 'name', organization_4.name,", - " 'role', bot_3.role,", - " 'token', bot_3.token,", - " 'type', entity_5.type", - " )", - " FROM agreego.bot bot_3", - " JOIN agreego.organization organization_4 ON organization_4.id = bot_3.id", - " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", - " WHERE", - " NOT entity_5.archived", - " AND entity_5.id = entity_2.id)", - " )", - " WHEN organization_1.type = 'organization' THEN (", - " (SELECT jsonb_build_object(", - " 'archived', entity_7.archived,", - " 'created_at', entity_7.created_at,", - " 'id', entity_7.id,", - " 'name', organization_6.name,", - " 'type', entity_7.type", - " )", - " FROM agreego.organization organization_6", - " JOIN agreego.entity entity_7 ON entity_7.id = organization_6.id", - " WHERE", - " NOT entity_7.archived", - " AND entity_7.id = entity_2.id)", - " )", - " WHEN organization_1.type = 'person' THEN (", - " (SELECT jsonb_build_object(", - " 'age', person_8.age,", - " 'archived', entity_10.archived,", - " 'created_at', entity_10.created_at,", - " 'first_name', person_8.first_name,", - " 'id', entity_10.id,", - " 'last_name', person_8.last_name,", - " 'name', organization_9.name,", - " 'type', entity_10.type", - " )", - " FROM agreego.person person_8", - " JOIN agreego.organization organization_9 ON organization_9.id = person_8.id", - " JOIN agreego.entity entity_10 ON entity_10.id = organization_9.id", - " WHERE", - " NOT entity_10.archived", - " AND entity_10.id = entity_2.id)", - " )", - " ELSE NULL", - " END", - "), '[]'::jsonb)", - "FROM agreego.organization organization_1", - "JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", - "WHERE NOT entity_2.archived)))" - ] - ] - } - }, - { - "description": "Light organizations select via a punc response with family", - "action": "query", - "schema_id": "get_light_organization.response", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT ", - " CASE", - " WHEN organization_1.type = 'bot' THEN (", - " (SELECT jsonb_build_object(", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", - " 'id', entity_5.id,", - " 'name', organization_4.name,", - " 'token', bot_3.token,", - " 'type', entity_5.type", - " )", - " FROM agreego.bot bot_3", - " JOIN agreego.organization organization_4 ON organization_4.id = bot_3.id", - " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", - " WHERE NOT entity_5.archived AND entity_5.id = entity_2.id)", - " )", - " WHEN organization_1.type = 'person' THEN (", - " (SELECT jsonb_build_object(", - " 'archived', entity_8.archived,", - " 'created_at', entity_8.created_at,", - " 'first_name', person_6.first_name,", - " 'id', entity_8.id,", - " 'last_name', person_6.last_name,", - " 'name', organization_7.name,", - " 'type', entity_8.type", - " )", - " FROM agreego.person person_6", - " JOIN agreego.organization organization_7 ON organization_7.id = person_6.id", - " JOIN agreego.entity entity_8 ON entity_8.id = organization_7.id", - " WHERE NOT entity_8.archived AND entity_8.id = entity_2.id)", - " )", - " ELSE NULL", - " END", - "FROM agreego.organization organization_1", - "JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", - "WHERE NOT entity_2.archived)))" - ] - ] - } - }, - { - "description": "Full organizations select via a punc response with family", - "action": "query", - "schema_id": "get_full_organization.response", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT CASE", - " WHEN organization_1.type = 'person' THEN (", - " (SELECT jsonb_build_object(", - " 'addresses',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_8.archived,", - " 'created_at', entity_8.created_at,", - " 'id', entity_8.id,", - " 'is_primary', contact_6.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'archived', entity_10.archived,", - " 'city', address_9.city,", - " 'created_at', entity_10.created_at,", - " 'id', entity_10.id,", - " 'type', entity_10.type", - " )", - " FROM agreego.address address_9", - " JOIN agreego.entity entity_10 ON entity_10.id = address_9.id", - " WHERE", - " NOT entity_10.archived", - " AND relationship_7.target_id = entity_10.id),", - " 'type', entity_8.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_6", - " JOIN agreego.relationship relationship_7 ON relationship_7.id = contact_6.id", - " JOIN agreego.entity entity_8 ON entity_8.id = relationship_7.id", - " WHERE", - " NOT entity_8.archived", - " AND relationship_7.target_type = 'address'", - " AND relationship_7.source_id = entity_5.id),", - " 'age', person_3.age,", - " 'archived', entity_5.archived,", - " 'contacts',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_13.archived,", - " 'created_at', entity_13.created_at,", - " 'id', entity_13.id,", - " 'is_primary', contact_11.is_primary,", - " 'target',", - " CASE", - " WHEN entity_13.target_type = 'address' THEN (", - " (SELECT jsonb_build_object(", - " 'archived', entity_15.archived,", - " 'city', address_14.city,", - " 'created_at', entity_15.created_at,", - " 'id', entity_15.id,", - " 'type', entity_15.type", - " )", - " FROM agreego.address address_14", - " JOIN agreego.entity entity_15 ON entity_15.id = address_14.id", - " WHERE", - " NOT entity_15.archived", - " AND relationship_12.target_id = entity_15.id)", - " )", - " WHEN entity_13.target_type = 'email_address' THEN (", - " (SELECT jsonb_build_object(", - " 'address', email_address_16.address,", - " 'archived', entity_17.archived,", - " 'created_at', entity_17.created_at,", - " 'id', entity_17.id,", - " 'type', entity_17.type", - " )", - " FROM agreego.email_address email_address_16", - " JOIN agreego.entity entity_17 ON entity_17.id = email_address_16.id", - " WHERE", - " NOT entity_17.archived", - " AND relationship_12.target_id = entity_17.id)", - " )", - " WHEN entity_13.target_type = 'phone_number' THEN (", - " (SELECT jsonb_build_object(", - " 'archived', entity_19.archived,", - " 'created_at', entity_19.created_at,", - " 'id', entity_19.id,", - " 'number', phone_number_18.number,", - " 'type', entity_19.type", - " )", - " FROM agreego.phone_number phone_number_18", - " JOIN agreego.entity entity_19 ON entity_19.id = phone_number_18.id", - " WHERE", - " NOT entity_19.archived", - " AND relationship_12.target_id = entity_19.id)", - " )", - " ELSE NULL", - " END,", - " 'type', entity_13.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_11", - " JOIN agreego.relationship relationship_12 ON relationship_12.id = contact_11.id", - " JOIN agreego.entity entity_13 ON entity_13.id = relationship_12.id", - " WHERE", - " NOT entity_13.archived", - " AND relationship_12.source_id = entity_5.id),", - " 'created_at', entity_5.created_at,", - " 'email_addresses',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_22.archived,", - " 'created_at', entity_22.created_at,", - " 'id', entity_22.id,", - " 'is_primary', contact_20.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'address', email_address_23.address,", - " 'archived', entity_24.archived,", - " 'created_at', entity_24.created_at,", - " 'id', entity_24.id,", - " 'type', entity_24.type", - " )", - " FROM agreego.email_address email_address_23", - " JOIN agreego.entity entity_24 ON entity_24.id = email_address_23.id", - " WHERE", - " NOT entity_24.archived", - " AND relationship_21.target_id = entity_24.id),", - " 'type', entity_22.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_20", - " JOIN agreego.relationship relationship_21 ON relationship_21.id = contact_20.id", - " JOIN agreego.entity entity_22 ON entity_22.id = relationship_21.id", - " WHERE", - " NOT entity_22.archived", - " AND relationship_21.target_type = 'email_address'", - " AND relationship_21.source_id = entity_5.id),", - " 'first_name', person_3.first_name,", - " 'id', entity_5.id,", - " 'last_name', person_3.last_name,", - " 'name', organization_4.name,", - " 'phone_numbers',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_27.archived,", - " 'created_at', entity_27.created_at,", - " 'id', entity_27.id,", - " 'is_primary', contact_25.is_primary,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'archived', entity_29.archived,", - " 'created_at', entity_29.created_at,", - " 'id', entity_29.id,", - " 'number', phone_number_28.number,", - " 'type', entity_29.type", - " )", - " FROM agreego.phone_number phone_number_28", - " JOIN agreego.entity entity_29 ON entity_29.id = phone_number_28.id", - " WHERE", - " NOT entity_29.archived", - " AND relationship_26.target_id = entity_29.id),", - " 'type', entity_27.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_25", - " JOIN agreego.relationship relationship_26 ON relationship_26.id = contact_25.id", - " JOIN agreego.entity entity_27 ON entity_27.id = relationship_26.id", - " WHERE", - " NOT entity_27.archived", - " AND relationship_26.target_type = 'phone_number'", - " AND relationship_26.source_id = entity_5.id),", - " 'type', entity_5.type", - " )", - " FROM agreego.person person_3", - " JOIN agreego.organization organization_4 ON organization_4.id = person_3.id", - " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", - " WHERE NOT entity_5.archived AND entity_5.id = entity_2.id))", - " ELSE NULL", - "END", - "FROM agreego.organization organization_1", - "JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", - "WHERE NOT entity_2.archived)))" - ] - ] - } - }, - { - "description": "Orders select via a punc with items", - "action": "query", - "schema_id": "get_orders.response", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'customer',", - " (SELECT jsonb_build_object(", - " 'age', person_3.age,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", - " 'first_name', person_3.first_name,", - " 'id', entity_5.id,", - " 'last_name', person_3.last_name,", - " 'name', organization_4.name,", - " 'type', entity_5.type", - " )", - " FROM agreego.person person_3", - " JOIN agreego.organization organization_4 ON organization_4.id = person_3.id", - " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", - " WHERE", - " NOT entity_5.archived", - " AND order_1.customer_id = person_3.id),", - " 'customer_id', order_1.customer_id,", - " 'id', entity_2.id,", - " 'total', order_1.total,", - " 'type', entity_2.type", - ")), '[]'::jsonb)", - "FROM agreego.order order_1", - "JOIN agreego.entity entity_2 ON entity_2.id = order_1.id", - "WHERE NOT entity_2.archived)))" - ] - ] - } - }, - { - "description": "Widgets select via a punc response with family (STI)", - "action": "query", - "schema_id": "get_widgets.response", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT COALESCE(jsonb_agg(", - " CASE", - " WHEN widget_1.kind = 'stock' THEN (", - " jsonb_build_object(", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'id', entity_2.id,", - " 'kind', widget_1.kind,", - " 'type', entity_2.type", - " )", - " )", - " WHEN widget_1.kind = 'tasks' THEN (", - " jsonb_build_object(", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'id', entity_2.id,", - " 'kind', widget_1.kind,", - " 'type', entity_2.type", - " )", - " )", - " ELSE NULL", - " END", - "), '[]'::jsonb)", - "FROM agreego.widget widget_1", - "JOIN agreego.entity entity_2 ON entity_2.id = widget_1.id", - "WHERE NOT entity_2.archived)))" - ] - ] - } - }, - { - "description": "Query invoice with complex JSONB metadata field extraction", - "action": "query", - "schema_id": "invoice", - "expect": { - "success": true, - "sql": [ - [ - "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'id', entity_2.id,", - " 'metadata', invoice_1.metadata,", - " 'number', invoice_1.number,", - " 'type', entity_2.type", - ")", - "FROM agreego.invoice invoice_1", - "JOIN agreego.entity entity_2 ON entity_2.id = invoice_1.id", - "WHERE NOT entity_2.archived)))" - ] - ] - } + { + "description": "Queryer Execution", + "database": { + "puncs": [ + { + "name": "get_organization", + "schemas": { + "get_organization.response": { + "type": "organization" } - ] - } + } + }, + { + "name": "get_organizations", + "schemas": { + "get_organizations.response": { + "type": "array", + "items": { + "$family": "organization" + } + } + } + }, + { + "name": "get_light_organization", + "schemas": { + "get_light_organization.response": { + "$family": "light.organization" + } + } + }, + { + "name": "get_full_organization", + "schemas": { + "get_full_organization.response": { + "$family": "full.organization" + } + } + }, + { + "name": "get_orders", + "schemas": { + "get_orders.response": { + "type": "array", + "items": { + "type": "light.order" + } + } + } + }, + { + "name": "get_widgets", + "schemas": { + "get_widgets.response": { + "type": "array", + "items": { + "$family": "widget" + } + } + } + } + ], + "enums": [], + "relations": [ + { + "type": "relation", + "id": "00000000-0000-0000-0000-000000000001", + "constraint": "fk_relationship_source_entity", + "source_type": "relationship", + "source_columns": [ + "source_id", + "source_type" + ], + "destination_type": "entity", + "destination_columns": [ + "id", + "type" + ], + "prefix": "source" + }, + { + "type": "relation", + "id": "00000000-0000-0000-0000-000000000002", + "constraint": "fk_relationship_target_entity", + "source_type": "relationship", + "source_columns": [ + "target_id", + "target_type" + ], + "destination_type": "entity", + "destination_columns": [ + "id", + "type" + ], + "prefix": "target" + }, + { + "id": "22222222-2222-2222-2222-222222222222", + "type": "relation", + "constraint": "fk_order_customer_person", + "source_type": "order", + "source_columns": [ + "customer_id" + ], + "destination_type": "person", + "destination_columns": [ + "id" + ], + "prefix": "customer" + }, + { + "id": "22222222-2222-2222-2222-222222222227", + "type": "relation", + "constraint": "fk_order_counterparty_entity", + "source_type": "order", + "source_columns": [ + "counterparty_id", + "counterparty_type" + ], + "destination_type": "entity", + "destination_columns": [ + "id", + "type" + ], + "prefix": "counterparty" + }, + { + "id": "33333333-3333-3333-3333-333333333333", + "type": "relation", + "constraint": "fk_order_line_order", + "source_type": "order_line", + "source_columns": [ + "order_id" + ], + "destination_type": "order", + "destination_columns": [ + "id" + ] + }, + { + "id": "33333333-3333-3333-3333-333333333334", + "type": "relation", + "constraint": "fk_invoice_line_invoice", + "source_type": "invoice_line", + "source_columns": [ + "invoice_id" + ], + "destination_type": "invoice", + "destination_columns": [ + "id" + ] + } + ], + "types": [ + { + "name": "entity", + "hierarchy": [ + "entity" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ] + }, + "field_types": { + "id": "uuid", + "archived": "boolean", + "created_at": "timestamptz", + "type": "text" + }, + "schemas": { + "entity": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "uuid" + }, + "type": { + "type": "string" + }, + "archived": { + "type": "boolean" + }, + "created_at": { + "type": "string", + "format": "date-time" + }, + "created": { + "type": "boolean" + } + } + } + }, + "fields": [ + "id", + "type", + "archived", + "created_at" + ], + "variations": [ + "address", + "bot", + "contact", + "email_address", + "entity", + "order", + "order_line", + "organization", + "person", + "phone_number", + "relationship" + ] + }, + { + "name": "organization", + "hierarchy": [ + "organization", + "entity" + ], + "fields": [ + "id", + "type", + "name", + "archived", + "created_at" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ], + "organization": [ + "name" + ] + }, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "name": "text", + "created_at": "timestamptz" + }, + "lookup_fields": [ + "id" + ], + "null_fields": [], + "default_fields": [ + "id", + "type", + "created_at", + "archived" + ], + "variations": [ + "bot", + "organization", + "person" + ], + "schemas": { + "organization": { + "type": "entity", + "properties": { + "name": { + "type": "string" + } + } + } + } + }, + { + "name": "bot", + "hierarchy": [ + "bot", + "organization", + "entity" + ], + "fields": [ + "token", + "id", + "type", + "name", + "archived", + "created_at", + "token", + "role" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ], + "organization": [ + "name" + ], + "bot": [ + "token", + "role" + ] + }, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "name": "text", + "token": "text", + "role": "text", + "created_at": "timestamptz" + }, + "schemas": { + "bot": { + "type": "organization", + "properties": { + "token": { + "type": "string" + }, + "role": { + "type": "string" + } + } + }, + "light.bot": { + "type": "organization", + "properties": { + "token": { + "type": "string" + } + } + } + }, + "variations": [ + "bot" + ] + }, + { + "name": "person", + "hierarchy": [ + "person", + "organization", + "entity" + ], + "fields": [ + "first_name", + "last_name", + "id", + "type", + "name", + "age", + "archived", + "created_at" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ], + "organization": [ + "name" + ], + "person": [ + "first_name", + "last_name", + "age" + ] + }, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "first_name": "text", + "last_name": "text", + "name": "text", + "age": "numeric", + "created_at": "timestamptz" + }, + "schemas": { + "person": { + "type": "organization", + "properties": { + "first_name": { + "type": "string" + }, + "last_name": { + "type": "string" + }, + "age": { + "type": "number" + } + } + }, + "light.person": { + "type": "organization", + "properties": { + "first_name": { + "type": "string" + }, + "last_name": { + "type": "string" + } + } + }, + "full.person": { + "type": "person", + "properties": { + "phone_numbers": { + "type": "array", + "items": { + "type": "contact", + "properties": { + "target": { + "type": "phone_number" + } + } + } + }, + "email_addresses": { + "type": "array", + "items": { + "type": "contact", + "properties": { + "target": { + "type": "email_address" + } + } + } + }, + "addresses": { + "type": "array", + "items": { + "type": "contact", + "properties": { + "target": { + "type": "address" + } + } + } + }, + "contacts": { + "type": "array", + "items": { + "type": "contact", + "properties": { + "target": { + "oneOf": [ + { + "type": "phone_number" + }, + { + "type": "email_address" + }, + { + "type": "address" + } + ] + } + } + } + } + } + } + }, + "variations": [ + "person" + ] + }, + { + "name": "relationship", + "relationship": true, + "hierarchy": [ + "relationship", + "entity" + ], + "fields": [ + "source_id", + "source_type", + "target_id", + "target_type", + "id", + "type", + "archived", + "created_at" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ], + "relationship": [ + "source_id", + "source_type", + "target_id", + "target_type" + ] + }, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "source_id": "uuid", + "source_type": "text", + "target_id": "uuid", + "target_type": "text", + "created_at": "timestamptz" + }, + "schemas": { + "relationship": { + "type": "entity", + "properties": {} + } + }, + "variations": [ + "contact", + "relationship" + ] + }, + { + "name": "contact", + "relationship": true, + "hierarchy": [ + "contact", + "relationship", + "entity" + ], + "fields": [ + "is_primary", + "source_id", + "source_type", + "target_id", + "target_type", + "id", + "type", + "archived", + "created_at" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ], + "relationship": [ + "source_id", + "source_type", + "target_id", + "target_type" + ], + "contact": [ + "is_primary" + ] + }, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "source_id": "uuid", + "source_type": "text", + "target_id": "uuid", + "target_type": "text", + "is_primary": "boolean", + "created_at": "timestamptz" + }, + "schemas": { + "contact": { + "type": "relationship", + "properties": { + "is_primary": { + "type": "boolean" + } + } + } + }, + "variations": [ + "contact" + ] + }, + { + "name": "phone_number", + "hierarchy": [ + "phone_number", + "entity" + ], + "fields": [ + "number", + "id", + "type", + "archived", + "created_at" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ], + "phone_number": [ + "number" + ] + }, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "number": "text", + "created_at": "timestamptz" + }, + "schemas": { + "phone_number": { + "type": "entity", + "properties": { + "number": { + "type": "string" + } + } + } + }, + "variations": [ + "phone_number" + ] + }, + { + "name": "email_address", + "hierarchy": [ + "email_address", + "entity" + ], + "fields": [ + "address", + "id", + "type", + "archived", + "created_at" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ], + "email_address": [ + "address" + ] + }, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "address": "text", + "created_at": "timestamptz" + }, + "schemas": { + "email_address": { + "type": "entity", + "properties": { + "address": { + "type": "string" + } + } + } + }, + "variations": [ + "email_address" + ] + }, + { + "name": "address", + "hierarchy": [ + "address", + "entity" + ], + "fields": [ + "city", + "id", + "type", + "archived", + "created_at" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ], + "address": [ + "city" + ] + }, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "city": "text", + "created_at": "timestamptz" + }, + "schemas": { + "address": { + "type": "entity", + "properties": { + "city": { + "type": "string" + } + } + } + }, + "variations": [ + "address" + ] + }, + { + "name": "order", + "schemas": { + "order": { + "type": "entity", + "properties": { + "total": { + "type": "number" + }, + "customer_id": { + "type": "string" + } + } + }, + "light.order": { + "type": "order", + "properties": { + "customer": { + "type": "person" + } + } + }, + "full.order": { + "type": "order", + "properties": { + "customer": { + "type": "person" + }, + "lines": { + "type": "array", + "items": { + "type": "order_line" + } + } + } + } + }, + "hierarchy": [ + "order", + "entity" + ], + "fields": [ + "id", + "type", + "total", + "customer_id", + "created_at", + "archived", + "counterparty_id", + "counterparty_type" + ], + "grouped_fields": { + "order": [ + "id", + "type", + "total", + "customer_id", + "counterparty_id", + "counterparty_type" + ], + "entity": [ + "id", + "type", + "created_at", + "archived" + ] + }, + "lookup_fields": [ + "id" + ], + "historical": true, + "relationship": false, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "total": "numeric", + "customer_id": "uuid", + "created_at": "timestamptz", + "created_by": "uuid", + "modified_at": "timestamptz", + "modified_by": "uuid", + "counterparty_id": "uuid", + "counterparty_type": "text" + }, + "variations": [ + "order" + ] + }, + { + "name": "order_line", + "schemas": { + "order_line": { + "type": "entity", + "properties": { + "order_id": { + "type": "string" + }, + "product": { + "type": "string" + }, + "price": { + "type": "number" + } + } + } + }, + "hierarchy": [ + "order_line", + "entity" + ], + "fields": [ + "id", + "type", + "order_id", + "product", + "price", + "created_at", + "archived" + ], + "grouped_fields": { + "order_line": [ + "id", + "type", + "order_id", + "product", + "price" + ], + "entity": [ + "id", + "type", + "created_at", + "archived" + ] + }, + "lookup_fields": [], + "historical": true, + "relationship": false, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "order_id": "uuid", + "product": "text", + "price": "numeric", + "created_at": "timestamptz" + }, + "variations": [ + "order_line" + ] + }, + { + "name": "widget", + "hierarchy": [ + "widget", + "entity" + ], + "fields": [ + "id", + "type", + "kind", + "archived", + "created_at" + ], + "grouped_fields": { + "entity": [ + "id", + "type", + "archived", + "created_at" + ], + "widget": [ + "kind" + ] + }, + "field_types": { + "id": "uuid", + "type": "text", + "kind": "text", + "archived": "boolean", + "created_at": "timestamptz" + }, + "variations": [ + "widget" + ], + "schemas": { + "widget": { + "type": "entity", + "properties": { + "kind": { + "type": "string" + } + } + }, + "stock.widget": { + "type": "widget", + "properties": {} + }, + "tasks.widget": { + "type": "widget", + "properties": {} + } + } + }, + { + "name": "invoice", + "schemas": { + "invoice": { + "type": "entity", + "properties": { + "total": { + "type": "number" + }, + "lines": { + "type": "array", + "items": { + "type": "invoice_line" + } + }, + "metadata_line": { + "type": "invoice_line" + }, + "metadata_lines": { + "type": "array", + "items": { + "type": "invoice_line" + } + }, + "metadata_nested_line": { + "type": "object", + "properties": { + "line": { + "type": "invoice_line" + } + } + }, + "metadata_nested_lines": { + "type": "object", + "properties": { + "lines": { + "type": "array", + "items": { + "type": "invoice_line" + } + } + } + } + } + } + }, + "hierarchy": [ + "invoice", + "entity" + ], + "fields": [ + "id", + "type", + "total", + "metadata_line", + "metadata_lines", + "metadata_nested_line", + "metadata_nested_lines", + "created_at", + "archived" + ], + "grouped_fields": { + "invoice": [ + "id", + "type", + "total", + "metadata_line", + "metadata_lines", + "metadata_nested_line", + "metadata_nested_lines" + ], + "entity": [ + "id", + "type", + "created_at", + "archived" + ] + }, + "lookup_fields": [ + "id" + ], + "historical": true, + "relationship": false, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "total": "numeric", + "metadata_line": "jsonb", + "metadata_lines": "jsonb", + "metadata_nested_line": "jsonb", + "metadata_nested_lines": "jsonb", + "created_at": "timestamptz", + "created_by": "uuid", + "modified_at": "timestamptz", + "modified_by": "uuid" + }, + "variations": [ + "invoice" + ] + }, + { + "name": "invoice_line", + "schemas": { + "invoice_line": { + "type": "entity", + "properties": { + "invoice_id": { + "type": "string" + }, + "price": { + "type": "number" + } + } + } + }, + "hierarchy": [ + "invoice_line", + "entity" + ], + "fields": [ + "id", + "type", + "invoice_id", + "price", + "created_at", + "archived" + ], + "grouped_fields": { + "invoice_line": [ + "id", + "type", + "invoice_id", + "price" + ], + "entity": [ + "id", + "type", + "created_at", + "created_by", + "modified_at", + "modified_by", + "archived" + ] + }, + "lookup_fields": [], + "historical": true, + "relationship": false, + "field_types": { + "id": "uuid", + "type": "text", + "archived": "boolean", + "invoice_id": "uuid", + "price": "numeric", + "created_at": "timestamptz" + }, + "variations": [ + "invoice_line" + ] + } + ] + }, + "tests": [ + { + "description": "Simple entity select", + "action": "query", + "schema_id": "entity", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'id', entity_1.id,", + " 'type', entity_1.type)", + "FROM agreego.entity entity_1", + "WHERE NOT entity_1.archived)))" + ] + ] + } + }, + { + "description": "Simple entity select with multiple filters", + "action": "query", + "schema_id": "entity", + "filters": { + "id": { + "$eq": "123e4567-e89b-12d3-a456-426614174000", + "$ne": "123e4567-e89b-12d3-a456-426614174001", + "$in": [ + "123e4567-e89b-12d3-a456-426614174000" + ], + "$nin": [ + "123e4567-e89b-12d3-a456-426614174001" + ] + }, + "created_at": { + "$eq": "2023-01-01T00:00:00Z", + "$ne": "2023-01-02T00:00:00Z", + "$gt": "2022-01-01T00:00:00Z", + "$gte": "2022-01-02T00:00:00Z", + "$lt": "2024-01-01T00:00:00Z", + "$lte": "2024-01-02T00:00:00Z" + }, + "archived": { + "$eq": false, + "$ne": true + } + }, + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'id', entity_1.id,", + " 'type', entity_1.type", + ")", + "FROM agreego.entity entity_1", + "WHERE", + " NOT entity_1.archived", + " AND entity_1.archived = ($1#>>'{}')::boolean", + " AND entity_1.archived != ($2#>>'{}')::boolean", + " AND entity_1.created_at = ($3#>>'{}')::timestamptz", + " AND entity_1.created_at > ($4#>>'{}')::timestamptz", + " AND entity_1.created_at >= ($5#>>'{}')::timestamptz", + " AND entity_1.created_at < ($6#>>'{}')::timestamptz", + " AND entity_1.created_at <= ($7#>>'{}')::timestamptz", + " AND entity_1.created_at != ($8#>>'{}')::timestamptz", + " AND entity_1.id = ($9#>>'{}')::uuid", + " AND entity_1.id IN (SELECT value::uuid FROM jsonb_array_elements_text(($10#>>'{}')::jsonb))", + " AND entity_1.id != ($11#>>'{}')::uuid", + " AND entity_1.id NOT IN (SELECT value::uuid FROM jsonb_array_elements_text(($12#>>'{}')::jsonb))", + ")))" + ] + ] + } + }, + { + "description": "Person select on base schema", + "action": "query", + "schema_id": "person", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", + " 'age', person_1.age,", + " 'archived', entity_3.archived,", + " 'created_at', entity_3.created_at,", + " 'first_name', person_1.first_name,", + " 'id', entity_3.id,", + " 'last_name', person_1.last_name,", + " 'name', organization_2.name,", + " 'type', entity_3.type)", + "FROM agreego.person person_1", + "JOIN agreego.organization organization_2 ON organization_2.id = person_1.id", + "JOIN agreego.entity entity_3 ON entity_3.id = organization_2.id", + "WHERE NOT entity_3.archived)))" + ] + ] + } + }, + { + "description": "Person select on full schema", + "action": "query", + "schema_id": "full.person", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", + " 'addresses',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_6.archived,", + " 'created_at', entity_6.created_at,", + " 'id', entity_6.id,", + " 'is_primary', contact_4.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'archived', entity_8.archived,", + " 'city', address_7.city,", + " 'created_at', entity_8.created_at,", + " 'id', entity_8.id,", + " 'type', entity_8.type", + " )", + " FROM agreego.address address_7", + " JOIN agreego.entity entity_8 ON entity_8.id = address_7.id", + " WHERE", + " NOT entity_8.archived", + " AND relationship_5.target_id = entity_8.id),", + " 'type', entity_6.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_4", + " JOIN agreego.relationship relationship_5 ON relationship_5.id = contact_4.id", + " JOIN agreego.entity entity_6 ON entity_6.id = relationship_5.id", + " WHERE", + " NOT entity_6.archived", + " AND relationship_5.target_type = 'address'", + " AND relationship_5.source_id = entity_3.id),", + " 'age', person_1.age,", + " 'archived', entity_3.archived,", + " 'contacts',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_11.archived,", + " 'created_at', entity_11.created_at,", + " 'id', entity_11.id,", + " 'is_primary', contact_9.is_primary,", + " 'target', CASE", + " WHEN entity_11.target_type = 'address' THEN", + " ((SELECT jsonb_build_object(", + " 'archived', entity_13.archived,", + " 'city', address_12.city,", + " 'created_at', entity_13.created_at,", + " 'id', entity_13.id,", + " 'type', entity_13.type", + " )", + " FROM agreego.address address_12", + " JOIN agreego.entity entity_13 ON entity_13.id = address_12.id", + " WHERE", + " NOT entity_13.archived", + " AND relationship_10.target_id = entity_13.id))", + " WHEN entity_11.target_type = 'email_address' THEN", + " ((SELECT jsonb_build_object(", + " 'address', email_address_14.address,", + " 'archived', entity_15.archived,", + " 'created_at', entity_15.created_at,", + " 'id', entity_15.id,", + " 'type', entity_15.type", + " )", + " FROM agreego.email_address email_address_14", + " JOIN agreego.entity entity_15 ON entity_15.id = email_address_14.id", + " WHERE", + " NOT entity_15.archived", + " AND relationship_10.target_id = entity_15.id))", + " WHEN entity_11.target_type = 'phone_number' THEN", + " ((SELECT jsonb_build_object(", + " 'archived', entity_17.archived,", + " 'created_at', entity_17.created_at,", + " 'id', entity_17.id,", + " 'number', phone_number_16.number,", + " 'type', entity_17.type", + " )", + " FROM agreego.phone_number phone_number_16", + " JOIN agreego.entity entity_17 ON entity_17.id = phone_number_16.id", + " WHERE", + " NOT entity_17.archived", + " AND relationship_10.target_id = entity_17.id))", + " ELSE NULL END,", + " 'type', entity_11.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_9", + " JOIN agreego.relationship relationship_10 ON relationship_10.id = contact_9.id", + " JOIN agreego.entity entity_11 ON entity_11.id = relationship_10.id", + " WHERE", + " NOT entity_11.archived", + " AND relationship_10.source_id = entity_3.id),", + " 'created_at', entity_3.created_at,", + " 'email_addresses',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_20.archived,", + " 'created_at', entity_20.created_at,", + " 'id', entity_20.id,", + " 'is_primary', contact_18.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'address', email_address_21.address,", + " 'archived', entity_22.archived,", + " 'created_at', entity_22.created_at,", + " 'id', entity_22.id,", + " 'type', entity_22.type", + " )", + " FROM agreego.email_address email_address_21", + " JOIN agreego.entity entity_22 ON entity_22.id = email_address_21.id", + " WHERE", + " NOT entity_22.archived", + " AND relationship_19.target_id = entity_22.id),", + " 'type', entity_20.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_18", + " JOIN agreego.relationship relationship_19 ON relationship_19.id = contact_18.id", + " JOIN agreego.entity entity_20 ON entity_20.id = relationship_19.id", + " WHERE", + " NOT entity_20.archived", + " AND relationship_19.target_type = 'email_address'", + " AND relationship_19.source_id = entity_3.id),", + " 'first_name', person_1.first_name,", + " 'id', entity_3.id,", + " 'last_name', person_1.last_name,", + " 'name', organization_2.name,", + " 'phone_numbers',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_25.archived,", + " 'created_at', entity_25.created_at,", + " 'id', entity_25.id,", + " 'is_primary', contact_23.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'archived', entity_27.archived,", + " 'created_at', entity_27.created_at,", + " 'id', entity_27.id,", + " 'number', phone_number_26.number,", + " 'type', entity_27.type", + " )", + " FROM agreego.phone_number phone_number_26", + " JOIN agreego.entity entity_27 ON entity_27.id = phone_number_26.id", + " WHERE", + " NOT entity_27.archived", + " AND relationship_24.target_id = entity_27.id),", + " 'type', entity_25.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_23", + " JOIN agreego.relationship relationship_24 ON relationship_24.id = contact_23.id", + " JOIN agreego.entity entity_25 ON entity_25.id = relationship_24.id", + " WHERE", + " NOT entity_25.archived", + " AND relationship_24.target_type = 'phone_number'", + " AND relationship_24.source_id = entity_3.id),", + " 'type', entity_3.type", + ")", + "FROM agreego.person person_1", + "JOIN agreego.organization organization_2 ON organization_2.id = person_1.id", + "JOIN agreego.entity entity_3 ON entity_3.id = organization_2.id", + "WHERE NOT entity_3.archived)))" + ] + ] + } + }, + { + "description": "Person select on full schema with filters", + "action": "query", + "schema_id": "full.person", + "filters": { + "age": { + "$eq": 30, + "$gt": 20, + "$gte": 20, + "$in": [ + 30, + 40 + ], + "$lt": 50, + "$lte": 50, + "$ne": 25, + "$nin": [ + 1, + 2 + ] + }, + "archived": { + "$eq": true, + "$ne": false + }, + "contacts": { + "is_primary": { + "$eq": true + } + }, + "created_at": { + "$eq": "2020-01-01T00:00:00Z", + "$gt": "2019-01-01T00:00:00Z", + "$gte": "2019-01-01T00:00:00Z", + "$lt": "2021-01-01T00:00:00Z", + "$lte": "2021-01-01T00:00:00Z", + "$ne": "2022-01-01T00:00:00Z" + }, + "first_name": { + "$eq": "Jane%", + "$gt": "A", + "$gte": "A", + "$in": [ + "Jane", + "John" + ], + "$lt": "Z", + "$lte": "Z", + "$ne": "Doe", + "$nin": [ + "Bob" + ] + }, + "id": { + "$eq": "00000000-0000-0000-0000-000000000001", + "$in": [ + "00000000-0000-0000-0000-000000000001" + ], + "$ne": "00000000-0000-0000-0000-000000000002", + "$nin": [ + "00000000-0000-0000-0000-000000000002" + ] + }, + "last_name": { + "$eq": "%Doe%", + "$ne": "%Smith%" + }, + "phone_numbers": { + "target": { + "number": { + "$eq": "555-1234" + } + } + } + }, + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", + " 'addresses',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_6.archived,", + " 'created_at', entity_6.created_at,", + " 'id', entity_6.id,", + " 'is_primary', contact_4.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'archived', entity_8.archived,", + " 'city', address_7.city,", + " 'created_at', entity_8.created_at,", + " 'id', entity_8.id,", + " 'type', entity_8.type", + " )", + " FROM agreego.address address_7", + " JOIN agreego.entity entity_8 ON entity_8.id = address_7.id", + " WHERE", + " NOT entity_8.archived", + " AND relationship_5.target_id = entity_8.id),", + " 'type', entity_6.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_4", + " JOIN agreego.relationship relationship_5 ON relationship_5.id = contact_4.id", + " JOIN agreego.entity entity_6 ON entity_6.id = relationship_5.id", + " WHERE", + " NOT entity_6.archived", + " AND relationship_5.target_type = 'address'", + " AND relationship_5.source_id = entity_3.id),", + " 'age', person_1.age,", + " 'archived', entity_3.archived,", + " 'contacts',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_11.archived,", + " 'created_at', entity_11.created_at,", + " 'id', entity_11.id,", + " 'is_primary', contact_9.is_primary,", + " 'target', CASE", + " WHEN entity_11.target_type = 'address' THEN", + " ((SELECT jsonb_build_object(", + " 'archived', entity_13.archived,", + " 'city', address_12.city,", + " 'created_at', entity_13.created_at,", + " 'id', entity_13.id,", + " 'type', entity_13.type", + " )", + " FROM agreego.address address_12", + " JOIN agreego.entity entity_13 ON entity_13.id = address_12.id", + " WHERE", + " NOT entity_13.archived", + " AND relationship_10.target_id = entity_13.id))", + " WHEN entity_11.target_type = 'email_address' THEN", + " ((SELECT jsonb_build_object(", + " 'address', email_address_14.address,", + " 'archived', entity_15.archived,", + " 'created_at', entity_15.created_at,", + " 'id', entity_15.id,", + " 'type', entity_15.type", + " )", + " FROM agreego.email_address email_address_14", + " JOIN agreego.entity entity_15 ON entity_15.id = email_address_14.id", + " WHERE", + " NOT entity_15.archived", + " AND relationship_10.target_id = entity_15.id))", + " WHEN entity_11.target_type = 'phone_number' THEN", + " ((SELECT jsonb_build_object(", + " 'archived', entity_17.archived,", + " 'created_at', entity_17.created_at,", + " 'id', entity_17.id,", + " 'number', phone_number_16.number,", + " 'type', entity_17.type", + " )", + " FROM agreego.phone_number phone_number_16", + " JOIN agreego.entity entity_17 ON entity_17.id = phone_number_16.id", + " WHERE", + " NOT entity_17.archived", + " AND relationship_10.target_id = entity_17.id))", + " ELSE NULL END,", + " 'type', entity_11.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_9", + " JOIN agreego.relationship relationship_10 ON relationship_10.id = contact_9.id", + " JOIN agreego.entity entity_11 ON entity_11.id = relationship_10.id", + " WHERE", + " NOT entity_11.archived", + " AND contact_9.is_primary = ($11#>>'{}')::boolean", + " AND relationship_10.source_id = entity_3.id),", + " 'created_at', entity_3.created_at,", + " 'email_addresses',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_20.archived,", + " 'created_at', entity_20.created_at,", + " 'id', entity_20.id,", + " 'is_primary', contact_18.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'address', email_address_21.address,", + " 'archived', entity_22.archived,", + " 'created_at', entity_22.created_at,", + " 'id', entity_22.id,", + " 'type', entity_22.type", + " )", + " FROM agreego.email_address email_address_21", + " JOIN agreego.entity entity_22 ON entity_22.id = email_address_21.id", + " WHERE", + " NOT entity_22.archived", + " AND relationship_19.target_id = entity_22.id),", + " 'type', entity_20.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_18", + " JOIN agreego.relationship relationship_19 ON relationship_19.id = contact_18.id", + " JOIN agreego.entity entity_20 ON entity_20.id = relationship_19.id", + " WHERE", + " NOT entity_20.archived", + " AND relationship_19.target_type = 'email_address'", + " AND relationship_19.source_id = entity_3.id),", + " 'first_name', person_1.first_name,", + " 'id', entity_3.id,", + " 'last_name', person_1.last_name,", + " 'name', organization_2.name,", + " 'phone_numbers',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_25.archived,", + " 'created_at', entity_25.created_at,", + " 'id', entity_25.id,", + " 'is_primary', contact_23.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'archived', entity_27.archived,", + " 'created_at', entity_27.created_at,", + " 'id', entity_27.id,", + " 'number', phone_number_26.number,", + " 'type', entity_27.type", + " )", + " FROM agreego.phone_number phone_number_26", + " JOIN agreego.entity entity_27 ON entity_27.id = phone_number_26.id", + " WHERE", + " NOT entity_27.archived", + " AND phone_number_26.number ILIKE $32#>>'{}'", + " AND relationship_24.target_id = entity_27.id),", + " 'type', entity_25.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_23", + " JOIN agreego.relationship relationship_24 ON relationship_24.id = contact_23.id", + " JOIN agreego.entity entity_25 ON entity_25.id = relationship_24.id", + " WHERE", + " NOT entity_25.archived", + " AND relationship_24.target_type = 'phone_number'", + " AND relationship_24.source_id = entity_3.id),", + " 'type', entity_3.type", + ")", + "FROM agreego.person person_1", + "JOIN agreego.organization organization_2 ON organization_2.id = person_1.id", + "JOIN agreego.entity entity_3 ON entity_3.id = organization_2.id", + "WHERE", + " NOT entity_3.archived", + " AND person_1.age = ($1#>>'{}')::numeric", + " AND person_1.age > ($2#>>'{}')::numeric", + " AND person_1.age >= ($3#>>'{}')::numeric", + " AND person_1.age IN (SELECT value::numeric FROM jsonb_array_elements_text(($4#>>'{}')::jsonb))", + " AND person_1.age < ($5#>>'{}')::numeric", + " AND person_1.age <= ($6#>>'{}')::numeric", + " AND person_1.age != ($7#>>'{}')::numeric", + " AND person_1.age NOT IN (SELECT value::numeric FROM jsonb_array_elements_text(($8#>>'{}')::jsonb))", + " AND entity_3.archived = ($9#>>'{}')::boolean", + " AND entity_3.archived != ($10#>>'{}')::boolean", + " AND entity_3.created_at = ($12#>>'{}')::timestamptz", + " AND entity_3.created_at > ($13#>>'{}')::timestamptz", + " AND entity_3.created_at >= ($14#>>'{}')::timestamptz", + " AND entity_3.created_at < ($15#>>'{}')::timestamptz", + " AND entity_3.created_at <= ($16#>>'{}')::timestamptz", + " AND entity_3.created_at != ($17#>>'{}')::timestamptz", + " AND person_1.first_name ILIKE $18#>>'{}'", + " AND person_1.first_name > ($19#>>'{}')", + " AND person_1.first_name >= ($20#>>'{}')", + " AND person_1.first_name IN (SELECT value FROM jsonb_array_elements_text(($21#>>'{}')::jsonb))", + " AND person_1.first_name < ($22#>>'{}')", + " AND person_1.first_name <= ($23#>>'{}')", + " AND person_1.first_name NOT ILIKE $24#>>'{}'", + " AND person_1.first_name NOT IN (SELECT value FROM jsonb_array_elements_text(($25#>>'{}')::jsonb))", + " AND entity_3.id = ($26#>>'{}')::uuid", + " AND entity_3.id IN (SELECT value::uuid FROM jsonb_array_elements_text(($27#>>'{}')::jsonb))", + " AND entity_3.id != ($28#>>'{}')::uuid", + " AND entity_3.id NOT IN (SELECT value::uuid FROM jsonb_array_elements_text(($29#>>'{}')::jsonb))", + " AND person_1.last_name ILIKE $30#>>'{}'", + " AND person_1.last_name NOT ILIKE $31#>>'{}')))" + ] + ] + } + }, + { + "description": "Person ad-hoc email addresses select", + "action": "query", + "schema_id": "full.person/email_addresses", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_3.archived,", + " 'created_at', entity_3.created_at,", + " 'id', entity_3.id,", + " 'is_primary', contact_1.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'address', email_address_4.address,", + " 'archived', entity_5.archived,", + " 'created_at', entity_5.created_at,", + " 'id', entity_5.id,", + " 'type', entity_5.type", + " )", + " FROM agreego.email_address email_address_4", + " JOIN agreego.entity entity_5 ON entity_5.id = email_address_4.id", + " WHERE", + " NOT entity_5.archived", + " AND relationship_2.target_id = entity_5.id),", + " 'type', entity_3.type", + ")), '[]'::jsonb)", + "FROM agreego.contact contact_1", + "JOIN agreego.relationship relationship_2 ON relationship_2.id = contact_1.id", + "JOIN agreego.entity entity_3 ON entity_3.id = relationship_2.id", + "WHERE", + " NOT entity_3.archived", + " AND relationship_2.target_type = 'email_address')))" + ] + ] + } + }, + { + "description": "Order select with customer and lines", + "action": "query", + "schema_id": "full.order", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", + " 'archived', entity_2.archived,", + " 'created_at', entity_2.created_at,", + " 'customer',", + " (SELECT jsonb_build_object(", + " 'age', person_3.age,", + " 'archived', entity_5.archived,", + " 'created_at', entity_5.created_at,", + " 'first_name', person_3.first_name,", + " 'id', entity_5.id,", + " 'last_name', person_3.last_name,", + " 'name', organization_4.name,", + " 'type', entity_5.type", + " )", + " FROM agreego.person person_3", + " JOIN agreego.organization organization_4 ON organization_4.id = person_3.id", + " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", + " WHERE", + " NOT entity_5.archived", + " AND order_1.customer_id = person_3.id),", + " 'customer_id', order_1.customer_id,", + " 'id', entity_2.id,", + " 'lines',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_7.archived,", + " 'created_at', entity_7.created_at,", + " 'id', entity_7.id,", + " 'order_id', order_line_6.order_id,", + " 'price', order_line_6.price,", + " 'product', order_line_6.product,", + " 'type', entity_7.type", + " )), '[]'::jsonb)", + " FROM agreego.order_line order_line_6", + " JOIN agreego.entity entity_7 ON entity_7.id = order_line_6.id", + " WHERE", + " NOT entity_7.archived", + " AND order_line_6.order_id = order_1.id),", + " 'total', order_1.total,", + " 'type', entity_2.type", + ")", + "FROM agreego.order order_1", + "JOIN agreego.entity entity_2 ON entity_2.id = order_1.id", + "WHERE NOT entity_2.archived)))" + ] + ] + } + }, + { + "description": "Organization select via a punc response with ref", + "action": "query", + "schema_id": "get_organization.response", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", + " 'archived', entity_2.archived,", + " 'created_at', entity_2.created_at,", + " 'id', entity_2.id,", + " 'name', organization_1.name,", + " 'type', entity_2.type", + ")", + "FROM agreego.organization organization_1", + "JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", + "WHERE NOT entity_2.archived)))" + ] + ] + } + }, + { + "description": "Organizations select via a punc response with family", + "action": "query", + "schema_id": "get_organizations.response", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT COALESCE(jsonb_agg(", + " CASE", + " WHEN organization_1.type = 'bot' THEN (", + " (SELECT jsonb_build_object(", + " 'archived', entity_5.archived,", + " 'created_at', entity_5.created_at,", + " 'id', entity_5.id,", + " 'name', organization_4.name,", + " 'role', bot_3.role,", + " 'token', bot_3.token,", + " 'type', entity_5.type", + " )", + " FROM agreego.bot bot_3", + " JOIN agreego.organization organization_4 ON organization_4.id = bot_3.id", + " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", + " WHERE", + " NOT entity_5.archived", + " AND entity_5.id = entity_2.id)", + " )", + " WHEN organization_1.type = 'organization' THEN (", + " (SELECT jsonb_build_object(", + " 'archived', entity_7.archived,", + " 'created_at', entity_7.created_at,", + " 'id', entity_7.id,", + " 'name', organization_6.name,", + " 'type', entity_7.type", + " )", + " FROM agreego.organization organization_6", + " JOIN agreego.entity entity_7 ON entity_7.id = organization_6.id", + " WHERE", + " NOT entity_7.archived", + " AND entity_7.id = entity_2.id)", + " )", + " WHEN organization_1.type = 'person' THEN (", + " (SELECT jsonb_build_object(", + " 'age', person_8.age,", + " 'archived', entity_10.archived,", + " 'created_at', entity_10.created_at,", + " 'first_name', person_8.first_name,", + " 'id', entity_10.id,", + " 'last_name', person_8.last_name,", + " 'name', organization_9.name,", + " 'type', entity_10.type", + " )", + " FROM agreego.person person_8", + " JOIN agreego.organization organization_9 ON organization_9.id = person_8.id", + " JOIN agreego.entity entity_10 ON entity_10.id = organization_9.id", + " WHERE", + " NOT entity_10.archived", + " AND entity_10.id = entity_2.id)", + " )", + " ELSE NULL", + " END", + "), '[]'::jsonb)", + "FROM agreego.organization organization_1", + "JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", + "WHERE NOT entity_2.archived)))" + ] + ] + } + }, + { + "description": "Light organizations select via a punc response with family", + "action": "query", + "schema_id": "get_light_organization.response", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT ", + " CASE", + " WHEN organization_1.type = 'bot' THEN (", + " (SELECT jsonb_build_object(", + " 'archived', entity_5.archived,", + " 'created_at', entity_5.created_at,", + " 'id', entity_5.id,", + " 'name', organization_4.name,", + " 'token', bot_3.token,", + " 'type', entity_5.type", + " )", + " FROM agreego.bot bot_3", + " JOIN agreego.organization organization_4 ON organization_4.id = bot_3.id", + " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", + " WHERE NOT entity_5.archived AND entity_5.id = entity_2.id)", + " )", + " WHEN organization_1.type = 'person' THEN (", + " (SELECT jsonb_build_object(", + " 'archived', entity_8.archived,", + " 'created_at', entity_8.created_at,", + " 'first_name', person_6.first_name,", + " 'id', entity_8.id,", + " 'last_name', person_6.last_name,", + " 'name', organization_7.name,", + " 'type', entity_8.type", + " )", + " FROM agreego.person person_6", + " JOIN agreego.organization organization_7 ON organization_7.id = person_6.id", + " JOIN agreego.entity entity_8 ON entity_8.id = organization_7.id", + " WHERE NOT entity_8.archived AND entity_8.id = entity_2.id)", + " )", + " ELSE NULL", + " END", + "FROM agreego.organization organization_1", + "JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", + "WHERE NOT entity_2.archived)))" + ] + ] + } + }, + { + "description": "Full organizations select via a punc response with family", + "action": "query", + "schema_id": "get_full_organization.response", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT CASE", + " WHEN organization_1.type = 'person' THEN (", + " (SELECT jsonb_build_object(", + " 'addresses',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_8.archived,", + " 'created_at', entity_8.created_at,", + " 'id', entity_8.id,", + " 'is_primary', contact_6.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'archived', entity_10.archived,", + " 'city', address_9.city,", + " 'created_at', entity_10.created_at,", + " 'id', entity_10.id,", + " 'type', entity_10.type", + " )", + " FROM agreego.address address_9", + " JOIN agreego.entity entity_10 ON entity_10.id = address_9.id", + " WHERE", + " NOT entity_10.archived", + " AND relationship_7.target_id = entity_10.id),", + " 'type', entity_8.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_6", + " JOIN agreego.relationship relationship_7 ON relationship_7.id = contact_6.id", + " JOIN agreego.entity entity_8 ON entity_8.id = relationship_7.id", + " WHERE", + " NOT entity_8.archived", + " AND relationship_7.target_type = 'address'", + " AND relationship_7.source_id = entity_5.id),", + " 'age', person_3.age,", + " 'archived', entity_5.archived,", + " 'contacts',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_13.archived,", + " 'created_at', entity_13.created_at,", + " 'id', entity_13.id,", + " 'is_primary', contact_11.is_primary,", + " 'target',", + " CASE", + " WHEN entity_13.target_type = 'address' THEN (", + " (SELECT jsonb_build_object(", + " 'archived', entity_15.archived,", + " 'city', address_14.city,", + " 'created_at', entity_15.created_at,", + " 'id', entity_15.id,", + " 'type', entity_15.type", + " )", + " FROM agreego.address address_14", + " JOIN agreego.entity entity_15 ON entity_15.id = address_14.id", + " WHERE", + " NOT entity_15.archived", + " AND relationship_12.target_id = entity_15.id)", + " )", + " WHEN entity_13.target_type = 'email_address' THEN (", + " (SELECT jsonb_build_object(", + " 'address', email_address_16.address,", + " 'archived', entity_17.archived,", + " 'created_at', entity_17.created_at,", + " 'id', entity_17.id,", + " 'type', entity_17.type", + " )", + " FROM agreego.email_address email_address_16", + " JOIN agreego.entity entity_17 ON entity_17.id = email_address_16.id", + " WHERE", + " NOT entity_17.archived", + " AND relationship_12.target_id = entity_17.id)", + " )", + " WHEN entity_13.target_type = 'phone_number' THEN (", + " (SELECT jsonb_build_object(", + " 'archived', entity_19.archived,", + " 'created_at', entity_19.created_at,", + " 'id', entity_19.id,", + " 'number', phone_number_18.number,", + " 'type', entity_19.type", + " )", + " FROM agreego.phone_number phone_number_18", + " JOIN agreego.entity entity_19 ON entity_19.id = phone_number_18.id", + " WHERE", + " NOT entity_19.archived", + " AND relationship_12.target_id = entity_19.id)", + " )", + " ELSE NULL", + " END,", + " 'type', entity_13.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_11", + " JOIN agreego.relationship relationship_12 ON relationship_12.id = contact_11.id", + " JOIN agreego.entity entity_13 ON entity_13.id = relationship_12.id", + " WHERE", + " NOT entity_13.archived", + " AND relationship_12.source_id = entity_5.id),", + " 'created_at', entity_5.created_at,", + " 'email_addresses',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_22.archived,", + " 'created_at', entity_22.created_at,", + " 'id', entity_22.id,", + " 'is_primary', contact_20.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'address', email_address_23.address,", + " 'archived', entity_24.archived,", + " 'created_at', entity_24.created_at,", + " 'id', entity_24.id,", + " 'type', entity_24.type", + " )", + " FROM agreego.email_address email_address_23", + " JOIN agreego.entity entity_24 ON entity_24.id = email_address_23.id", + " WHERE", + " NOT entity_24.archived", + " AND relationship_21.target_id = entity_24.id),", + " 'type', entity_22.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_20", + " JOIN agreego.relationship relationship_21 ON relationship_21.id = contact_20.id", + " JOIN agreego.entity entity_22 ON entity_22.id = relationship_21.id", + " WHERE", + " NOT entity_22.archived", + " AND relationship_21.target_type = 'email_address'", + " AND relationship_21.source_id = entity_5.id),", + " 'first_name', person_3.first_name,", + " 'id', entity_5.id,", + " 'last_name', person_3.last_name,", + " 'name', organization_4.name,", + " 'phone_numbers',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_27.archived,", + " 'created_at', entity_27.created_at,", + " 'id', entity_27.id,", + " 'is_primary', contact_25.is_primary,", + " 'target',", + " (SELECT jsonb_build_object(", + " 'archived', entity_29.archived,", + " 'created_at', entity_29.created_at,", + " 'id', entity_29.id,", + " 'number', phone_number_28.number,", + " 'type', entity_29.type", + " )", + " FROM agreego.phone_number phone_number_28", + " JOIN agreego.entity entity_29 ON entity_29.id = phone_number_28.id", + " WHERE", + " NOT entity_29.archived", + " AND relationship_26.target_id = entity_29.id),", + " 'type', entity_27.type", + " )), '[]'::jsonb)", + " FROM agreego.contact contact_25", + " JOIN agreego.relationship relationship_26 ON relationship_26.id = contact_25.id", + " JOIN agreego.entity entity_27 ON entity_27.id = relationship_26.id", + " WHERE", + " NOT entity_27.archived", + " AND relationship_26.target_type = 'phone_number'", + " AND relationship_26.source_id = entity_5.id),", + " 'type', entity_5.type", + " )", + " FROM agreego.person person_3", + " JOIN agreego.organization organization_4 ON organization_4.id = person_3.id", + " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", + " WHERE NOT entity_5.archived AND entity_5.id = entity_2.id))", + " ELSE NULL", + "END", + "FROM agreego.organization organization_1", + "JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", + "WHERE NOT entity_2.archived)))" + ] + ] + } + }, + { + "description": "Orders select via a punc with items", + "action": "query", + "schema_id": "get_orders.response", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_2.archived,", + " 'created_at', entity_2.created_at,", + " 'customer',", + " (SELECT jsonb_build_object(", + " 'age', person_3.age,", + " 'archived', entity_5.archived,", + " 'created_at', entity_5.created_at,", + " 'first_name', person_3.first_name,", + " 'id', entity_5.id,", + " 'last_name', person_3.last_name,", + " 'name', organization_4.name,", + " 'type', entity_5.type", + " )", + " FROM agreego.person person_3", + " JOIN agreego.organization organization_4 ON organization_4.id = person_3.id", + " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", + " WHERE", + " NOT entity_5.archived", + " AND order_1.customer_id = person_3.id),", + " 'customer_id', order_1.customer_id,", + " 'id', entity_2.id,", + " 'total', order_1.total,", + " 'type', entity_2.type", + ")), '[]'::jsonb)", + "FROM agreego.order order_1", + "JOIN agreego.entity entity_2 ON entity_2.id = order_1.id", + "WHERE NOT entity_2.archived)))" + ] + ] + } + }, + { + "description": "Widgets select via a punc response with family (STI)", + "action": "query", + "schema_id": "get_widgets.response", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT COALESCE(jsonb_agg(", + " CASE", + " WHEN widget_1.kind = 'stock' THEN (", + " jsonb_build_object(", + " 'archived', entity_2.archived,", + " 'created_at', entity_2.created_at,", + " 'id', entity_2.id,", + " 'kind', widget_1.kind,", + " 'type', entity_2.type", + " )", + " )", + " WHEN widget_1.kind = 'tasks' THEN (", + " jsonb_build_object(", + " 'archived', entity_2.archived,", + " 'created_at', entity_2.created_at,", + " 'id', entity_2.id,", + " 'kind', widget_1.kind,", + " 'type', entity_2.type", + " )", + " )", + " ELSE NULL", + " END", + "), '[]'::jsonb)", + "FROM agreego.widget widget_1", + "JOIN agreego.entity entity_2 ON entity_2.id = widget_1.id", + "WHERE NOT entity_2.archived)))" + ] + ] + } + }, + { + "description": "Query invoice with JSONB metadata fields", + "action": "query", + "schema_id": "invoice", + "expect": { + "success": true, + "sql": [ + [ + "(SELECT jsonb_strip_nulls((SELECT jsonb_build_object(", + " 'archived', entity_2.archived,", + " 'created_at', entity_2.created_at,", + " 'id', entity_2.id,", + " 'lines',", + " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", + " 'archived', entity_4.archived,", + " 'created_at', entity_4.created_at,", + " 'id', entity_4.id,", + " 'invoice_id', invoice_line_3.invoice_id,", + " 'price', invoice_line_3.price,", + " 'type', entity_4.type", + " )), '[]'::jsonb)", + " FROM agreego.invoice_line invoice_line_3", + " JOIN agreego.entity entity_4 ON entity_4.id = invoice_line_3.id", + " WHERE", + " NOT entity_4.archived", + " AND invoice_line_3.invoice_id = invoice_1.id),", + " 'metadata_line', invoice_1.metadata_line,", + " 'metadata_lines', invoice_1.metadata_lines,", + " 'metadata_nested_line', invoice_1.metadata_nested_line,", + " 'metadata_nested_lines', invoice_1.metadata_nested_lines,", + " 'total', invoice_1.total,", + " 'type', entity_2.type", + ")", + "FROM agreego.invoice invoice_1", + "JOIN agreego.entity entity_2 ON entity_2.id = invoice_1.id", + "WHERE NOT entity_2.archived)))" + ] + ] + } + } + ] + } ] \ No newline at end of file diff --git a/src/database/mod.rs b/src/database/mod.rs index e32ed6c..19e7a3a 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -2,9 +2,9 @@ pub mod edge; pub mod r#enum; pub mod executors; pub mod formats; +pub mod object; pub mod page; pub mod punc; -pub mod object; pub mod relation; pub mod schema; pub mod r#type; @@ -60,7 +60,10 @@ impl Database { db.enums.insert(def.name.clone(), def); } Err(e) => { - let name = item.get("name").and_then(|v| v.as_str()).unwrap_or("unknown"); + let name = item + .get("name") + .and_then(|v| v.as_str()) + .unwrap_or("unknown"); errors.push(crate::drop::Error { code: "DATABASE_ENUM_PARSE_FAILED".to_string(), message: format!("Failed to parse database enum '{}': {}", name, e), @@ -81,7 +84,10 @@ impl Database { db.types.insert(def.name.clone(), def); } Err(e) => { - let name = item.get("name").and_then(|v| v.as_str()).unwrap_or("unknown"); + let name = item + .get("name") + .and_then(|v| v.as_str()) + .unwrap_or("unknown"); errors.push(crate::drop::Error { code: "DATABASE_TYPE_PARSE_FAILED".to_string(), message: format!("Failed to parse database type '{}': {}", name, e), @@ -106,7 +112,10 @@ impl Database { } } Err(e) => { - let constraint = item.get("constraint").and_then(|v| v.as_str()).unwrap_or("unknown"); + let constraint = item + .get("constraint") + .and_then(|v| v.as_str()) + .unwrap_or("unknown"); errors.push(crate::drop::Error { code: "DATABASE_RELATION_PARSE_FAILED".to_string(), message: format!("Failed to parse database relation '{}': {}", constraint, e), @@ -127,7 +136,10 @@ impl Database { db.puncs.insert(def.name.clone(), def); } Err(e) => { - let name = item.get("name").and_then(|v| v.as_str()).unwrap_or("unknown"); + let name = item + .get("name") + .and_then(|v| v.as_str()) + .unwrap_or("unknown"); errors.push(crate::drop::Error { code: "DATABASE_PUNC_PARSE_FAILED".to_string(), message: format!("Failed to parse database punc '{}': {}", name, e), @@ -199,7 +211,13 @@ impl Database { pub fn compile(&mut self, errors: &mut Vec) { let mut harvested = Vec::new(); for (id, schema_arc) in &self.schemas { - crate::database::schema::Schema::collect_schemas(schema_arc, id, id.clone(), &mut harvested, errors); + crate::database::schema::Schema::collect_schemas( + schema_arc, + id, + id.clone(), + &mut harvested, + errors, + ); } for (id, schema_arc) in harvested { self.schemas.insert(id, schema_arc); @@ -208,11 +226,12 @@ impl Database { self.collect_schemas(errors); // Mathematically evaluate all property inheritances, formats, schemas, and foreign key edges topographically over OnceLocks - let mut visited = std::collections::HashSet::new(); for (id, schema_arc) in &self.schemas { // First compile pass initializes exact structural root_id mapping to resolve DB constraints let root_id = id.split('/').next().unwrap_or(id); - schema_arc.as_ref().compile(self, root_id, id.clone(), &mut visited, errors); + schema_arc + .as_ref() + .compile(self, root_id, id.clone(), errors); } } @@ -224,19 +243,37 @@ impl Database { for type_def in self.types.values() { for (id, schema_arc) in &type_def.schemas { to_insert.push((id.clone(), Arc::clone(schema_arc))); - crate::database::schema::Schema::collect_schemas(schema_arc, id, id.clone(), &mut to_insert, errors); + crate::database::schema::Schema::collect_schemas( + schema_arc, + id, + id.clone(), + &mut to_insert, + errors, + ); } } for punc_def in self.puncs.values() { for (id, schema_arc) in &punc_def.schemas { to_insert.push((id.clone(), Arc::clone(schema_arc))); - crate::database::schema::Schema::collect_schemas(schema_arc, id, id.clone(), &mut to_insert, errors); + crate::database::schema::Schema::collect_schemas( + schema_arc, + id, + id.clone(), + &mut to_insert, + errors, + ); } } for enum_def in self.enums.values() { for (id, schema_arc) in &enum_def.schemas { to_insert.push((id.clone(), Arc::clone(schema_arc))); - crate::database::schema::Schema::collect_schemas(schema_arc, id, id.clone(), &mut to_insert, errors); + crate::database::schema::Schema::collect_schemas( + schema_arc, + id, + id.clone(), + &mut to_insert, + errors, + ); } } @@ -276,10 +313,10 @@ impl Database { all_rels.sort_by(|a, b| a.constraint.cmp(&b.constraint)); for rel in all_rels { - let mut is_forward = - p_def.hierarchy.contains(&rel.source_type) && c_def.hierarchy.contains(&rel.destination_type); - let is_reverse = - p_def.hierarchy.contains(&rel.destination_type) && c_def.hierarchy.contains(&rel.source_type); + let mut is_forward = p_def.hierarchy.contains(&rel.source_type) + && c_def.hierarchy.contains(&rel.destination_type); + let is_reverse = p_def.hierarchy.contains(&rel.destination_type) + && c_def.hierarchy.contains(&rel.source_type); // Structural Cardinality Filtration: // If the schema requires a collection (Array), it is mathematically impossible for a pure diff --git a/src/database/schema.rs b/src/database/schema.rs index 7ad9285..93cd33e 100644 --- a/src/database/schema.rs +++ b/src/database/schema.rs @@ -28,21 +28,12 @@ impl Schema { db: &crate::database::Database, root_id: &str, path: String, - visited: &mut std::collections::HashSet, errors: &mut Vec, ) { if self.obj.compiled_properties.get().is_some() { return; } - if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &self.obj.type_ { - if !crate::database::object::is_primitive_type(t) { - if !visited.insert(t.clone()) { - return; // Break cyclical resolution - } - } - } - if let Some(format_str) = &self.obj.format { if let Some(fmt) = crate::database::formats::FORMATS.get(format_str.as_str()) { let _ = self @@ -79,7 +70,7 @@ impl Schema { if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &self.obj.type_ { if !crate::database::object::is_primitive_type(t) { if let Some(parent) = db.schemas.get(t) { - parent.as_ref().compile(db, t, t.clone(), visited, errors); + parent.as_ref().compile(db, t, t.clone(), errors); if let Some(p_props) = parent.obj.compiled_properties.get() { props.extend(p_props.clone()); } @@ -113,7 +104,7 @@ impl Schema { for t in types { if !crate::database::object::is_primitive_type(t) { if let Some(parent) = db.schemas.get(t) { - parent.as_ref().compile(db, t, t.clone(), visited, errors); + parent.as_ref().compile(db, t, t.clone(), errors); } } } @@ -133,21 +124,21 @@ impl Schema { let _ = self.obj.compiled_property_names.set(names); // 4. Compute Edges natively - let schema_edges = self.compile_edges(db, root_id, &path, visited, &props, errors); + let schema_edges = self.compile_edges(db, root_id, &path, &props, errors); let _ = self.obj.compiled_edges.set(schema_edges); // 5. Build our inline children properties recursively NOW! (Depth-first search) if let Some(local_props) = &self.obj.properties { for (k, child) in local_props { - child.compile(db, root_id, format!("{}/{}", path, k), visited, errors); + child.compile(db, root_id, format!("{}/{}", path, k), errors); } } if let Some(items) = &self.obj.items { - items.compile(db, root_id, format!("{}/items", path), visited, errors); + items.compile(db, root_id, format!("{}/items", path), errors); } if let Some(pattern_props) = &self.obj.pattern_properties { for (k, child) in pattern_props { - child.compile(db, root_id, format!("{}/{}", path, k), visited, errors); + child.compile(db, root_id, format!("{}/{}", path, k), errors); } } if let Some(additional_props) = &self.obj.additional_properties { @@ -155,7 +146,6 @@ impl Schema { db, root_id, format!("{}/additionalProperties", path), - visited, errors, ); } @@ -165,7 +155,6 @@ impl Schema { db, root_id, format!("{}/oneOf/{}", path, i), - visited, errors, ); } @@ -176,16 +165,15 @@ impl Schema { db, root_id, format!("{}/prefixItems/{}", path, i), - visited, errors, ); } } if let Some(child) = &self.obj.not { - child.compile(db, root_id, format!("{}/not", path), visited, errors); + child.compile(db, root_id, format!("{}/not", path), errors); } if let Some(child) = &self.obj.contains { - child.compile(db, root_id, format!("{}/contains", path), visited, errors); + child.compile(db, root_id, format!("{}/contains", path), errors); } if let Some(cases) = &self.obj.cases { for (i, c) in cases.iter().enumerate() { @@ -194,7 +182,6 @@ impl Schema { db, root_id, format!("{}/cases/{}/when", path, i), - visited, errors, ); } @@ -203,7 +190,6 @@ impl Schema { db, root_id, format!("{}/cases/{}/then", path, i), - visited, errors, ); } @@ -212,7 +198,6 @@ impl Schema { db, root_id, format!("{}/cases/{}/else", path, i), - visited, errors, ); } @@ -220,12 +205,6 @@ impl Schema { } self.compile_polymorphism(db, root_id, &path, errors); - - if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &self.obj.type_ { - if !crate::database::object::is_primitive_type(t) { - visited.remove(t); - } - } } /// Dynamically infers and compiles all structural database relationships between this Schema @@ -237,7 +216,6 @@ impl Schema { db: &crate::database::Database, root_id: &str, path: &str, - visited: &mut std::collections::HashSet, props: &std::collections::BTreeMap>, errors: &mut Vec, ) -> std::collections::BTreeMap { @@ -263,31 +241,11 @@ impl Schema { } } - if parent_type_name.is_none() { - // 3. Absolute fallback for anonymous inline structures - let base_type_name = root_id - .split('.') - .next_back() - .unwrap_or(root_id) - .to_string(); - if db.types.contains_key(&base_type_name) { - parent_type_name = Some(base_type_name); - } - } - if let Some(p_type) = parent_type_name { // Proceed only if the resolved table physically exists within the Postgres Type hierarchy if let Some(type_def) = db.types.get(&p_type) { // Iterate over all discovered schema boundaries mapped inside the object for (prop_name, prop_schema) in props { - if let Some(field_types_map) = type_def.field_types.as_ref().and_then(|v| v.as_object()) { - if let Some(pg_type) = field_types_map.get(prop_name).and_then(|v| v.as_str()) { - if pg_type == "json" || pg_type == "jsonb" { - continue; - } - } - } - let mut child_type_name = None; let mut target_schema = prop_schema.clone(); let mut is_array = false; @@ -325,6 +283,16 @@ impl Schema { } if let Some(c_type) = child_type_name { + // Skip edge compilation for JSONB columns — they store data inline, not relationally. + // The physical column type from field_types is the single source of truth. + if let Some(ft) = type_def.field_types.as_ref() + .and_then(|v| v.get(prop_name.as_str())) + .and_then(|v| v.as_str()) + { + if ft == "jsonb" { + continue; + } + } if db.types.contains_key(&c_type) { // Ensure the child Schema's AST has accurately compiled its own physical property keys so we can // inject them securely for Many-to-Many Twin Deduction disambiguation matching. @@ -332,9 +300,9 @@ impl Schema { db, root_id, format!("{}/{}", path, prop_name), - visited, errors, ); + if let Some(compiled_target_props) = target_schema.obj.compiled_properties.get() { let keys_for_ambiguity: Vec = compiled_target_props.keys().cloned().collect(); diff --git a/src/queryer/compiler.rs b/src/queryer/compiler.rs index 0473257..6bfeb0e 100644 --- a/src/queryer/compiler.rs +++ b/src/queryer/compiler.rs @@ -347,22 +347,23 @@ impl<'a> Compiler<'a> { child_node.schema = Arc::clone(target_schema); child_node.is_polymorphic_branch = true; - let val_sql = if disc == "kind" && node.parent_type.is_some() && node.parent_type_aliases.is_some() { + let val_sql = + if disc == "kind" && node.parent_type.is_some() && node.parent_type_aliases.is_some() { let aliases_arc = node.parent_type_aliases.as_ref().unwrap(); let aliases = aliases_arc.as_ref(); let p_type = node.parent_type.unwrap(); - + let select_args = self.compile_select_clause(p_type, aliases, child_node.clone())?; - + if select_args.is_empty() { - "jsonb_build_object()".to_string() + "jsonb_build_object()".to_string() } else { - format!("jsonb_build_object({})", select_args.join(", ")) + format!("jsonb_build_object({})", select_args.join(", ")) } - } else { + } else { let (sql, _) = self.compile_node(child_node)?; sql - }; + }; case_statements.push(format!( "WHEN {}.{} = '{}' THEN ({})", diff --git a/src/tests/fixtures.rs b/src/tests/fixtures.rs index 8d3371d..57c65e3 100644 --- a/src/tests/fixtures.rs +++ b/src/tests/fixtures.rs @@ -3695,6 +3695,12 @@ fn test_database_5_0() { crate::tests::runner::run_test_case(&path, 5, 0).unwrap(); } +#[test] +fn test_database_6_0() { + let path = format!("{}/fixtures/database.json", env!("CARGO_MANIFEST_DIR")); + crate::tests::runner::run_test_case(&path, 6, 0).unwrap(); +} + #[test] fn test_cases_0_0() { let path = format!("{}/fixtures/cases.json", env!("CARGO_MANIFEST_DIR"));