added explicit lookup_fields to entity types
This commit is contained in:
@ -911,9 +911,7 @@
|
||||
"archived"
|
||||
]
|
||||
},
|
||||
"lookup_fields": [
|
||||
"id"
|
||||
],
|
||||
"lookup_fields": [],
|
||||
"historical": true,
|
||||
"relationship": false,
|
||||
"field_types": {
|
||||
@ -1018,5 +1016,100 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Validation - lookup fields without matching index",
|
||||
"database": {
|
||||
"types": [
|
||||
{
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"type": "type",
|
||||
"name": "user",
|
||||
"module": "test",
|
||||
"source": "test",
|
||||
"hierarchy": ["user"],
|
||||
"variations": ["user"],
|
||||
"fields": ["id", "email"],
|
||||
"lookup_fields": ["email"],
|
||||
"schemas": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": { "type": "string", "format": "uuid" },
|
||||
"email": { "type": "string", "format": "email" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "Fails setup compilation with MISSING_LOOKUP_INDEX if unique index is missing",
|
||||
"action": "compile",
|
||||
"expect": {
|
||||
"success": false,
|
||||
"errors": [
|
||||
{
|
||||
"code": "MISSING_LOOKUP_INDEX",
|
||||
"values": {
|
||||
"type": "user",
|
||||
"lookup_fields": "[\"email\"]"
|
||||
},
|
||||
"details": {
|
||||
"path": "/types/user",
|
||||
"schema": "user"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Validation - lookup fields with matching index",
|
||||
"database": {
|
||||
"indexes": [
|
||||
{
|
||||
"table": "user",
|
||||
"columns": ["email"]
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"type": "type",
|
||||
"name": "user",
|
||||
"module": "test",
|
||||
"source": "test",
|
||||
"hierarchy": ["user"],
|
||||
"variations": ["user"],
|
||||
"fields": ["id", "email"],
|
||||
"lookup_fields": ["email"],
|
||||
"schemas": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": { "type": "string", "format": "uuid" },
|
||||
"email": { "type": "string", "format": "email" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "Compiles successfully when unique index matches lookup_fields",
|
||||
"action": "compile",
|
||||
"expect": {
|
||||
"success": true,
|
||||
"schemas": {
|
||||
"user": {},
|
||||
"user.filter": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -117,6 +117,16 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"indexes": [
|
||||
{
|
||||
"table": "person",
|
||||
"columns": ["first_name", "last_name", "date_of_birth", "pronouns"]
|
||||
},
|
||||
{
|
||||
"table": "user",
|
||||
"columns": ["name"]
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"name": "entity",
|
||||
@ -296,7 +306,9 @@
|
||||
"archived"
|
||||
]
|
||||
},
|
||||
"lookup_fields": [],
|
||||
"lookup_fields": [
|
||||
"name"
|
||||
],
|
||||
"historical": true,
|
||||
"notify": true,
|
||||
"relationship": false
|
||||
@ -478,9 +490,7 @@
|
||||
"organization_id"
|
||||
]
|
||||
},
|
||||
"lookup_fields": [
|
||||
"id"
|
||||
],
|
||||
"lookup_fields": [],
|
||||
"historical": true,
|
||||
"notify": true,
|
||||
"relationship": false
|
||||
@ -1068,9 +1078,7 @@
|
||||
"archived"
|
||||
]
|
||||
},
|
||||
"lookup_fields": [
|
||||
"id"
|
||||
],
|
||||
"lookup_fields": [],
|
||||
"historical": true,
|
||||
"relationship": false,
|
||||
"field_types": {
|
||||
@ -1593,6 +1601,180 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Update existing person with id and multiple inherited lookup keys",
|
||||
"action": "merge",
|
||||
"data": {
|
||||
"id": "33333333-3333-3333-3333-333333333333",
|
||||
"type": "person",
|
||||
"name": "LookupName",
|
||||
"first_name": "LookupFirst",
|
||||
"last_name": "LookupLast",
|
||||
"date_of_birth": "1990-01-01T00:00:00Z",
|
||||
"pronouns": "they/them",
|
||||
"contact_id": "abc-contact"
|
||||
},
|
||||
"mocks": [
|
||||
{
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"type": "person",
|
||||
"name": "LookupName",
|
||||
"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: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')",
|
||||
"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",
|
||||
" (\"name\" = 'LookupName'))"
|
||||
],
|
||||
[
|
||||
"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\",",
|
||||
" \"name\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'LookupName',",
|
||||
" '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 (",
|
||||
" \"old\",",
|
||||
" \"new\",",
|
||||
" \"entity_id\",",
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"name\": \"LookupName\",",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" '{{uuid:data.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"name\": \"LookupName\",",
|
||||
" \"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\": {",
|
||||
" \"name\": \"LookupName\",",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Replace existing person with id and no changes (lookup)",
|
||||
"action": "merge",
|
||||
@ -2235,12 +2417,7 @@
|
||||
"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'))"
|
||||
" t1.id = 'abc')"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
@ -3519,12 +3696,7 @@
|
||||
"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}}'))"
|
||||
" t1.id = '{{uuid:data.id}}')"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
|
||||
@ -258,9 +258,7 @@
|
||||
"name": "text",
|
||||
"created_at": "timestamptz"
|
||||
},
|
||||
"lookup_fields": [
|
||||
"id"
|
||||
],
|
||||
"lookup_fields": [],
|
||||
"null_fields": [],
|
||||
"default_fields": [
|
||||
"id",
|
||||
@ -806,9 +804,7 @@
|
||||
"archived"
|
||||
]
|
||||
},
|
||||
"lookup_fields": [
|
||||
"id"
|
||||
],
|
||||
"lookup_fields": [],
|
||||
"historical": true,
|
||||
"relationship": false,
|
||||
"field_types": {
|
||||
@ -1106,9 +1102,7 @@
|
||||
"archived"
|
||||
]
|
||||
},
|
||||
"lookup_fields": [
|
||||
"id"
|
||||
],
|
||||
"lookup_fields": [],
|
||||
"historical": true,
|
||||
"relationship": false,
|
||||
"field_types": {
|
||||
|
||||
Reference in New Issue
Block a user