Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| abf1d12e43 | |||
| a885713563 | |||
| d9b4f417f6 | |||
| eae39f92d6 | |||
| 2895f06074 | |||
| c1c16bc814 | |||
| 5885552192 | |||
| dc033296d7 | |||
| 03a871bc1a | |||
| 8aa15873b0 | |||
| 0d282cc930 | |||
| 581fc8e0c0 | |||
| 6f0bff8dc7 | |||
| 99c69e27ab |
@ -87,6 +87,34 @@
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schedule": {
|
||||
"type": [
|
||||
"opening_hours",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"season": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"label": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"opening_hours": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"open": {
|
||||
"type": "string"
|
||||
},
|
||||
"seasons": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "season"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -262,6 +290,7 @@
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"schedule",
|
||||
"$and",
|
||||
"$or"
|
||||
],
|
||||
@ -277,6 +306,7 @@
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"schedule",
|
||||
"$and",
|
||||
"$or"
|
||||
],
|
||||
@ -298,6 +328,7 @@
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"schedule",
|
||||
"$and",
|
||||
"$or"
|
||||
],
|
||||
@ -366,6 +397,12 @@
|
||||
"string.condition",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"schedule": {
|
||||
"type": [
|
||||
"opening_hours.filter",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "filter"
|
||||
@ -483,7 +520,63 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"opening_hours": {},
|
||||
"season": {},
|
||||
"opening_hours.filter": {
|
||||
"type": "filter",
|
||||
"compiledPropertyNames": [
|
||||
"open",
|
||||
"seasons",
|
||||
"$and",
|
||||
"$or"
|
||||
],
|
||||
"properties": {
|
||||
"open": {
|
||||
"type": [
|
||||
"string.condition",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"seasons": {
|
||||
"type": [
|
||||
"season.filter",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"$and": {
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
],
|
||||
"items": {
|
||||
"type": "opening_hours.filter",
|
||||
"compiledPropertyNames": [
|
||||
"open",
|
||||
"seasons",
|
||||
"$and",
|
||||
"$or"
|
||||
]
|
||||
}
|
||||
},
|
||||
"$or": {
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
],
|
||||
"items": {
|
||||
"type": "opening_hours.filter",
|
||||
"compiledPropertyNames": [
|
||||
"open",
|
||||
"seasons",
|
||||
"$and",
|
||||
"$or"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"season.filter": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1320,62 +1320,17 @@
|
||||
" AND \"pronouns\" = 'they/them'))"
|
||||
],
|
||||
[
|
||||
"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'",
|
||||
")"
|
||||
"UPDATE agreego.\"person\" SET",
|
||||
" contact_id = 'abc-contact'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1388,45 +1343,40 @@
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" }',",
|
||||
" '{",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" '{{uuid:generated_1}}',",
|
||||
" 'create',",
|
||||
" 'update',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"kind\": \"update\",",
|
||||
" \"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\"",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
@ -1461,75 +1411,20 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"organization\" t2 ON ",
|
||||
"JOIN agreego.\"user\" t3 ON ",
|
||||
"JOIN agreego.\"person\" t4 ON ",
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE t1.id = '{{uuid:data.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE (\"first_name\" = 'LookupFirst' AND \"last_name\" = 'LookupLast' AND \"date_of_birth\" = '{{timestamp}}' AND \"pronouns\" = 'they/them'))"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"entity\" SET",
|
||||
" modified_at = '{{timestamp}}',",
|
||||
" modified_by = '00000000-0000-0000-0000-000000000000'",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.id}}'",
|
||||
" OR (\"first_name\" = 'LookupFirst'",
|
||||
" AND \"last_name\" = 'LookupLast'",
|
||||
" AND \"date_of_birth\" = '{{timestamp}}'",
|
||||
" AND \"pronouns\" = 'they/them'))"
|
||||
" 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'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"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'",
|
||||
")"
|
||||
"UPDATE agreego.\"person\" SET",
|
||||
" contact_id = 'abc-contact'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1542,46 +1437,42 @@
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" }',",
|
||||
" '{",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" '{{uuid:data.id}}',",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" 'update',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"kind\": \"update\",",
|
||||
" \"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}}\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -1614,122 +1505,26 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"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'",
|
||||
" AND \"last_name\" = 'LookupLast'",
|
||||
" AND \"date_of_birth\" = '{{timestamp}}'",
|
||||
" AND \"pronouns\" = 'they/them'))"
|
||||
],
|
||||
[
|
||||
"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\",",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" '{{uuid:data.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE t1.id = '{{uuid:data.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE (\"first_name\" = 'LookupFirst' AND \"last_name\" = 'LookupLast' AND \"date_of_birth\" = '{{timestamp}}' AND \"pronouns\" = 'they/them'))"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"kind\": \"replace\",",
|
||||
" \"complete\": {",
|
||||
" \"id\": \"{{uuid:mocks.0.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"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}}\",",
|
||||
" \"contact_id\": \"old-contact\",",
|
||||
" \"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}}\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -1766,56 +1561,18 @@
|
||||
" t1.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'",
|
||||
")"
|
||||
"UPDATE agreego.\"person\" SET",
|
||||
" first_name = 'NewFirst',",
|
||||
" last_name = 'NewLast'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1828,7 +1585,10 @@
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"first_name\": \"OldFirst\",",
|
||||
" \"last_name\": \"OldLast\"",
|
||||
" }',",
|
||||
" '{",
|
||||
" \"first_name\": \"NewFirst\",",
|
||||
" \"last_name\": \"NewLast\",",
|
||||
@ -1836,21 +1596,19 @@
|
||||
" }',",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" 'update',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"kind\": \"update\",",
|
||||
" \"complete\": {",
|
||||
" \"first_name\": \"NewFirst\",",
|
||||
" \"last_name\": \"NewLast\",",
|
||||
" \"id\": \"{{uuid:mocks.0.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"created_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"created_at\": \"{{timestamp}}\",",
|
||||
" \"first_name\": \"NewFirst\",",
|
||||
" \"last_name\": \"NewLast\",",
|
||||
" \"modified_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"modified_at\": \"{{timestamp}}\"",
|
||||
" },",
|
||||
@ -1858,6 +1616,10 @@
|
||||
" \"first_name\": \"NewFirst\",",
|
||||
" \"last_name\": \"NewLast\",",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"old\": {",
|
||||
" \"first_name\": \"OldFirst\",",
|
||||
" \"last_name\": \"OldLast\"",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
@ -2219,12 +1981,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"order\" t2 ON ",
|
||||
"WHERE",
|
||||
" t1.id = 'abc'",
|
||||
" OR (\"id\" = 'abc'))"
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"order\" t2 ON t2.id = t1.id WHERE t1.id = 'abc' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"order\" t2 ON t2.id = t1.id WHERE (\"id\" = 'abc'))"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
@ -3031,54 +2788,12 @@
|
||||
" t1.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'",
|
||||
")"
|
||||
"UPDATE agreego.\"entity\" SET",
|
||||
" archived = true,",
|
||||
" modified_at = '{{timestamp}}',",
|
||||
" modified_by = '00000000-0000-0000-0000-000000000000'",
|
||||
"WHERE",
|
||||
" id = 'abc-archived'"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -3091,33 +2806,38 @@
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"archived\": false",
|
||||
" }',",
|
||||
" '{",
|
||||
" \"archived\": true,",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" 'abc-archived',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" 'delete',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"kind\": \"delete\",",
|
||||
" \"complete\": {",
|
||||
" \"archived\": true,",
|
||||
" \"id\": \"abc-archived\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"created_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"created_at\": \"{{timestamp}}\",",
|
||||
" \"first_name\": \"ArchivedFirst\",",
|
||||
" \"last_name\": \"ArchivedLast\",",
|
||||
" \"archived\": true,",
|
||||
" \"modified_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"modified_at\": \"{{timestamp}}\"",
|
||||
" },",
|
||||
" \"new\": {",
|
||||
" \"archived\": true,",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"old\": {",
|
||||
" \"archived\": false",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
@ -3499,12 +3219,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"invoice\" t2 ON ",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.id}}'",
|
||||
" OR (\"id\" = '{{uuid:data.id}}'))"
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"invoice\" t2 ON t2.id = t1.id WHERE t1.id = '{{uuid:data.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"invoice\" t2 ON t2.id = t1.id WHERE (\"id\" = '{{uuid:data.id}}'))"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
@ -4057,6 +3772,143 @@
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Existence probes hit the same row via id and lookup key (dedup, updates)",
|
||||
"action": "merge",
|
||||
"data": {
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"type": "person",
|
||||
"first_name": "LookupFirst",
|
||||
"last_name": "LookupLast",
|
||||
"date_of_birth": "1990-01-01T00:00:00Z",
|
||||
"pronouns": "they/them",
|
||||
"contact_id": "new-contact"
|
||||
},
|
||||
"mocks": [
|
||||
{
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"type": "person",
|
||||
"first_name": "LookupFirst",
|
||||
"last_name": "LookupLast",
|
||||
"date_of_birth": "1990-01-01T00:00:00Z",
|
||||
"pronouns": "they/them",
|
||||
"contact_id": "old-contact"
|
||||
}
|
||||
],
|
||||
"schema_id": "person",
|
||||
"expect": {
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE t1.id = '{{uuid:mocks.0.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE (\"first_name\" = 'LookupFirst' AND \"last_name\" = 'LookupLast' AND \"date_of_birth\" = '{{timestamp}}' AND \"pronouns\" = 'they/them'))"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"entity\" SET",
|
||||
" modified_at = '{{timestamp}}',",
|
||||
" modified_by = '00000000-0000-0000-0000-000000000000'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"person\" SET",
|
||||
" contact_id = 'new-contact'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
" \"old\",",
|
||||
" \"new\",",
|
||||
" \"entity_id\",",
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" }',",
|
||||
" '{",
|
||||
" \"contact_id\": \"new-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'update',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"update\",",
|
||||
" \"complete\": {",
|
||||
" \"id\": \"{{uuid:mocks.0.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"new-contact\",",
|
||||
" \"modified_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"modified_at\": \"{{timestamp}}\"",
|
||||
" },",
|
||||
" \"new\": {",
|
||||
" \"contact_id\": \"new-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"old\": {",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Id probe and lookup probe find different rows (TOO_MANY_LOOKUP_ROWS)",
|
||||
"action": "merge",
|
||||
"data": {
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"type": "person",
|
||||
"first_name": "OtherFirst",
|
||||
"last_name": "OtherLast",
|
||||
"date_of_birth": "1991-02-02T00:00:00Z",
|
||||
"pronouns": "she/her"
|
||||
},
|
||||
"mocks": [
|
||||
{
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"type": "person",
|
||||
"first_name": "LookupFirst",
|
||||
"last_name": "LookupLast",
|
||||
"date_of_birth": "1990-01-01T00:00:00Z",
|
||||
"pronouns": "they/them"
|
||||
},
|
||||
{
|
||||
"id": "44444444-4444-4444-4444-444444444444",
|
||||
"type": "person",
|
||||
"first_name": "OtherFirst",
|
||||
"last_name": "OtherLast",
|
||||
"date_of_birth": "1991-02-02T00:00:00Z",
|
||||
"pronouns": "she/her"
|
||||
}
|
||||
],
|
||||
"schema_id": "person",
|
||||
"expect": {
|
||||
"success": false,
|
||||
"errors": [
|
||||
{
|
||||
"code": "MERGE_FAILED",
|
||||
"values": {
|
||||
"error": "TOO_MANY_LOOKUP_ROWS: Lookup for person found too many existing rows"
|
||||
},
|
||||
"details": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -151,6 +151,7 @@ impl Schema {
|
||||
"number" => Some(vec!["number.condition".to_string()]),
|
||||
"boolean" => Some(vec!["boolean.condition".to_string()]),
|
||||
"object" => None, // Inline structures are ignored in Composed References
|
||||
"dict" => None, // Dynamic dictionary maps are ignored in Composed References
|
||||
"array" => {
|
||||
if let Some(items) = &schema.obj.items {
|
||||
return Self::resolve_filter_type(items, db);
|
||||
@ -164,8 +165,20 @@ impl Schema {
|
||||
} else if db.enums.contains_key(custom) {
|
||||
Some(vec![format!("{}.condition", custom)])
|
||||
} else {
|
||||
// Assume anything else is a Relational cross-boundary that already has its own .filter dynamically built
|
||||
Some(vec![format!("{}.filter", custom)])
|
||||
// A named type gets a reference to its dynamically built .filter — either a
|
||||
// Relational cross-boundary (table-backed) or a named value type, whose filter
|
||||
// is likewise synthesized (see Database::compile_filters). A named type with no
|
||||
// compilable structure gets no filter — omit it rather than dangle a reference.
|
||||
let base = custom.split('.').next_back().unwrap_or(custom);
|
||||
let has_value_filter = db
|
||||
.schemas
|
||||
.get(custom)
|
||||
.map_or(false, |s| Database::is_value_filter_candidate(custom, s));
|
||||
if db.types.contains_key(base) || has_value_filter {
|
||||
Some(vec![format!("{}.filter", custom)])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,6 +125,7 @@ impl Schema {
|
||||
child.compile(db, root_id, format!("{}/{}", path, k), errors);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(items) = &self.obj.items {
|
||||
items.compile(db, root_id, format!("{}/items", path), errors);
|
||||
}
|
||||
@ -138,6 +139,7 @@ impl Schema {
|
||||
if let Some(child) = &self.obj.not {
|
||||
child.compile(db, root_id, format!("{}/not", path), errors);
|
||||
}
|
||||
|
||||
if let Some(child) = &self.obj.contains {
|
||||
child.compile(db, root_id, format!("{}/contains", path), errors);
|
||||
}
|
||||
|
||||
@ -116,99 +116,17 @@ fn parse_and_match_mocks(sql: &str, mocks: &[Value]) -> Option<Vec<Value>> {
|
||||
return None;
|
||||
}
|
||||
|
||||
// 1. Extract table name
|
||||
let table_regex = Regex::new(r#"(?i)\s+FROM\s+(?:[a-zA-Z_]\w*\.)?"?([a-zA-Z_]\w*)"?"#).ok()?;
|
||||
let table = if let Some(caps) = table_regex.captures(sql) {
|
||||
caps.get(1)?.as_str()
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
// The merger's existence read emits one SELECT per probe (id / lookup key)
|
||||
// joined by UNION. Match each arm independently against its own tables and
|
||||
// WHERE clause; a mock matching any arm is returned once, mirroring UNION's
|
||||
// dedup semantics.
|
||||
let union_regex = Regex::new(r"(?i)\s+UNION\s+(?:ALL\s+)?").ok()?;
|
||||
let arms: Vec<&str> = union_regex.split(sql).collect();
|
||||
|
||||
// 2. Extract WHERE conditions string
|
||||
let mut where_clause = String::new();
|
||||
if let Some(where_idx) = sql_upper.find(" WHERE ") {
|
||||
let mut where_end = sql_upper.find(" ORDER BY ").unwrap_or(sql_upper.len());
|
||||
if let Some(limit_idx) = sql_upper.find(" LIMIT ") {
|
||||
if limit_idx < where_end {
|
||||
where_end = limit_idx;
|
||||
}
|
||||
}
|
||||
where_clause = sql[where_idx + 7..where_end].to_string();
|
||||
}
|
||||
|
||||
// 3. Find matching mocks
|
||||
let mut matches = Vec::new();
|
||||
let or_regex = Regex::new(r"(?i)\s+OR\s+").ok()?;
|
||||
let and_regex = Regex::new(r"(?i)\s+AND\s+").ok()?;
|
||||
|
||||
for mock in mocks {
|
||||
if let Some(mock_obj) = mock.as_object() {
|
||||
if let Some(t) = mock_obj.get("type") {
|
||||
if t.as_str() != Some(table) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if where_clause.is_empty() {
|
||||
matches.push(mock.clone());
|
||||
continue;
|
||||
}
|
||||
|
||||
let or_parts = or_regex.split(&where_clause);
|
||||
let mut any_branch_matched = false;
|
||||
|
||||
for or_part in or_parts {
|
||||
let branch_str = or_part.replace('(', "").replace(')', "");
|
||||
let mut branch_matches = true;
|
||||
|
||||
for part in and_regex.split(&branch_str) {
|
||||
if let Some(eq_idx) = part.find('=') {
|
||||
let left = part[..eq_idx]
|
||||
.trim()
|
||||
.split('.')
|
||||
.last()
|
||||
.unwrap_or("")
|
||||
.trim_matches('"');
|
||||
let right = part[eq_idx + 1..].trim().trim_matches('\'');
|
||||
|
||||
let mock_val_str = match mock_obj.get(left) {
|
||||
Some(Value::String(s)) => s.clone(),
|
||||
Some(Value::Number(n)) => n.to_string(),
|
||||
Some(Value::Bool(b)) => b.to_string(),
|
||||
Some(Value::Null) => "null".to_string(),
|
||||
_ => "".to_string(),
|
||||
};
|
||||
if mock_val_str != right {
|
||||
branch_matches = false;
|
||||
break;
|
||||
}
|
||||
} else if part.to_uppercase().contains(" IS NULL") {
|
||||
let left = part[..part.to_uppercase().find(" IS NULL").unwrap()]
|
||||
.trim()
|
||||
.split('.')
|
||||
.last()
|
||||
.unwrap_or("")
|
||||
.trim_matches('"');
|
||||
|
||||
let mock_val_str = match mock_obj.get(left) {
|
||||
Some(Value::Null) => "null".to_string(),
|
||||
_ => "".to_string(),
|
||||
};
|
||||
|
||||
if mock_val_str != "null" {
|
||||
branch_matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if branch_matches {
|
||||
any_branch_matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if any_branch_matched {
|
||||
if arms.iter().any(|arm| arm_matches_mock(arm, mock_obj)) {
|
||||
matches.push(mock.clone());
|
||||
}
|
||||
}
|
||||
@ -216,3 +134,103 @@ fn parse_and_match_mocks(sql: &str, mocks: &[Value]) -> Option<Vec<Value>> {
|
||||
|
||||
Some(matches)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn arm_matches_mock(arm: &str, mock_obj: &serde_json::Map<String, Value>) -> bool {
|
||||
let arm_upper = arm.to_uppercase();
|
||||
|
||||
// 1. The mock's type must name one of the arm's tables. Hierarchy reads
|
||||
// SELECT FROM the root (entity) and JOIN the subtype tables, so every
|
||||
// FROM/JOIN table counts, not just the first.
|
||||
let table_regex = match Regex::new(r#"(?i)\b(?:FROM|JOIN)\s+(?:[a-zA-Z_]\w*\.)?"?([a-zA-Z_]\w*)"?"#) {
|
||||
Ok(r) => r,
|
||||
Err(_) => return false,
|
||||
};
|
||||
let tables: Vec<&str> = table_regex.captures_iter(arm).filter_map(|c| c.get(1)).map(|m| m.as_str()).collect();
|
||||
if tables.is_empty() {
|
||||
return false;
|
||||
}
|
||||
if let Some(t) = mock_obj.get("type") {
|
||||
if !tables.iter().any(|table| t.as_str() == Some(table)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Extract this arm's WHERE conditions
|
||||
let mut where_clause = String::new();
|
||||
if let Some(where_idx) = arm_upper.find(" WHERE ") {
|
||||
let mut where_end = arm_upper.find(" ORDER BY ").unwrap_or(arm_upper.len());
|
||||
if let Some(limit_idx) = arm_upper.find(" LIMIT ") {
|
||||
if limit_idx < where_end {
|
||||
where_end = limit_idx;
|
||||
}
|
||||
}
|
||||
where_clause = arm[where_idx + 7..where_end].to_string();
|
||||
}
|
||||
|
||||
if where_clause.is_empty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Match the mock against the conditions
|
||||
let or_regex = match Regex::new(r"(?i)\s+OR\s+") {
|
||||
Ok(r) => r,
|
||||
Err(_) => return false,
|
||||
};
|
||||
let and_regex = match Regex::new(r"(?i)\s+AND\s+") {
|
||||
Ok(r) => r,
|
||||
Err(_) => return false,
|
||||
};
|
||||
|
||||
for or_part in or_regex.split(&where_clause) {
|
||||
let branch_str = or_part.replace('(', "").replace(')', "");
|
||||
let mut branch_matches = true;
|
||||
|
||||
for part in and_regex.split(&branch_str) {
|
||||
if let Some(eq_idx) = part.find('=') {
|
||||
let left = part[..eq_idx]
|
||||
.trim()
|
||||
.split('.')
|
||||
.last()
|
||||
.unwrap_or("")
|
||||
.trim_matches('"');
|
||||
let right = part[eq_idx + 1..].trim().trim_matches('\'');
|
||||
|
||||
let mock_val_str = match mock_obj.get(left) {
|
||||
Some(Value::String(s)) => s.clone(),
|
||||
Some(Value::Number(n)) => n.to_string(),
|
||||
Some(Value::Bool(b)) => b.to_string(),
|
||||
Some(Value::Null) => "null".to_string(),
|
||||
_ => "".to_string(),
|
||||
};
|
||||
if mock_val_str != right {
|
||||
branch_matches = false;
|
||||
break;
|
||||
}
|
||||
} else if part.to_uppercase().contains(" IS NULL") {
|
||||
let left = part[..part.to_uppercase().find(" IS NULL").unwrap()]
|
||||
.trim()
|
||||
.split('.')
|
||||
.last()
|
||||
.unwrap_or("")
|
||||
.trim_matches('"');
|
||||
|
||||
let mock_val_str = match mock_obj.get(left) {
|
||||
Some(Value::Null) => "null".to_string(),
|
||||
_ => "".to_string(),
|
||||
};
|
||||
|
||||
if mock_val_str != "null" {
|
||||
branch_matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if branch_matches {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
@ -262,15 +262,23 @@ impl Database {
|
||||
}
|
||||
}
|
||||
|
||||
/// Synthesizes Composed Filter References for all table-backed boundaries.
|
||||
/// Synthesizes Composed Filter References for all table-backed boundaries — and for
|
||||
/// named non-table value types (schema-only objects, e.g. an operating-hours config),
|
||||
/// so a property reference resolves to ONE named filter instead of inlining anonymous
|
||||
/// per-path copies (which duplicate identical leaf type names for downstream codegen).
|
||||
fn compile_filters(&mut self, errors: &mut Vec<crate::drop::Error>) -> Vec<(String, String)> {
|
||||
let mut filter_schemas = Vec::new();
|
||||
let mut seen_value_ids = std::collections::HashSet::new();
|
||||
for (type_name, type_def) in &self.types {
|
||||
for (id, schema_arc) in &type_def.schemas {
|
||||
// Only run synthesis on actual structured, table-backed boundaries. Exclude subschemas!
|
||||
// Run synthesis on structured table-backed boundaries and named value types.
|
||||
// Exclude subschemas!
|
||||
let base_name = id.split('.').last().unwrap_or(id);
|
||||
let is_table_backed = base_name == type_def.name;
|
||||
if is_table_backed && !id.contains('/') {
|
||||
let is_value_type = !is_table_backed
|
||||
&& Self::is_value_filter_candidate(id, schema_arc)
|
||||
&& seen_value_ids.insert(id.clone());
|
||||
if (is_table_backed || is_value_type) && !id.contains('/') {
|
||||
if let Some(filter_schema) = schema_arc.compile_filter(self, id, errors) {
|
||||
filter_schemas.push((
|
||||
type_name.clone(),
|
||||
@ -293,6 +301,20 @@ impl Database {
|
||||
filter_ids
|
||||
}
|
||||
|
||||
/// A named non-table value type that earns its own synthesized filter: a bare-named
|
||||
/// (dotless) schema-only object with compiled properties. The base `filter`/`condition`
|
||||
/// schemas are infrastructure, not value types.
|
||||
pub fn is_value_filter_candidate(id: &str, schema: &Arc<Schema>) -> bool {
|
||||
!id.contains('.')
|
||||
&& id != "filter"
|
||||
&& id != "condition"
|
||||
&& schema
|
||||
.obj
|
||||
.compiled_properties
|
||||
.get()
|
||||
.map_or(false, |props| !props.is_empty())
|
||||
}
|
||||
|
||||
/// Synthesizes strong Enum Conditions mirroring the string.condition capabilities.
|
||||
fn compile_conditions(&mut self) -> Vec<(String, String)> {
|
||||
let mut enum_conditions = Vec::new();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
use crate::database::action::Action;
|
||||
use indexmap::IndexMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(default)]
|
||||
@ -13,6 +14,11 @@ pub struct Page {
|
||||
pub sidebar: Option<Sidebar>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub actions: Option<IndexMap<String, Action>>,
|
||||
/// The personal-scope filter template ("one surface, two scopes"): the
|
||||
/// "mine" predicate the page merges into its filter when the app is in
|
||||
/// personal scope, e.g. {"reserved_by": "$me"}. Opaque to the engine.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub personal: Option<Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
@ -22,4 +28,6 @@ pub struct Sidebar {
|
||||
pub category: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub priority: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub icon: Option<String>,
|
||||
}
|
||||
|
||||
@ -744,9 +744,19 @@ impl Merger {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let where_clause = format!("WHERE {}", where_parts.join(" OR "));
|
||||
|
||||
let final_sql = format!("{} {}", fetch_sql_template, where_clause);
|
||||
// An OR across the hierarchy join is un-indexable — it forces a full scan
|
||||
// of the subtype table on every child merge. UNION lets each arm use its
|
||||
// own index (pk for the id arm, the lk_ unique index for the lookup arm)
|
||||
// and still dedups, so TOO_MANY_LOOKUP_ROWS semantics are preserved.
|
||||
let final_sql = if where_parts.len() == 1 {
|
||||
format!("{} WHERE {}", fetch_sql_template, where_parts[0])
|
||||
} else {
|
||||
where_parts
|
||||
.iter()
|
||||
.map(|p| format!("{} WHERE {}", fetch_sql_template, p))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" UNION ")
|
||||
};
|
||||
|
||||
let fetched = match self.db.query(&final_sql, None) {
|
||||
Ok(Value::Array(table)) => {
|
||||
|
||||
@ -7660,3 +7660,15 @@ fn test_merger_0_15() {
|
||||
let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 15).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_merger_0_16() {
|
||||
let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 16).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_merger_0_17() {
|
||||
let path = format!("{}/fixtures/merger.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 17).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user