diff --git a/fixtures/database.json b/fixtures/database.json index 823f6d3..e1c5201 100644 --- a/fixtures/database.json +++ b/fixtures/database.json @@ -791,8 +791,8 @@ } }, "hierarchy": [ - "invoice", - "entity" + "entity", + "invoice" ], "fields": [ "id", @@ -867,8 +867,8 @@ } }, "hierarchy": [ - "invoice_line", - "entity" + "entity", + "invoice_line" ], "fields": [ "id", diff --git a/fixtures/invoice.json b/fixtures/invoice.json index 865458d..3ae8123 100644 --- a/fixtures/invoice.json +++ b/fixtures/invoice.json @@ -110,8 +110,8 @@ } }, "hierarchy": [ - "activity", - "entity" + "entity", + "activity" ], "variations": [ "activity", @@ -166,9 +166,9 @@ } }, "hierarchy": [ - "invoice", + "entity", "activity", - "entity" + "invoice" ], "variations": [ "invoice" @@ -237,8 +237,8 @@ } }, "hierarchy": [ - "attachment", - "entity" + "entity", + "attachment" ], "variations": [ "attachment" diff --git a/fixtures/merger.json b/fixtures/merger.json index f60ddea..3608978 100644 --- a/fixtures/merger.json +++ b/fixtures/merger.json @@ -219,8 +219,8 @@ } }, "hierarchy": [ - "organization", - "entity" + "entity", + "organization" ], "fields": [ "id", @@ -262,9 +262,9 @@ } }, "hierarchy": [ - "user", + "entity", "organization", - "entity" + "user" ], "fields": [ "id", @@ -359,10 +359,10 @@ } }, "hierarchy": [ - "person", - "user", + "entity", "organization", - "entity" + "user", + "person" ], "fields": [ "id", @@ -445,8 +445,8 @@ } }, "hierarchy": [ - "order", - "entity" + "entity", + "order" ], "fields": [ "id", @@ -504,8 +504,8 @@ } }, "hierarchy": [ - "order_line", - "entity" + "entity", + "order_line" ], "fields": [ "id", @@ -548,8 +548,8 @@ "name": "relationship", "relationship": true, "hierarchy": [ - "relationship", - "entity" + "entity", + "relationship" ], "fields": [ "source_id", @@ -611,9 +611,9 @@ "name": "contact", "relationship": true, "hierarchy": [ - "contact", + "entity", "relationship", - "entity" + "contact" ], "fields": [ "is_primary", @@ -683,8 +683,8 @@ { "name": "phone_number", "hierarchy": [ - "phone_number", - "entity" + "entity", + "phone_number" ], "fields": [ "number", @@ -741,8 +741,8 @@ { "name": "email_address", "hierarchy": [ - "email_address", - "entity" + "entity", + "email_address" ], "fields": [ "address", @@ -834,8 +834,8 @@ } }, "hierarchy": [ - "attachment", - "entity" + "entity", + "attachment" ], "fields": [ "id", @@ -887,8 +887,8 @@ { "name": "account", "hierarchy": [ - "account", - "entity" + "entity", + "account" ], "fields": [ "id", @@ -1031,8 +1031,8 @@ } }, "hierarchy": [ - "invoice", - "entity" + "entity", + "invoice" ], "fields": [ "id", @@ -1107,8 +1107,8 @@ } }, "hierarchy": [ - "invoice_line", - "entity" + "entity", + "invoice_line" ], "fields": [ "id", @@ -1309,10 +1309,10 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)", - "FROM agreego.\"person\" t1", - "JOIN agreego.\"user\" t2 ON ", - "JOIN agreego.\"organization\" t3 ON ", - "JOIN agreego.\"entity\" t4 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"organization\" t2 ON ", + "JOIN agreego.\"user\" t3 ON ", + "JOIN agreego.\"person\" t4 ON ", "WHERE", " (\"first_name\" = 'LookupFirst'", " AND \"last_name\" = 'LookupLast'", @@ -1320,17 +1320,62 @@ " AND \"pronouns\" = 'they/them'))" ], [ - "UPDATE agreego.\"person\" SET", - " contact_id = 'abc-contact'", - "WHERE", - " id = '{{uuid:mocks.0.id}}'" + "INSERT INTO agreego.\"entity\" (", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", + ")", + "VALUES (", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:generated_0}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'person'", + ")" ], [ - "UPDATE agreego.\"entity\" SET", - " modified_at = '{{timestamp}}',", - " modified_by = '00000000-0000-0000-0000-000000000000'", - "WHERE", - " id = '{{uuid:mocks.0.id}}'" + "INSERT INTO agreego.\"organization\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " '{{uuid:generated_0}}',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"user\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " '{{uuid:generated_0}}',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"person\" (", + " \"contact_id\",", + " \"date_of_birth\",", + " \"first_name\",", + " \"id\",", + " \"last_name\",", + " \"pronouns\",", + " \"type\"", + ")", + "VALUES (", + " 'abc-contact',", + " '{{timestamp}}',", + " 'LookupFirst',", + " '{{uuid:generated_0}}',", + " 'LookupLast',", + " 'they/them',", + " 'person'", + ")" ], [ "INSERT INTO agreego.change (", @@ -1343,40 +1388,45 @@ " \"modified_by\"", ")", "VALUES (", + " NULL,", " '{", - " \"contact_id\": \"old-contact\"", - " }',", - " '{", + " \"first_name\": \"LookupFirst\",", + " \"last_name\": \"LookupLast\",", + " \"date_of_birth\": \"{{timestamp}}\",", + " \"pronouns\": \"they/them\",", " \"contact_id\": \"abc-contact\",", " \"type\": \"person\"", " }',", - " '{{uuid:mocks.0.id}}',", " '{{uuid:generated_0}}',", - " 'update',", + " '{{uuid:generated_1}}',", + " 'create',", " '{{timestamp}}',", " '00000000-0000-0000-0000-000000000000'", ")" ], [ "(SELECT pg_notify('entity', '{", - " \"kind\": \"update\",", + " \"kind\": \"create\",", " \"complete\": {", - " \"id\": \"{{uuid:mocks.0.id}}\",", - " \"type\": \"person\",", " \"first_name\": \"LookupFirst\",", " \"last_name\": \"LookupLast\",", " \"date_of_birth\": \"{{timestamp}}\",", " \"pronouns\": \"they/them\",", " \"contact_id\": \"abc-contact\",", + " \"id\": \"{{uuid:generated_0}}\",", + " \"type\": \"person\",", + " \"created_by\": \"00000000-0000-0000-0000-000000000000\",", + " \"created_at\": \"{{timestamp}}\",", " \"modified_by\": \"00000000-0000-0000-0000-000000000000\",", " \"modified_at\": \"{{timestamp}}\"", " },", " \"new\": {", + " \"first_name\": \"LookupFirst\",", + " \"last_name\": \"LookupLast\",", + " \"date_of_birth\": \"{{timestamp}}\",", + " \"pronouns\": \"they/them\",", " \"contact_id\": \"abc-contact\",", " \"type\": \"person\"", - " },", - " \"old\": {", - " \"contact_id\": \"old-contact\"", " }", "}'))" ] @@ -1412,10 +1462,10 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)", - "FROM agreego.\"person\" t1", - "JOIN agreego.\"user\" t2 ON ", - "JOIN agreego.\"organization\" t3 ON ", - "JOIN agreego.\"entity\" t4 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"organization\" t2 ON ", + "JOIN agreego.\"user\" t3 ON ", + "JOIN agreego.\"person\" t4 ON ", "WHERE", " t1.id = '{{uuid:data.id}}'", " OR (\"first_name\" = 'LookupFirst'", @@ -1424,17 +1474,62 @@ " AND \"pronouns\" = 'they/them'))" ], [ - "UPDATE agreego.\"person\" SET", - " contact_id = 'abc-contact'", - "WHERE", - " id = '{{uuid:mocks.0.id}}'" + "INSERT INTO agreego.\"entity\" (", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", + ")", + "VALUES (", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:data.id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'person'", + ")" ], [ - "UPDATE agreego.\"entity\" SET", - " modified_at = '{{timestamp}}',", - " modified_by = '00000000-0000-0000-0000-000000000000'", - "WHERE", - " id = '{{uuid:mocks.0.id}}'" + "INSERT INTO agreego.\"organization\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " '{{uuid:data.id}}',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"user\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " '{{uuid:data.id}}',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"person\" (", + " \"contact_id\",", + " \"date_of_birth\",", + " \"first_name\",", + " \"id\",", + " \"last_name\",", + " \"pronouns\",", + " \"type\"", + ")", + "VALUES (", + " 'abc-contact',", + " '{{timestamp}}',", + " 'LookupFirst',", + " '{{uuid:data.id}}',", + " 'LookupLast',", + " 'they/them',", + " 'person'", + ")" ], [ "INSERT INTO agreego.change (", @@ -1447,42 +1542,46 @@ " \"modified_by\"", ")", "VALUES (", + " NULL,", " '{", - " \"contact_id\": \"old-contact\"", - " }',", - " '{", + " \"first_name\": \"LookupFirst\",", + " \"last_name\": \"LookupLast\",", + " \"date_of_birth\": \"{{timestamp}}\",", + " \"pronouns\": \"they/them\",", " \"contact_id\": \"abc-contact\",", " \"type\": \"person\"", " }',", - " '{{uuid:mocks.0.id}}',", + " '{{uuid:data.id}}',", " '{{uuid:generated_0}}',", - " 'update',", + " 'create',", " '{{timestamp}}',", " '00000000-0000-0000-0000-000000000000'", ")" ], [ "(SELECT pg_notify('entity', '{", - " \"kind\": \"update\",", + " \"kind\": \"create\",", " \"complete\": {", - " \"id\": \"{{uuid:mocks.0.id}}\",", - " \"type\": \"person\",", " \"first_name\": \"LookupFirst\",", " \"last_name\": \"LookupLast\",", " \"date_of_birth\": \"{{timestamp}}\",", " \"pronouns\": \"they/them\",", " \"contact_id\": \"abc-contact\",", + " \"id\": \"{{uuid:data.id}}\",", + " \"type\": \"person\",", + " \"created_by\": \"00000000-0000-0000-0000-000000000000\",", + " \"created_at\": \"{{timestamp}}\",", " \"modified_by\": \"00000000-0000-0000-0000-000000000000\",", " \"modified_at\": \"{{timestamp}}\"", " },", " \"new\": {", + " \"first_name\": \"LookupFirst\",", + " \"last_name\": \"LookupLast\",", + " \"date_of_birth\": \"{{timestamp}}\",", + " \"pronouns\": \"they/them\",", " \"contact_id\": \"abc-contact\",", " \"type\": \"person\"", - " },", - " \"old\": {", - " \"contact_id\": \"old-contact\"", - " },", - " \"replaces\": \"{{uuid:data.id}}\"", + " }", "}'))" ] ] @@ -1516,10 +1615,10 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)", - "FROM agreego.\"person\" t1", - "JOIN agreego.\"user\" t2 ON ", - "JOIN agreego.\"organization\" t3 ON ", - "JOIN agreego.\"entity\" t4 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"organization\" t2 ON ", + "JOIN agreego.\"user\" t3 ON ", + "JOIN agreego.\"person\" t4 ON ", "WHERE", " t1.id = '{{uuid:data.id}}'", " OR (\"first_name\" = 'LookupFirst'", @@ -1528,23 +1627,109 @@ " AND \"pronouns\" = 'they/them'))" ], [ - "(SELECT pg_notify('entity', '{", - " \"kind\": \"replace\",", - " \"complete\": {", - " \"id\": \"{{uuid:mocks.0.id}}\",", - " \"type\": \"person\",", + "INSERT INTO agreego.\"entity\" (", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", + ")", + "VALUES (", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:data.id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"organization\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " '{{uuid:data.id}}',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"user\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " '{{uuid:data.id}}',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"person\" (", + " \"date_of_birth\",", + " \"first_name\",", + " \"id\",", + " \"last_name\",", + " \"pronouns\",", + " \"type\"", + ")", + "VALUES (", + " '{{timestamp}}',", + " 'LookupFirst',", + " '{{uuid:data.id}}',", + " 'LookupLast',", + " 'they/them',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.change (", + " \"old\",", + " \"new\",", + " \"entity_id\",", + " \"id\",", + " \"kind\",", + " \"modified_at\",", + " \"modified_by\"", + ")", + "VALUES (", + " NULL,", + " '{", " \"first_name\": \"LookupFirst\",", " \"last_name\": \"LookupLast\",", " \"date_of_birth\": \"{{timestamp}}\",", " \"pronouns\": \"they/them\",", - " \"contact_id\": \"old-contact\",", + " \"type\": \"person\"", + " }',", + " '{{uuid:data.id}}',", + " '{{uuid:generated_0}}',", + " 'create',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000'", + ")" + ], + [ + "(SELECT pg_notify('entity', '{", + " \"kind\": \"create\",", + " \"complete\": {", + " \"first_name\": \"LookupFirst\",", + " \"last_name\": \"LookupLast\",", + " \"date_of_birth\": \"{{timestamp}}\",", + " \"pronouns\": \"they/them\",", + " \"id\": \"{{uuid:data.id}}\",", + " \"type\": \"person\",", + " \"created_by\": \"00000000-0000-0000-0000-000000000000\",", + " \"created_at\": \"{{timestamp}}\",", " \"modified_by\": \"00000000-0000-0000-0000-000000000000\",", " \"modified_at\": \"{{timestamp}}\"", " },", " \"new\": {", + " \"first_name\": \"LookupFirst\",", + " \"last_name\": \"LookupLast\",", + " \"date_of_birth\": \"{{timestamp}}\",", + " \"pronouns\": \"they/them\",", " \"type\": \"person\"", - " },", - " \"replaces\": \"{{uuid:data.id}}\"", + " }", "}'))" ] ] @@ -1573,26 +1758,64 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)", - "FROM agreego.\"person\" t1", - "JOIN agreego.\"user\" t2 ON ", - "JOIN agreego.\"organization\" t3 ON ", - "JOIN agreego.\"entity\" t4 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"organization\" t2 ON ", + "JOIN agreego.\"user\" t3 ON ", + "JOIN agreego.\"person\" t4 ON ", "WHERE", " t1.id = '{{uuid:mocks.0.id}}')" ], [ - "UPDATE agreego.\"person\" SET", - " first_name = 'NewFirst',", - " last_name = 'NewLast'", - "WHERE", - " id = '{{uuid:mocks.0.id}}'" + "INSERT INTO agreego.\"entity\" (", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", + ")", + "VALUES (", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " '{{uuid:mocks.0.id}}',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'person'", + ")" ], [ - "UPDATE agreego.\"entity\" SET", - " modified_at = '{{timestamp}}',", - " modified_by = '00000000-0000-0000-0000-000000000000'", - "WHERE", - " id = '{{uuid:mocks.0.id}}'" + "INSERT INTO agreego.\"organization\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " '{{uuid:mocks.0.id}}',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"user\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " '{{uuid:mocks.0.id}}',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"person\" (", + " \"first_name\",", + " \"id\",", + " \"last_name\",", + " \"type\"", + ")", + "VALUES (", + " 'NewFirst',", + " '{{uuid:mocks.0.id}}',", + " 'NewLast',", + " 'person'", + ")" ], [ "INSERT INTO agreego.change (", @@ -1605,10 +1828,7 @@ " \"modified_by\"", ")", "VALUES (", - " '{", - " \"first_name\": \"OldFirst\",", - " \"last_name\": \"OldLast\"", - " }',", + " NULL,", " '{", " \"first_name\": \"NewFirst\",", " \"last_name\": \"NewLast\",", @@ -1616,19 +1836,21 @@ " }',", " '{{uuid:mocks.0.id}}',", " '{{uuid:generated_0}}',", - " 'update',", + " 'create',", " '{{timestamp}}',", " '00000000-0000-0000-0000-000000000000'", ")" ], [ "(SELECT pg_notify('entity', '{", - " \"kind\": \"update\",", + " \"kind\": \"create\",", " \"complete\": {", - " \"id\": \"{{uuid:mocks.0.id}}\",", - " \"type\": \"person\",", " \"first_name\": \"NewFirst\",", " \"last_name\": \"NewLast\",", + " \"id\": \"{{uuid:mocks.0.id}}\",", + " \"type\": \"person\",", + " \"created_by\": \"00000000-0000-0000-0000-000000000000\",", + " \"created_at\": \"{{timestamp}}\",", " \"modified_by\": \"00000000-0000-0000-0000-000000000000\",", " \"modified_at\": \"{{timestamp}}\"", " },", @@ -1636,10 +1858,6 @@ " \"first_name\": \"NewFirst\",", " \"last_name\": \"NewLast\",", " \"type\": \"person\"", - " },", - " \"old\": {", - " \"first_name\": \"OldFirst\",", - " \"last_name\": \"OldLast\"", " }", "}'))" ] @@ -1663,10 +1881,10 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)", - "FROM agreego.\"person\" t1", - "JOIN agreego.\"user\" t2 ON ", - "JOIN agreego.\"organization\" t3 ON ", - "JOIN agreego.\"entity\" t4 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"organization\" t2 ON ", + "JOIN agreego.\"user\" t3 ON ", + "JOIN agreego.\"person\" t4 ON ", "WHERE", " t1.id = '123')" ], @@ -2002,8 +2220,8 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)", - "FROM agreego.\"order\" t1", - "JOIN agreego.\"entity\" t2 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"order\" t2 ON ", "WHERE", " t1.id = 'abc'", " OR (\"id\" = 'abc'))" @@ -2805,20 +3023,62 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)", - "FROM agreego.\"person\" t1", - "JOIN agreego.\"user\" t2 ON ", - "JOIN agreego.\"organization\" t3 ON ", - "JOIN agreego.\"entity\" t4 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"organization\" t2 ON ", + "JOIN agreego.\"user\" t3 ON ", + "JOIN agreego.\"person\" t4 ON ", "WHERE", " t1.id = 'abc-archived')" ], [ - "UPDATE agreego.\"entity\" SET", - " archived = true,", - " modified_at = '{{timestamp}}',", - " modified_by = '00000000-0000-0000-0000-000000000000'", - "WHERE", - " id = 'abc-archived'" + "INSERT INTO agreego.\"entity\" (", + " \"archived\",", + " \"created_at\",", + " \"created_by\",", + " \"id\",", + " \"modified_at\",", + " \"modified_by\",", + " \"type\"", + ")", + "VALUES (", + " true,", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'abc-archived',", + " '{{timestamp}}',", + " '00000000-0000-0000-0000-000000000000',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"organization\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " 'abc-archived',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"user\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " 'abc-archived',", + " 'person'", + ")" + ], + [ + "INSERT INTO agreego.\"person\" (", + " \"id\",", + " \"type\"", + ")", + "VALUES (", + " 'abc-archived',", + " 'person'", + ")" ], [ "INSERT INTO agreego.change (", @@ -2831,38 +3091,33 @@ " \"modified_by\"", ")", "VALUES (", - " '{", - " \"archived\": false", - " }',", + " NULL,", " '{", " \"archived\": true,", " \"type\": \"person\"", " }',", " 'abc-archived',", " '{{uuid:generated_0}}',", - " 'delete',", + " 'create',", " '{{timestamp}}',", " '00000000-0000-0000-0000-000000000000'", ")" ], [ "(SELECT pg_notify('entity', '{", - " \"kind\": \"delete\",", + " \"kind\": \"create\",", " \"complete\": {", + " \"archived\": true,", " \"id\": \"abc-archived\",", " \"type\": \"person\",", - " \"first_name\": \"ArchivedFirst\",", - " \"last_name\": \"ArchivedLast\",", - " \"archived\": true,", + " \"created_by\": \"00000000-0000-0000-0000-000000000000\",", + " \"created_at\": \"{{timestamp}}\",", " \"modified_by\": \"00000000-0000-0000-0000-000000000000\",", " \"modified_at\": \"{{timestamp}}\"", " },", " \"new\": {", " \"archived\": true,", " \"type\": \"person\"", - " },", - " \"old\": {", - " \"archived\": false", " }", "}'))" ] @@ -3121,8 +3376,8 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)", - "FROM agreego.\"order_line\" t1", - "JOIN agreego.\"entity\" t2 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"order_line\" t2 ON ", "WHERE", " t1.id = '{{uuid:data.lines.0.id}}')" ], @@ -3245,8 +3500,8 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)", - "FROM agreego.\"invoice\" t1", - "JOIN agreego.\"entity\" t2 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"invoice\" t2 ON ", "WHERE", " t1.id = '{{uuid:data.id}}'", " OR (\"id\" = '{{uuid:data.id}}'))" @@ -3362,8 +3617,8 @@ "sql": [ [ "(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)", - "FROM agreego.\"account\" t1", - "JOIN agreego.\"entity\" t2 ON ", + "FROM agreego.\"entity\" t1", + "JOIN agreego.\"account\" t2 ON ", "WHERE", " t1.id = '{{uuid:data.id}}')" ], diff --git a/fixtures/queryer.json b/fixtures/queryer.json index 0fe8601..e09ed07 100644 --- a/fixtures/queryer.json +++ b/fixtures/queryer.json @@ -230,8 +230,8 @@ { "name": "organization", "hierarchy": [ - "organization", - "entity" + "entity", + "organization" ], "fields": [ "id", @@ -287,9 +287,9 @@ { "name": "bot", "hierarchy": [ - "bot", + "entity", "organization", - "entity" + "bot" ], "fields": [ "token", @@ -353,9 +353,9 @@ { "name": "person", "hierarchy": [ - "person", + "entity", "organization", - "entity" + "person" ], "fields": [ "first_name", @@ -487,8 +487,8 @@ "name": "relationship", "relationship": true, "hierarchy": [ - "relationship", - "entity" + "entity", + "relationship" ], "fields": [ "source_id", @@ -539,9 +539,9 @@ "name": "contact", "relationship": true, "hierarchy": [ - "contact", + "entity", "relationship", - "entity" + "contact" ], "fields": [ "is_primary", @@ -599,8 +599,8 @@ { "name": "phone_number", "hierarchy": [ - "phone_number", - "entity" + "entity", + "phone_number" ], "fields": [ "number", @@ -644,8 +644,8 @@ { "name": "email_address", "hierarchy": [ - "email_address", - "entity" + "entity", + "email_address" ], "fields": [ "address", @@ -689,8 +689,8 @@ { "name": "address", "hierarchy": [ - "address", - "entity" + "entity", + "address" ], "fields": [ "city", @@ -777,8 +777,8 @@ } }, "hierarchy": [ - "order", - "entity" + "entity", + "order" ], "fields": [ "id", @@ -847,8 +847,8 @@ } }, "hierarchy": [ - "order_line", - "entity" + "entity", + "order_line" ], "fields": [ "id", @@ -893,8 +893,8 @@ { "name": "widget", "hierarchy": [ - "widget", - "entity" + "entity", + "widget" ], "fields": [ "id", @@ -946,8 +946,8 @@ { "name": "account", "hierarchy": [ - "account", - "entity" + "entity", + "account" ], "fields": [ "id", @@ -1075,8 +1075,8 @@ } }, "hierarchy": [ - "invoice", - "entity" + "entity", + "invoice" ], "fields": [ "id", @@ -1145,8 +1145,8 @@ } }, "hierarchy": [ - "invoice_line", - "entity" + "entity", + "invoice_line" ], "fields": [ "id", @@ -1283,20 +1283,20 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT jsonb_build_object(", - " 'id', entity_3.id,", - " 'type', entity_3.type,", - " 'archived', entity_3.archived,", - " 'created_at', entity_3.created_at,", + " 'id', entity_1.id,", + " 'type', entity_1.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", " 'name', organization_2.name,", - " 'first_name', person_1.first_name,", - " 'last_name', person_1.last_name,", - " 'age', person_1.age", + " 'first_name', person_3.first_name,", + " 'last_name', person_3.last_name,", + " 'age', person_3.age", " )", - " 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", + " FROM agreego.entity entity_1", + " JOIN agreego.organization organization_2 ON organization_2.id = entity_1.id", + " JOIN agreego.person person_3 ON person_3.id = organization_2.id", " WHERE", - " NOT entity_3.archived", + " NOT entity_1.archived", "))))" ] ] @@ -1312,170 +1312,170 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT jsonb_build_object(", - " 'id', entity_3.id,", - " 'type', entity_3.type,", - " 'archived', entity_3.archived,", - " 'created_at', entity_3.created_at,", + " 'id', entity_1.id,", + " 'type', entity_1.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", " 'name', organization_2.name,", - " 'first_name', person_1.first_name,", - " 'last_name', person_1.last_name,", - " 'age', person_1.age,", + " 'first_name', person_3.first_name,", + " 'last_name', person_3.last_name,", + " 'age', person_3.age,", " 'phone_numbers', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_6.id,", - " 'type', entity_6.type,", - " 'archived', entity_6.archived,", - " 'created_at', entity_6.created_at,", - " 'is_primary', contact_4.is_primary,", + " 'id', entity_4.id,", + " 'type', entity_4.type,", + " 'archived', entity_4.archived,", + " 'created_at', entity_4.created_at,", + " 'is_primary', contact_6.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_8.id,", - " 'type', entity_8.type,", - " 'archived', entity_8.archived,", - " 'created_at', entity_8.created_at,", - " 'number', phone_number_7.number", + " 'id', entity_7.id,", + " 'type', entity_7.type,", + " 'archived', entity_7.archived,", + " 'created_at', entity_7.created_at,", + " 'number', phone_number_8.number", " )", - " FROM agreego.phone_number phone_number_7", - " JOIN agreego.entity entity_8 ON entity_8.id = phone_number_7.id", + " FROM agreego.entity entity_7", + " JOIN agreego.phone_number phone_number_8 ON phone_number_8.id = entity_7.id", " WHERE", - " NOT entity_8.archived", - " AND relationship_5.target_id = entity_8.id", + " NOT entity_7.archived", + " AND relationship_5.target_id = entity_7.id", " )", " )), '[]'::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", + " FROM agreego.entity entity_4", + " JOIN agreego.relationship relationship_5 ON relationship_5.id = entity_4.id", + " JOIN agreego.contact contact_6 ON contact_6.id = relationship_5.id", " WHERE", - " NOT entity_6.archived", + " NOT entity_4.archived", " AND relationship_5.target_type = 'phone_number'", - " AND relationship_5.source_id = entity_3.id", + " AND relationship_5.source_id = entity_1.id", " ),", " 'email_addresses', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_11.id,", - " 'type', entity_11.type,", - " 'archived', entity_11.archived,", - " 'created_at', entity_11.created_at,", - " 'is_primary', contact_9.is_primary,", + " 'id', entity_9.id,", + " 'type', entity_9.type,", + " 'archived', entity_9.archived,", + " 'created_at', entity_9.created_at,", + " 'is_primary', contact_11.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_13.id,", - " 'type', entity_13.type,", - " 'archived', entity_13.archived,", - " 'created_at', entity_13.created_at,", - " 'address', email_address_12.address", + " 'id', entity_12.id,", + " 'type', entity_12.type,", + " 'archived', entity_12.archived,", + " 'created_at', entity_12.created_at,", + " 'address', email_address_13.address", " )", - " FROM agreego.email_address email_address_12", - " JOIN agreego.entity entity_13 ON entity_13.id = email_address_12.id", + " FROM agreego.entity entity_12", + " JOIN agreego.email_address email_address_13 ON email_address_13.id = entity_12.id", " WHERE", - " NOT entity_13.archived", - " AND relationship_10.target_id = entity_13.id", + " NOT entity_12.archived", + " AND relationship_10.target_id = entity_12.id", " )", " )), '[]'::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", + " FROM agreego.entity entity_9", + " JOIN agreego.relationship relationship_10 ON relationship_10.id = entity_9.id", + " JOIN agreego.contact contact_11 ON contact_11.id = relationship_10.id", " WHERE", - " NOT entity_11.archived", + " NOT entity_9.archived", " AND relationship_10.target_type = 'email_address'", - " AND relationship_10.source_id = entity_3.id", + " AND relationship_10.source_id = entity_1.id", " ),", " 'addresses', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_16.id,", - " 'type', entity_16.type,", - " 'archived', entity_16.archived,", - " 'created_at', entity_16.created_at,", - " 'is_primary', contact_14.is_primary,", + " 'id', entity_14.id,", + " 'type', entity_14.type,", + " 'archived', entity_14.archived,", + " 'created_at', entity_14.created_at,", + " 'is_primary', contact_16.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_18.id,", - " 'type', entity_18.type,", - " 'archived', entity_18.archived,", - " 'created_at', entity_18.created_at,", - " 'city', address_17.city", + " 'id', entity_17.id,", + " 'type', entity_17.type,", + " 'archived', entity_17.archived,", + " 'created_at', entity_17.created_at,", + " 'city', address_18.city", " )", - " FROM agreego.address address_17", - " JOIN agreego.entity entity_18 ON entity_18.id = address_17.id", + " FROM agreego.entity entity_17", + " JOIN agreego.address address_18 ON address_18.id = entity_17.id", " WHERE", - " NOT entity_18.archived", - " AND relationship_15.target_id = entity_18.id", + " NOT entity_17.archived", + " AND relationship_15.target_id = entity_17.id", " )", " )), '[]'::jsonb)", - " FROM agreego.contact contact_14", - " JOIN agreego.relationship relationship_15 ON relationship_15.id = contact_14.id", - " JOIN agreego.entity entity_16 ON entity_16.id = relationship_15.id", + " FROM agreego.entity entity_14", + " JOIN agreego.relationship relationship_15 ON relationship_15.id = entity_14.id", + " JOIN agreego.contact contact_16 ON contact_16.id = relationship_15.id", " WHERE", - " NOT entity_16.archived", + " NOT entity_14.archived", " AND relationship_15.target_type = 'address'", - " AND relationship_15.source_id = entity_3.id", + " AND relationship_15.source_id = entity_1.id", " ),", " 'contacts', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_21.id,", - " 'type', entity_21.type,", - " 'archived', entity_21.archived,", - " 'created_at', entity_21.created_at,", - " 'is_primary', contact_19.is_primary,", + " 'id', entity_19.id,", + " 'type', entity_19.type,", + " 'archived', entity_19.archived,", + " 'created_at', entity_19.created_at,", + " 'is_primary', contact_21.is_primary,", " 'target', CASE", " WHEN relationship_20.target_type = 'phone_number' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_23.id,", - " 'type', entity_23.type,", - " 'archived', entity_23.archived,", - " 'created_at', entity_23.created_at,", - " 'number', phone_number_22.number", + " 'id', entity_22.id,", + " 'type', entity_22.type,", + " 'archived', entity_22.archived,", + " 'created_at', entity_22.created_at,", + " 'number', phone_number_23.number", " )", - " FROM agreego.phone_number phone_number_22", - " JOIN agreego.entity entity_23 ON entity_23.id = phone_number_22.id", + " FROM agreego.entity entity_22", + " JOIN agreego.phone_number phone_number_23 ON phone_number_23.id = entity_22.id", " WHERE", - " NOT entity_23.archived", - " AND relationship_20.target_id = entity_23.id", + " NOT entity_22.archived", + " AND relationship_20.target_id = entity_22.id", " ))", " WHEN relationship_20.target_type = 'email_address' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_25.id,", - " 'type', entity_25.type,", - " 'archived', entity_25.archived,", - " 'created_at', entity_25.created_at,", - " 'address', email_address_24.address", + " 'id', entity_24.id,", + " 'type', entity_24.type,", + " 'archived', entity_24.archived,", + " 'created_at', entity_24.created_at,", + " 'address', email_address_25.address", " )", - " FROM agreego.email_address email_address_24", - " JOIN agreego.entity entity_25 ON entity_25.id = email_address_24.id", + " FROM agreego.entity entity_24", + " JOIN agreego.email_address email_address_25 ON email_address_25.id = entity_24.id", " WHERE", - " NOT entity_25.archived", - " AND relationship_20.target_id = entity_25.id", + " NOT entity_24.archived", + " AND relationship_20.target_id = entity_24.id", " ))", " WHEN relationship_20.target_type = 'address' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_27.id,", - " 'type', entity_27.type,", - " 'archived', entity_27.archived,", - " 'created_at', entity_27.created_at,", - " 'city', address_26.city", + " 'id', entity_26.id,", + " 'type', entity_26.type,", + " 'archived', entity_26.archived,", + " 'created_at', entity_26.created_at,", + " 'city', address_27.city", " )", - " FROM agreego.address address_26", - " JOIN agreego.entity entity_27 ON entity_27.id = address_26.id", + " FROM agreego.entity entity_26", + " JOIN agreego.address address_27 ON address_27.id = entity_26.id", " WHERE", - " NOT entity_27.archived", - " AND relationship_20.target_id = entity_27.id", + " NOT entity_26.archived", + " AND relationship_20.target_id = entity_26.id", " ))", " ELSE NULL", " END", " )), '[]'::jsonb)", - " FROM agreego.contact contact_19", - " JOIN agreego.relationship relationship_20 ON relationship_20.id = contact_19.id", - " JOIN agreego.entity entity_21 ON entity_21.id = relationship_20.id", + " FROM agreego.entity entity_19", + " JOIN agreego.relationship relationship_20 ON relationship_20.id = entity_19.id", + " JOIN agreego.contact contact_21 ON contact_21.id = relationship_20.id", " WHERE", - " NOT entity_21.archived", - " AND relationship_20.source_id = entity_3.id", + " NOT entity_19.archived", + " AND relationship_20.source_id = entity_1.id", " )", " )", - " 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", + " FROM agreego.entity entity_1", + " JOIN agreego.organization organization_2 ON organization_2.id = entity_1.id", + " JOIN agreego.person person_3 ON person_3.id = organization_2.id", " WHERE", - " NOT entity_3.archived", + " NOT entity_1.archived", "))))" ] ] @@ -1562,202 +1562,202 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT jsonb_build_object(", - " 'id', entity_3.id,", - " 'type', entity_3.type,", - " 'archived', entity_3.archived,", - " 'created_at', entity_3.created_at,", + " 'id', entity_1.id,", + " 'type', entity_1.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", " 'name', organization_2.name,", - " 'first_name', person_1.first_name,", - " 'last_name', person_1.last_name,", - " 'age', person_1.age,", + " 'first_name', person_3.first_name,", + " 'last_name', person_3.last_name,", + " 'age', person_3.age,", " 'phone_numbers', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_6.id,", - " 'type', entity_6.type,", - " 'archived', entity_6.archived,", - " 'created_at', entity_6.created_at,", - " 'is_primary', contact_4.is_primary,", + " 'id', entity_4.id,", + " 'type', entity_4.type,", + " 'archived', entity_4.archived,", + " 'created_at', entity_4.created_at,", + " 'is_primary', contact_6.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_8.id,", - " 'type', entity_8.type,", - " 'archived', entity_8.archived,", - " 'created_at', entity_8.created_at,", - " 'number', phone_number_7.number", + " 'id', entity_7.id,", + " 'type', entity_7.type,", + " 'archived', entity_7.archived,", + " 'created_at', entity_7.created_at,", + " 'number', phone_number_8.number", " )", - " FROM agreego.phone_number phone_number_7", - " JOIN agreego.entity entity_8 ON entity_8.id = phone_number_7.id", + " FROM agreego.entity entity_7", + " JOIN agreego.phone_number phone_number_8 ON phone_number_8.id = entity_7.id", " WHERE", - " NOT entity_8.archived", - " AND phone_number_7.number ILIKE $32 #>> '{}'", - " AND relationship_5.target_id = entity_8.id", + " NOT entity_7.archived", + " AND phone_number_8.number ILIKE $32 #>> '{}'", + " AND relationship_5.target_id = entity_7.id", " )", " )), '[]'::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", + " FROM agreego.entity entity_4", + " JOIN agreego.relationship relationship_5 ON relationship_5.id = entity_4.id", + " JOIN agreego.contact contact_6 ON contact_6.id = relationship_5.id", " WHERE", - " NOT entity_6.archived", + " NOT entity_4.archived", " AND relationship_5.target_type = 'phone_number'", - " AND relationship_5.source_id = entity_3.id", + " AND relationship_5.source_id = entity_1.id", " ),", " 'email_addresses', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_11.id,", - " 'type', entity_11.type,", - " 'archived', entity_11.archived,", - " 'created_at', entity_11.created_at,", - " 'is_primary', contact_9.is_primary,", + " 'id', entity_9.id,", + " 'type', entity_9.type,", + " 'archived', entity_9.archived,", + " 'created_at', entity_9.created_at,", + " 'is_primary', contact_11.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_13.id,", - " 'type', entity_13.type,", - " 'archived', entity_13.archived,", - " 'created_at', entity_13.created_at,", - " 'address', email_address_12.address", + " 'id', entity_12.id,", + " 'type', entity_12.type,", + " 'archived', entity_12.archived,", + " 'created_at', entity_12.created_at,", + " 'address', email_address_13.address", " )", - " FROM agreego.email_address email_address_12", - " JOIN agreego.entity entity_13 ON entity_13.id = email_address_12.id", + " FROM agreego.entity entity_12", + " JOIN agreego.email_address email_address_13 ON email_address_13.id = entity_12.id", " WHERE", - " NOT entity_13.archived", - " AND relationship_10.target_id = entity_13.id", + " NOT entity_12.archived", + " AND relationship_10.target_id = entity_12.id", " )", " )), '[]'::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", + " FROM agreego.entity entity_9", + " JOIN agreego.relationship relationship_10 ON relationship_10.id = entity_9.id", + " JOIN agreego.contact contact_11 ON contact_11.id = relationship_10.id", " WHERE", - " NOT entity_11.archived", + " NOT entity_9.archived", " AND relationship_10.target_type = 'email_address'", - " AND relationship_10.source_id = entity_3.id", + " AND relationship_10.source_id = entity_1.id", " ),", " 'addresses', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_16.id,", - " 'type', entity_16.type,", - " 'archived', entity_16.archived,", - " 'created_at', entity_16.created_at,", - " 'is_primary', contact_14.is_primary,", + " 'id', entity_14.id,", + " 'type', entity_14.type,", + " 'archived', entity_14.archived,", + " 'created_at', entity_14.created_at,", + " 'is_primary', contact_16.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_18.id,", - " 'type', entity_18.type,", - " 'archived', entity_18.archived,", - " 'created_at', entity_18.created_at,", - " 'city', address_17.city", + " 'id', entity_17.id,", + " 'type', entity_17.type,", + " 'archived', entity_17.archived,", + " 'created_at', entity_17.created_at,", + " 'city', address_18.city", " )", - " FROM agreego.address address_17", - " JOIN agreego.entity entity_18 ON entity_18.id = address_17.id", + " FROM agreego.entity entity_17", + " JOIN agreego.address address_18 ON address_18.id = entity_17.id", " WHERE", - " NOT entity_18.archived", - " AND relationship_15.target_id = entity_18.id", + " NOT entity_17.archived", + " AND relationship_15.target_id = entity_17.id", " )", " )), '[]'::jsonb)", - " FROM agreego.contact contact_14", - " JOIN agreego.relationship relationship_15 ON relationship_15.id = contact_14.id", - " JOIN agreego.entity entity_16 ON entity_16.id = relationship_15.id", + " FROM agreego.entity entity_14", + " JOIN agreego.relationship relationship_15 ON relationship_15.id = entity_14.id", + " JOIN agreego.contact contact_16 ON contact_16.id = relationship_15.id", " WHERE", - " NOT entity_16.archived", + " NOT entity_14.archived", " AND relationship_15.target_type = 'address'", - " AND relationship_15.source_id = entity_3.id", + " AND relationship_15.source_id = entity_1.id", " ),", " 'contacts', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_21.id,", - " 'type', entity_21.type,", - " 'archived', entity_21.archived,", - " 'created_at', entity_21.created_at,", - " 'is_primary', contact_19.is_primary,", + " 'id', entity_19.id,", + " 'type', entity_19.type,", + " 'archived', entity_19.archived,", + " 'created_at', entity_19.created_at,", + " 'is_primary', contact_21.is_primary,", " 'target', CASE", " WHEN relationship_20.target_type = 'phone_number' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_23.id,", - " 'type', entity_23.type,", - " 'archived', entity_23.archived,", - " 'created_at', entity_23.created_at,", - " 'number', phone_number_22.number", + " 'id', entity_22.id,", + " 'type', entity_22.type,", + " 'archived', entity_22.archived,", + " 'created_at', entity_22.created_at,", + " 'number', phone_number_23.number", " )", - " FROM agreego.phone_number phone_number_22", - " JOIN agreego.entity entity_23 ON entity_23.id = phone_number_22.id", + " FROM agreego.entity entity_22", + " JOIN agreego.phone_number phone_number_23 ON phone_number_23.id = entity_22.id", " WHERE", - " NOT entity_23.archived", - " AND relationship_20.target_id = entity_23.id", + " NOT entity_22.archived", + " AND relationship_20.target_id = entity_22.id", " ))", " WHEN relationship_20.target_type = 'email_address' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_25.id,", - " 'type', entity_25.type,", - " 'archived', entity_25.archived,", - " 'created_at', entity_25.created_at,", - " 'address', email_address_24.address", + " 'id', entity_24.id,", + " 'type', entity_24.type,", + " 'archived', entity_24.archived,", + " 'created_at', entity_24.created_at,", + " 'address', email_address_25.address", " )", - " FROM agreego.email_address email_address_24", - " JOIN agreego.entity entity_25 ON entity_25.id = email_address_24.id", + " FROM agreego.entity entity_24", + " JOIN agreego.email_address email_address_25 ON email_address_25.id = entity_24.id", " WHERE", - " NOT entity_25.archived", - " AND relationship_20.target_id = entity_25.id", + " NOT entity_24.archived", + " AND relationship_20.target_id = entity_24.id", " ))", " WHEN relationship_20.target_type = 'address' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_27.id,", - " 'type', entity_27.type,", - " 'archived', entity_27.archived,", - " 'created_at', entity_27.created_at,", - " 'city', address_26.city", + " 'id', entity_26.id,", + " 'type', entity_26.type,", + " 'archived', entity_26.archived,", + " 'created_at', entity_26.created_at,", + " 'city', address_27.city", " )", - " FROM agreego.address address_26", - " JOIN agreego.entity entity_27 ON entity_27.id = address_26.id", + " FROM agreego.entity entity_26", + " JOIN agreego.address address_27 ON address_27.id = entity_26.id", " WHERE", - " NOT entity_27.archived", - " AND relationship_20.target_id = entity_27.id", + " NOT entity_26.archived", + " AND relationship_20.target_id = entity_26.id", " ))", " ELSE NULL", " END", " )), '[]'::jsonb)", - " FROM agreego.contact contact_19", - " JOIN agreego.relationship relationship_20 ON relationship_20.id = contact_19.id", - " JOIN agreego.entity entity_21 ON entity_21.id = relationship_20.id", + " FROM agreego.entity entity_19", + " JOIN agreego.relationship relationship_20 ON relationship_20.id = entity_19.id", + " JOIN agreego.contact contact_21 ON contact_21.id = relationship_20.id", " WHERE", - " NOT entity_21.archived", - " AND contact_19.is_primary = ($11 #>> '{}')::BOOLEAN", - " AND relationship_20.source_id = entity_3.id", + " NOT entity_19.archived", + " AND contact_21.is_primary = ($11 #>> '{}')::BOOLEAN", + " AND relationship_20.source_id = entity_1.id", " )", " )", - " 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", + " FROM agreego.entity entity_1", + " JOIN agreego.organization organization_2 ON organization_2.id = entity_1.id", + " JOIN agreego.person person_3 ON person_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 < ($4 #>> '{}')::NUMERIC", - " AND person_1.age <= ($5 #>> '{}')::NUMERIC", - " AND person_1.age <> ($6 #>> '{}')::NUMERIC", - " AND person_1.age NOT IN (SELECT value::NUMERIC FROM jsonb_array_elements_text(($7 #>> '{}')::jsonb))", - " AND person_1.age 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 < ($21 #>> '{)", - " AND person_1.first_name <= ($22 #>> '{)", - " AND person_1.first_name NOT ILIKE $23 #>> '{}'", - " AND person_1.first_name NOT IN (SELECT value FROM jsonb_array_elements_text(($24 #>> '{}')::jsonb))", - " AND person_1.first_name IN (SELECT value FROM jsonb_array_elements_text(($25 #>> '{}')::jsonb))", - " AND entity_3.id = ($26 #>> '{}')::UUID", - " AND entity_3.id <> ($27 #>> '{}')::UUID", - " AND entity_3.id NOT IN (SELECT value::UUID FROM jsonb_array_elements_text(($28 #>> '{}')::jsonb))", - " AND entity_3.id 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 #>> '{}'", + " NOT entity_1.archived", + " AND person_3.age = ($1 #>> '{}')::NUMERIC", + " AND person_3.age > ($2 #>> '{}')::NUMERIC", + " AND person_3.age >= ($3 #>> '{}')::NUMERIC", + " AND person_3.age < ($4 #>> '{}')::NUMERIC", + " AND person_3.age <= ($5 #>> '{}')::NUMERIC", + " AND person_3.age <> ($6 #>> '{}')::NUMERIC", + " AND person_3.age NOT IN (SELECT value::NUMERIC FROM jsonb_array_elements_text(($7 #>> '{}')::jsonb))", + " AND person_3.age IN (SELECT value::NUMERIC FROM jsonb_array_elements_text(($8 #>> '{}')::jsonb))", + " AND entity_1.archived = ($9 #>> '{}')::BOOLEAN", + " AND entity_1.archived <> ($10 #>> '{}')::BOOLEAN", + " AND entity_1.created_at = ($12 #>> '{}')::TIMESTAMPTZ", + " AND entity_1.created_at > ($13 #>> '{}')::TIMESTAMPTZ", + " AND entity_1.created_at >= ($14 #>> '{}')::TIMESTAMPTZ", + " AND entity_1.created_at < ($15 #>> '{}')::TIMESTAMPTZ", + " AND entity_1.created_at <= ($16 #>> '{}')::TIMESTAMPTZ", + " AND entity_1.created_at <> ($17 #>> '{}')::TIMESTAMPTZ", + " AND person_3.first_name ILIKE $18 #>> '{}'", + " AND person_3.first_name > ($19 #>> '{)", + " AND person_3.first_name >= ($20 #>> '{)", + " AND person_3.first_name < ($21 #>> '{)", + " AND person_3.first_name <= ($22 #>> '{)", + " AND person_3.first_name NOT ILIKE $23 #>> '{}'", + " AND person_3.first_name NOT IN (SELECT value FROM jsonb_array_elements_text(($24 #>> '{}')::jsonb))", + " AND person_3.first_name IN (SELECT value FROM jsonb_array_elements_text(($25 #>> '{}')::jsonb))", + " AND entity_1.id = ($26 #>> '{}')::UUID", + " AND entity_1.id <> ($27 #>> '{}')::UUID", + " AND entity_1.id NOT IN (SELECT value::UUID FROM jsonb_array_elements_text(($28 #>> '{}')::jsonb))", + " AND entity_1.id IN (SELECT value::UUID FROM jsonb_array_elements_text(($29 #>> '{}')::jsonb))", + " AND person_3.last_name ILIKE $30 #>> '{}'", + " AND person_3.last_name NOT ILIKE $31 #>> '{}'", " ))))" ] ] @@ -1773,31 +1773,31 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_3.id,", - " 'type', entity_3.type,", - " 'archived', entity_3.archived,", - " 'created_at', entity_3.created_at,", - " 'is_primary', contact_1.is_primary,", + " 'id', entity_1.id,", + " 'type', entity_1.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'is_primary', contact_3.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_5.id,", - " 'type', entity_5.type,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", - " 'address', email_address_4.address", + " 'id', entity_4.id,", + " 'type', entity_4.type,", + " 'archived', entity_4.archived,", + " 'created_at', entity_4.created_at,", + " 'address', email_address_5.address", " )", - " FROM agreego.email_address email_address_4", - " JOIN agreego.entity entity_5 ON entity_5.id = email_address_4.id", + " FROM agreego.entity entity_4", + " JOIN agreego.email_address email_address_5 ON email_address_5.id = entity_4.id", " WHERE", - " NOT entity_5.archived", - " AND relationship_2.target_id = entity_5.id", + " NOT entity_4.archived", + " AND relationship_2.target_id = entity_4.id", " )", " )), '[]'::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", + " FROM agreego.entity entity_1", + " JOIN agreego.relationship relationship_2 ON relationship_2.id = entity_1.id", + " JOIN agreego.contact contact_3 ON contact_3.id = relationship_2.id", " WHERE", - " NOT entity_3.archived", + " NOT entity_1.archived", " AND relationship_2.target_type = 'email_address'", "))))" ] @@ -1814,51 +1814,51 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT jsonb_build_object(", - " 'id', order_1.id,", - " 'type', order_1.type,", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'total', order_1.total,", - " 'customer_id', order_1.customer_id,", + " 'id', order_2.id,", + " 'type', order_2.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'total', order_2.total,", + " 'customer_id', order_2.customer_id,", " 'customer', (", " SELECT jsonb_build_object(", - " 'id', entity_5.id,", - " 'type', entity_5.type,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", + " 'id', entity_3.id,", + " 'type', entity_3.type,", + " 'archived', entity_3.archived,", + " 'created_at', entity_3.created_at,", " 'name', organization_4.name,", - " 'first_name', person_3.first_name,", - " 'last_name', person_3.last_name,", - " 'age', person_3.age", + " 'first_name', person_5.first_name,", + " 'last_name', person_5.last_name,", + " 'age', person_5.age", " )", - " 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", + " FROM agreego.entity entity_3", + " JOIN agreego.organization organization_4 ON organization_4.id = entity_3.id", + " JOIN agreego.person person_5 ON person_5.id = organization_4.id", " WHERE", - " NOT entity_5.archived", - " AND order_1.customer_id = person_3.id", + " NOT entity_3.archived", + " AND order_2.customer_id = person_5.id", " ),", " 'lines', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', order_line_6.id,", - " 'type', order_line_6.type,", - " 'archived', entity_7.archived,", - " 'created_at', entity_7.created_at,", - " 'order_id', order_line_6.order_id,", - " 'product', order_line_6.product,", - " 'price', order_line_6.price", + " 'id', order_line_7.id,", + " 'type', order_line_7.type,", + " 'archived', entity_6.archived,", + " 'created_at', entity_6.created_at,", + " 'order_id', order_line_7.order_id,", + " 'product', order_line_7.product,", + " 'price', order_line_7.price", " )), '[]'::jsonb)", - " FROM agreego.order_line order_line_6", - " JOIN agreego.entity entity_7 ON entity_7.id = order_line_6.id", + " FROM agreego.entity entity_6", + " JOIN agreego.order_line order_line_7 ON order_line_7.id = entity_6.id", " WHERE", - " NOT entity_7.archived", - " AND order_line_6.order_id = order_1.id", + " NOT entity_6.archived", + " AND order_line_7.order_id = order_2.id", " )", " )", - " FROM agreego.order order_1", - " JOIN agreego.entity entity_2 ON entity_2.id = order_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.order order_2 ON order_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", + " NOT entity_1.archived", "))))" ] ] @@ -1874,16 +1874,16 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT jsonb_build_object(", - " 'id', entity_2.id,", - " 'type', entity_2.type,", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'name', organization_1.name", + " 'id', entity_1.id,", + " 'type', entity_1.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'name', organization_2.name", " )", - " FROM agreego.organization organization_1", - " JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.organization organization_2 ON organization_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", + " NOT entity_1.archived", "))))" ] ] @@ -1899,61 +1899,61 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT COALESCE(jsonb_agg(CASE", - " WHEN organization_1.type = 'bot' THEN ((", + " WHEN organization_2.type = 'bot' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_5.id,", - " 'type', entity_5.type,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", + " 'id', entity_3.id,", + " 'type', entity_3.type,", + " 'archived', entity_3.archived,", + " 'created_at', entity_3.created_at,", " 'name', organization_4.name,", - " 'token', bot_3.token,", - " 'role', bot_3.role", + " 'token', bot_5.token,", + " 'role', bot_5.role", " )", - " 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", + " FROM agreego.entity entity_3", + " JOIN agreego.organization organization_4 ON organization_4.id = entity_3.id", + " JOIN agreego.bot bot_5 ON bot_5.id = organization_4.id", " WHERE", - " NOT entity_5.archived", - " AND entity_5.id = entity_2.id", + " NOT entity_3.archived", + " AND entity_3.id = entity_1.id", " ))", - " WHEN organization_1.type = 'organization' THEN ((", + " WHEN organization_2.type = 'organization' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_7.id,", - " 'type', entity_7.type,", - " 'archived', entity_7.archived,", - " 'created_at', entity_7.created_at,", - " 'name', organization_6.name", + " 'id', entity_6.id,", + " 'type', entity_6.type,", + " 'archived', entity_6.archived,", + " 'created_at', entity_6.created_at,", + " 'name', organization_7.name", " )", - " FROM agreego.organization organization_6", - " JOIN agreego.entity entity_7 ON entity_7.id = organization_6.id", + " FROM agreego.entity entity_6", + " JOIN agreego.organization organization_7 ON organization_7.id = entity_6.id", " WHERE", - " NOT entity_7.archived", - " AND entity_7.id = entity_2.id", + " NOT entity_6.archived", + " AND entity_6.id = entity_1.id", " ))", - " WHEN organization_1.type = 'person' THEN ((", + " WHEN organization_2.type = 'person' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_10.id,", - " 'type', entity_10.type,", - " 'archived', entity_10.archived,", - " 'created_at', entity_10.created_at,", + " 'id', entity_8.id,", + " 'type', entity_8.type,", + " 'archived', entity_8.archived,", + " 'created_at', entity_8.created_at,", " 'name', organization_9.name,", - " 'first_name', person_8.first_name,", - " 'last_name', person_8.last_name,", - " 'age', person_8.age", + " 'first_name', person_10.first_name,", + " 'last_name', person_10.last_name,", + " 'age', person_10.age", " )", - " 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", + " FROM agreego.entity entity_8", + " JOIN agreego.organization organization_9 ON organization_9.id = entity_8.id", + " JOIN agreego.person person_10 ON person_10.id = organization_9.id", " WHERE", - " NOT entity_10.archived", - " AND entity_10.id = entity_2.id", + " NOT entity_8.archived", + " AND entity_8.id = entity_1.id", " ))", " ELSE NULL", " END), '[]'::jsonb)", - " FROM agreego.organization organization_1", - " JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.organization organization_2 ON organization_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", + " NOT entity_1.archived", "))))" ] ] @@ -1969,45 +1969,45 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT CASE", - " WHEN organization_1.type = 'bot' THEN ((", + " WHEN organization_2.type = 'bot' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_5.id,", - " 'type', entity_5.type,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", + " 'id', entity_3.id,", + " 'type', entity_3.type,", + " 'archived', entity_3.archived,", + " 'created_at', entity_3.created_at,", " 'name', organization_4.name,", - " 'token', bot_3.token", + " 'token', bot_5.token", " )", - " 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", + " FROM agreego.entity entity_3", + " JOIN agreego.organization organization_4 ON organization_4.id = entity_3.id", + " JOIN agreego.bot bot_5 ON bot_5.id = organization_4.id", " WHERE", - " NOT entity_5.archived", - " AND entity_5.id = entity_2.id", + " NOT entity_3.archived", + " AND entity_3.id = entity_1.id", " ))", - " WHEN organization_1.type = 'person' THEN ((", + " WHEN organization_2.type = 'person' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_8.id,", - " 'type', entity_8.type,", - " 'archived', entity_8.archived,", - " 'created_at', entity_8.created_at,", + " 'id', entity_6.id,", + " 'type', entity_6.type,", + " 'archived', entity_6.archived,", + " 'created_at', entity_6.created_at,", " 'name', organization_7.name,", - " 'first_name', person_6.first_name,", - " 'last_name', person_6.last_name", + " 'first_name', person_8.first_name,", + " 'last_name', person_8.last_name", " )", - " 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", + " FROM agreego.entity entity_6", + " JOIN agreego.organization organization_7 ON organization_7.id = entity_6.id", + " JOIN agreego.person person_8 ON person_8.id = organization_7.id", " WHERE", - " NOT entity_8.archived", - " AND entity_8.id = entity_2.id", + " NOT entity_6.archived", + " AND entity_6.id = entity_1.id", " ))", " ELSE NULL", " END", - " FROM agreego.organization organization_1", - " JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.organization organization_2 ON organization_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", + " NOT entity_1.archived", "))))" ] ] @@ -2023,180 +2023,180 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT CASE", - " WHEN organization_1.type = 'person' THEN ((", + " WHEN organization_2.type = 'person' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_5.id,", - " 'type', entity_5.type,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", + " 'id', entity_3.id,", + " 'type', entity_3.type,", + " 'archived', entity_3.archived,", + " 'created_at', entity_3.created_at,", " 'name', organization_4.name,", - " 'first_name', person_3.first_name,", - " 'last_name', person_3.last_name,", - " 'age', person_3.age,", + " 'first_name', person_5.first_name,", + " 'last_name', person_5.last_name,", + " 'age', person_5.age,", " 'phone_numbers', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_8.id,", - " 'type', entity_8.type,", - " 'archived', entity_8.archived,", - " 'created_at', entity_8.created_at,", - " 'is_primary', contact_6.is_primary,", + " 'id', entity_6.id,", + " 'type', entity_6.type,", + " 'archived', entity_6.archived,", + " 'created_at', entity_6.created_at,", + " 'is_primary', contact_8.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_10.id,", - " 'type', entity_10.type,", - " 'archived', entity_10.archived,", - " 'created_at', entity_10.created_at,", - " 'number', phone_number_9.number", + " 'id', entity_9.id,", + " 'type', entity_9.type,", + " 'archived', entity_9.archived,", + " 'created_at', entity_9.created_at,", + " 'number', phone_number_10.number", " )", - " FROM agreego.phone_number phone_number_9", - " JOIN agreego.entity entity_10 ON entity_10.id = phone_number_9.id", + " FROM agreego.entity entity_9", + " JOIN agreego.phone_number phone_number_10 ON phone_number_10.id = entity_9.id", " WHERE", - " NOT entity_10.archived", - " AND relationship_7.target_id = entity_10.id", + " NOT entity_9.archived", + " AND relationship_7.target_id = entity_9.id", " )", " )), '[]'::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", + " FROM agreego.entity entity_6", + " JOIN agreego.relationship relationship_7 ON relationship_7.id = entity_6.id", + " JOIN agreego.contact contact_8 ON contact_8.id = relationship_7.id", " WHERE", - " NOT entity_8.archived", + " NOT entity_6.archived", " AND relationship_7.target_type = 'phone_number'", - " AND relationship_7.source_id = entity_5.id", + " AND relationship_7.source_id = entity_3.id", " ),", " 'email_addresses', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_13.id,", - " 'type', entity_13.type,", - " 'archived', entity_13.archived,", - " 'created_at', entity_13.created_at,", - " 'is_primary', contact_11.is_primary,", + " 'id', entity_11.id,", + " 'type', entity_11.type,", + " 'archived', entity_11.archived,", + " 'created_at', entity_11.created_at,", + " 'is_primary', contact_13.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_15.id,", - " 'type', entity_15.type,", - " 'archived', entity_15.archived,", - " 'created_at', entity_15.created_at,", - " 'address', email_address_14.address", + " 'id', entity_14.id,", + " 'type', entity_14.type,", + " 'archived', entity_14.archived,", + " 'created_at', entity_14.created_at,", + " 'address', email_address_15.address", " )", - " FROM agreego.email_address email_address_14", - " JOIN agreego.entity entity_15 ON entity_15.id = email_address_14.id", + " FROM agreego.entity entity_14", + " JOIN agreego.email_address email_address_15 ON email_address_15.id = entity_14.id", " WHERE", - " NOT entity_15.archived", - " AND relationship_12.target_id = entity_15.id", + " NOT entity_14.archived", + " AND relationship_12.target_id = entity_14.id", " )", " )), '[]'::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", + " FROM agreego.entity entity_11", + " JOIN agreego.relationship relationship_12 ON relationship_12.id = entity_11.id", + " JOIN agreego.contact contact_13 ON contact_13.id = relationship_12.id", " WHERE", - " NOT entity_13.archived", + " NOT entity_11.archived", " AND relationship_12.target_type = 'email_address'", - " AND relationship_12.source_id = entity_5.id", + " AND relationship_12.source_id = entity_3.id", " ),", " 'addresses', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_18.id,", - " 'type', entity_18.type,", - " 'archived', entity_18.archived,", - " 'created_at', entity_18.created_at,", - " 'is_primary', contact_16.is_primary,", + " 'id', entity_16.id,", + " 'type', entity_16.type,", + " 'archived', entity_16.archived,", + " 'created_at', entity_16.created_at,", + " 'is_primary', contact_18.is_primary,", " 'target', (", " SELECT jsonb_build_object(", - " 'id', entity_20.id,", - " 'type', entity_20.type,", - " 'archived', entity_20.archived,", - " 'created_at', entity_20.created_at,", - " 'city', address_19.city", + " 'id', entity_19.id,", + " 'type', entity_19.type,", + " 'archived', entity_19.archived,", + " 'created_at', entity_19.created_at,", + " 'city', address_20.city", " )", - " FROM agreego.address address_19", - " JOIN agreego.entity entity_20 ON entity_20.id = address_19.id", + " FROM agreego.entity entity_19", + " JOIN agreego.address address_20 ON address_20.id = entity_19.id", " WHERE", - " NOT entity_20.archived", - " AND relationship_17.target_id = entity_20.id", + " NOT entity_19.archived", + " AND relationship_17.target_id = entity_19.id", " )", " )), '[]'::jsonb)", - " FROM agreego.contact contact_16", - " JOIN agreego.relationship relationship_17 ON relationship_17.id = contact_16.id", - " JOIN agreego.entity entity_18 ON entity_18.id = relationship_17.id", + " FROM agreego.entity entity_16", + " JOIN agreego.relationship relationship_17 ON relationship_17.id = entity_16.id", + " JOIN agreego.contact contact_18 ON contact_18.id = relationship_17.id", " WHERE", - " NOT entity_18.archived", + " NOT entity_16.archived", " AND relationship_17.target_type = 'address'", - " AND relationship_17.source_id = entity_5.id", + " AND relationship_17.source_id = entity_3.id", " ),", " 'contacts', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', entity_23.id,", - " 'type', entity_23.type,", - " 'archived', entity_23.archived,", - " 'created_at', entity_23.created_at,", - " 'is_primary', contact_21.is_primary,", + " 'id', entity_21.id,", + " 'type', entity_21.type,", + " 'archived', entity_21.archived,", + " 'created_at', entity_21.created_at,", + " 'is_primary', contact_23.is_primary,", " 'target', CASE", " WHEN relationship_22.target_type = 'phone_number' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_25.id,", - " 'type', entity_25.type,", - " 'archived', entity_25.archived,", - " 'created_at', entity_25.created_at,", - " 'number', phone_number_24.number", + " 'id', entity_24.id,", + " 'type', entity_24.type,", + " 'archived', entity_24.archived,", + " 'created_at', entity_24.created_at,", + " 'number', phone_number_25.number", " )", - " FROM agreego.phone_number phone_number_24", - " JOIN agreego.entity entity_25 ON entity_25.id = phone_number_24.id", + " FROM agreego.entity entity_24", + " JOIN agreego.phone_number phone_number_25 ON phone_number_25.id = entity_24.id", " WHERE", - " NOT entity_25.archived", - " AND relationship_22.target_id = entity_25.id", + " NOT entity_24.archived", + " AND relationship_22.target_id = entity_24.id", " ))", " WHEN relationship_22.target_type = 'email_address' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_27.id,", - " 'type', entity_27.type,", - " 'archived', entity_27.archived,", - " 'created_at', entity_27.created_at,", - " 'address', email_address_26.address", + " 'id', entity_26.id,", + " 'type', entity_26.type,", + " 'archived', entity_26.archived,", + " 'created_at', entity_26.created_at,", + " 'address', email_address_27.address", " )", - " FROM agreego.email_address email_address_26", - " JOIN agreego.entity entity_27 ON entity_27.id = email_address_26.id", + " FROM agreego.entity entity_26", + " JOIN agreego.email_address email_address_27 ON email_address_27.id = entity_26.id", " WHERE", - " NOT entity_27.archived", - " AND relationship_22.target_id = entity_27.id", + " NOT entity_26.archived", + " AND relationship_22.target_id = entity_26.id", " ))", " WHEN relationship_22.target_type = 'address' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_29.id,", - " 'type', entity_29.type,", - " 'archived', entity_29.archived,", - " 'created_at', entity_29.created_at,", - " 'city', address_28.city", + " 'id', entity_28.id,", + " 'type', entity_28.type,", + " 'archived', entity_28.archived,", + " 'created_at', entity_28.created_at,", + " 'city', address_29.city", " )", - " FROM agreego.address address_28", - " JOIN agreego.entity entity_29 ON entity_29.id = address_28.id", + " FROM agreego.entity entity_28", + " JOIN agreego.address address_29 ON address_29.id = entity_28.id", " WHERE", - " NOT entity_29.archived", - " AND relationship_22.target_id = entity_29.id", + " NOT entity_28.archived", + " AND relationship_22.target_id = entity_28.id", " ))", " ELSE NULL", " END", " )), '[]'::jsonb)", - " FROM agreego.contact contact_21", - " JOIN agreego.relationship relationship_22 ON relationship_22.id = contact_21.id", - " JOIN agreego.entity entity_23 ON entity_23.id = relationship_22.id", + " FROM agreego.entity entity_21", + " JOIN agreego.relationship relationship_22 ON relationship_22.id = entity_21.id", + " JOIN agreego.contact contact_23 ON contact_23.id = relationship_22.id", " WHERE", - " NOT entity_23.archived", - " AND relationship_22.source_id = entity_5.id", + " NOT entity_21.archived", + " AND relationship_22.source_id = entity_3.id", " )", " )", - " 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", + " FROM agreego.entity entity_3", + " JOIN agreego.organization organization_4 ON organization_4.id = entity_3.id", + " JOIN agreego.person person_5 ON person_5.id = organization_4.id", " WHERE", - " NOT entity_5.archived", - " AND entity_5.id = entity_2.id", + " NOT entity_3.archived", + " AND entity_3.id = entity_1.id", " ))", " ELSE NULL", " END", - " FROM agreego.organization organization_1", - " JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.organization organization_2 ON organization_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", + " NOT entity_1.archived", "))))" ] ] @@ -2212,35 +2212,35 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', order_1.id,", - " 'type', order_1.type,", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'total', order_1.total,", - " 'customer_id', order_1.customer_id,", + " 'id', order_2.id,", + " 'type', order_2.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'total', order_2.total,", + " 'customer_id', order_2.customer_id,", " 'customer', (", " SELECT jsonb_build_object(", - " 'id', entity_5.id,", - " 'type', entity_5.type,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", + " 'id', entity_3.id,", + " 'type', entity_3.type,", + " 'archived', entity_3.archived,", + " 'created_at', entity_3.created_at,", " 'name', organization_4.name,", - " 'first_name', person_3.first_name,", - " 'last_name', person_3.last_name,", - " 'age', person_3.age", + " 'first_name', person_5.first_name,", + " 'last_name', person_5.last_name,", + " 'age', person_5.age", " )", - " 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", + " FROM agreego.entity entity_3", + " JOIN agreego.organization organization_4 ON organization_4.id = entity_3.id", + " JOIN agreego.person person_5 ON person_5.id = organization_4.id", " WHERE", - " NOT entity_5.archived", - " AND order_1.customer_id = person_3.id", + " NOT entity_3.archived", + " AND order_2.customer_id = person_5.id", " )", " )), '[]'::jsonb)", - " FROM agreego.order order_1", - " JOIN agreego.entity entity_2 ON entity_2.id = order_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.order order_2 ON order_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", + " NOT entity_1.archived", "))))" ] ] @@ -2256,26 +2256,26 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT COALESCE(jsonb_agg(CASE", - " WHEN widget_1.kind = 'stock' THEN (jsonb_build_object(", - " 'id', entity_2.id,", - " 'type', entity_2.type,", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'kind', widget_1.kind", + " WHEN widget_2.kind = 'stock' THEN (jsonb_build_object(", + " 'id', entity_1.id,", + " 'type', entity_1.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'kind', widget_2.kind", " ))", - " WHEN widget_1.kind = 'tasks' THEN (jsonb_build_object(", - " 'id', entity_2.id,", - " 'type', entity_2.type,", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'kind', widget_1.kind", + " WHEN widget_2.kind = 'tasks' THEN (jsonb_build_object(", + " 'id', entity_1.id,", + " 'type', entity_1.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'kind', widget_2.kind", " ))", " ELSE NULL", " END), '[]'::jsonb)", - " FROM agreego.widget widget_1", - " JOIN agreego.entity entity_2 ON entity_2.id = widget_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.widget widget_2 ON widget_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", + " NOT entity_1.archived", "))))" ] ] @@ -2291,35 +2291,35 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT jsonb_build_object(", - " 'id', invoice_1.id,", - " 'type', invoice_1.type,", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'total', invoice_1.total,", + " 'id', invoice_2.id,", + " 'type', invoice_2.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'total', invoice_2.total,", " 'lines', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', invoice_line_3.id,", - " 'type', invoice_line_3.type,", - " 'archived', entity_4.archived,", - " 'created_at', entity_4.created_at,", - " 'invoice_id', invoice_line_3.invoice_id,", - " 'price', invoice_line_3.price", + " 'id', invoice_line_4.id,", + " 'type', invoice_line_4.type,", + " 'archived', entity_3.archived,", + " 'created_at', entity_3.created_at,", + " 'invoice_id', invoice_line_4.invoice_id,", + " 'price', invoice_line_4.price", " )), '[]'::jsonb)", - " FROM agreego.invoice_line invoice_line_3", - " JOIN agreego.entity entity_4 ON entity_4.id = invoice_line_3.id", + " FROM agreego.entity entity_3", + " JOIN agreego.invoice_line invoice_line_4 ON invoice_line_4.id = entity_3.id", " WHERE", - " NOT entity_4.archived", - " AND invoice_line_3.invoice_id = invoice_1.id", + " NOT entity_3.archived", + " AND invoice_line_4.invoice_id = invoice_2.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", + " 'metadata_line', invoice_2.metadata_line,", + " 'metadata_lines', invoice_2.metadata_lines,", + " 'metadata_nested_line', invoice_2.metadata_nested_line,", + " 'metadata_nested_lines', invoice_2.metadata_nested_lines", " )", - " FROM agreego.invoice invoice_1", - " JOIN agreego.entity entity_2 ON entity_2.id = invoice_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.invoice invoice_2 ON invoice_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", + " NOT entity_1.archived", "))))" ] ] @@ -2335,18 +2335,18 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT jsonb_build_object(", - " 'id', entity_2.id,", - " 'type', entity_2.type,", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'kind', account_1.kind,", - " 'routing_number', account_1.routing_number,", - " 'card_number', account_1.card_number", + " 'id', entity_1.id,", + " 'type', entity_1.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'kind', account_2.kind,", + " 'routing_number', account_2.routing_number,", + " 'card_number', account_2.card_number", " )", - " FROM agreego.account account_1", - " JOIN agreego.entity entity_2 ON entity_2.id = account_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.account account_2 ON account_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", + " NOT entity_1.archived", "))))" ] ] @@ -2362,77 +2362,77 @@ [ "((SELECT jsonb_strip_nulls((", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'id', order_1.id,", - " 'type', order_1.type,", - " 'archived', entity_2.archived,", - " 'created_at', entity_2.created_at,", - " 'total', order_1.total,", - " 'customer_id', order_1.customer_id,", + " 'id', order_2.id,", + " 'type', order_2.type,", + " 'archived', entity_1.archived,", + " 'created_at', entity_1.created_at,", + " 'total', order_2.total,", + " 'customer_id', order_2.customer_id,", " 'counterparty', (", " SELECT CASE", - " WHEN organization_3.type = 'bot' THEN ((", + " WHEN organization_4.type = 'bot' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_7.id,", - " 'type', entity_7.type,", - " 'archived', entity_7.archived,", - " 'created_at', entity_7.created_at,", + " 'id', entity_5.id,", + " 'type', entity_5.type,", + " 'archived', entity_5.archived,", + " 'created_at', entity_5.created_at,", " 'name', organization_6.name,", - " 'token', bot_5.token,", - " 'role', bot_5.role", + " 'token', bot_7.token,", + " 'role', bot_7.role", " )", - " FROM agreego.bot bot_5", - " JOIN agreego.organization organization_6 ON organization_6.id = bot_5.id", - " JOIN agreego.entity entity_7 ON entity_7.id = organization_6.id", + " FROM agreego.entity entity_5", + " JOIN agreego.organization organization_6 ON organization_6.id = entity_5.id", + " JOIN agreego.bot bot_7 ON bot_7.id = organization_6.id", " WHERE", - " NOT entity_7.archived", - " AND entity_7.id = entity_4.id", + " NOT entity_5.archived", + " AND entity_5.id = entity_3.id", " ))", - " WHEN organization_3.type = 'organization' THEN ((", + " WHEN organization_4.type = 'organization' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_9.id,", - " 'type', entity_9.type,", - " 'archived', entity_9.archived,", - " 'created_at', entity_9.created_at,", - " 'name', organization_8.name", + " 'id', entity_8.id,", + " 'type', entity_8.type,", + " 'archived', entity_8.archived,", + " 'created_at', entity_8.created_at,", + " 'name', organization_9.name", " )", - " FROM agreego.organization organization_8", - " JOIN agreego.entity entity_9 ON entity_9.id = organization_8.id", + " FROM agreego.entity entity_8", + " JOIN agreego.organization organization_9 ON organization_9.id = entity_8.id", " WHERE", - " NOT entity_9.archived", - " AND entity_9.id = entity_4.id", + " NOT entity_8.archived", + " AND entity_8.id = entity_3.id", " ))", - " WHEN organization_3.type = 'person' THEN ((", + " WHEN organization_4.type = 'person' THEN ((", " SELECT jsonb_build_object(", - " 'id', entity_12.id,", - " 'type', entity_12.type,", - " 'archived', entity_12.archived,", - " 'created_at', entity_12.created_at,", + " 'id', entity_10.id,", + " 'type', entity_10.type,", + " 'archived', entity_10.archived,", + " 'created_at', entity_10.created_at,", " 'name', organization_11.name,", - " 'first_name', person_10.first_name,", - " 'last_name', person_10.last_name,", - " 'age', person_10.age", + " 'first_name', person_12.first_name,", + " 'last_name', person_12.last_name,", + " 'age', person_12.age", " )", - " FROM agreego.person person_10", - " JOIN agreego.organization organization_11 ON organization_11.id = person_10.id", - " JOIN agreego.entity entity_12 ON entity_12.id = organization_11.id", + " FROM agreego.entity entity_10", + " JOIN agreego.organization organization_11 ON organization_11.id = entity_10.id", + " JOIN agreego.person person_12 ON person_12.id = organization_11.id", " WHERE", - " NOT entity_12.archived", - " AND entity_12.id = entity_4.id", + " NOT entity_10.archived", + " AND entity_10.id = entity_3.id", " ))", " ELSE NULL", " END", - " FROM agreego.organization organization_3", - " JOIN agreego.entity entity_4 ON entity_4.id = organization_3.id", + " FROM agreego.entity entity_3", + " JOIN agreego.organization organization_4 ON organization_4.id = entity_3.id", " WHERE", - " NOT entity_4.archived", - " AND order_1.counterparty_id = entity_4.id", + " NOT entity_3.archived", + " AND order_2.counterparty_id = entity_3.id", " )", " )), '[]'::jsonb)", - " FROM agreego.order order_1", - " JOIN agreego.entity entity_2 ON entity_2.id = order_1.id", + " FROM agreego.entity entity_1", + " JOIN agreego.order order_2 ON order_2.id = entity_1.id", " WHERE", - " NOT entity_2.archived", - " AND order_1.counterparty_type IN ('bot', 'organization', 'person')", + " NOT entity_1.archived", + " AND order_2.counterparty_type IN ('bot', 'organization', 'person')", "))))" ] ] diff --git a/src/merger/mod.rs b/src/merger/mod.rs index 66e90f1..78427c5 100644 --- a/src/merger/mod.rs +++ b/src/merger/mod.rs @@ -792,7 +792,7 @@ impl Merger { }; for table_name in &entity_type.hierarchy { - let table_fields = match grouped_fields.get(&table_name).and_then(|v| v.as_array()) { + let table_fields = match grouped_fields.get(table_name).and_then(|v| v.as_array()) { Some(arr) => arr .iter() .filter_map(|v| v.as_str().map(|s| s.to_string())) diff --git a/src/tests/mod.rs b/src/tests/mod.rs index a02c0a3..977112a 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -44,7 +44,7 @@ fn test_library_api() { { "name": "source_schema", "variations": ["source_schema"], - "hierarchy": ["source_schema", "entity"], + "hierarchy": ["entity", "source_schema"], "schemas": { "source_schema": { "type": "object", @@ -60,7 +60,7 @@ fn test_library_api() { { "name": "target_schema", "variations": ["target_schema"], - "hierarchy": ["target_schema", "entity"], + "hierarchy": ["entity", "target_schema"], "schemas": { "target_schema": { "type": "object", @@ -109,7 +109,7 @@ fn test_library_api() { "field_types": null, "fields": [], "grouped_fields": null, - "hierarchy": ["source_schema", "entity"], + "hierarchy": ["entity", "source_schema"], "historical": false, "id": "", "longevity": null, @@ -174,7 +174,7 @@ fn test_library_api() { "field_types": null, "fields": [], "grouped_fields": null, - "hierarchy": ["target_schema", "entity"], + "hierarchy": ["entity", "target_schema"], "historical": false, "id": "", "longevity": null,