2061 lines
89 KiB
JSON
2061 lines
89 KiB
JSON
[
|
|
{
|
|
"description": "Merger Execution",
|
|
"database": {
|
|
"puncs": [],
|
|
"enums": [
|
|
{
|
|
"id": "11111111-1111-1111-1111-111111111111",
|
|
"type": "relation_type",
|
|
"enum": "relation_type",
|
|
"values": [
|
|
"foreign_key",
|
|
"polymorphic",
|
|
"graph"
|
|
]
|
|
}
|
|
],
|
|
"relations": [
|
|
{
|
|
"id": "22222222-2222-2222-2222-222222222222",
|
|
"type": "relation",
|
|
"constraint": "fk_order_customer",
|
|
"source_type": "order",
|
|
"source_columns": [
|
|
"customer_id"
|
|
],
|
|
"destination_type": "person",
|
|
"destination_columns": [
|
|
"id"
|
|
],
|
|
"prefix": "customer"
|
|
},
|
|
{
|
|
"id": "33333333-3333-3333-3333-333333333333",
|
|
"type": "relation",
|
|
"constraint": "fk_order_line_order",
|
|
"source_type": "order_line",
|
|
"source_columns": [
|
|
"order_id"
|
|
],
|
|
"destination_type": "order",
|
|
"destination_columns": [
|
|
"id"
|
|
],
|
|
"prefix": "lines"
|
|
},
|
|
{
|
|
"id": "44444444-4444-4444-4444-444444444444",
|
|
"type": "relation",
|
|
"constraint": "fk_relationship_source_entity",
|
|
"source_type": "relationship",
|
|
"source_columns": [
|
|
"source_id",
|
|
"source_type"
|
|
],
|
|
"destination_type": "entity",
|
|
"destination_columns": [
|
|
"id",
|
|
"type"
|
|
],
|
|
"prefix": "source"
|
|
},
|
|
{
|
|
"id": "55555555-5555-5555-5555-555555555555",
|
|
"type": "relation",
|
|
"constraint": "fk_relationship_target_entity",
|
|
"source_type": "relationship",
|
|
"source_columns": [
|
|
"target_id",
|
|
"target_type"
|
|
],
|
|
"destination_type": "entity",
|
|
"destination_columns": [
|
|
"id",
|
|
"type"
|
|
],
|
|
"prefix": "target"
|
|
}
|
|
],
|
|
"types": [
|
|
{
|
|
"name": "entity",
|
|
"schemas": [
|
|
{
|
|
"$id": "entity",
|
|
"type": "object",
|
|
"properties": {
|
|
"id": {
|
|
"type": "string"
|
|
},
|
|
"type": {
|
|
"type": "string"
|
|
},
|
|
"archived": {
|
|
"type": "boolean"
|
|
},
|
|
"created_by": {
|
|
"type": "string"
|
|
},
|
|
"modified_by": {
|
|
"type": "string"
|
|
},
|
|
"created_at": {
|
|
"type": "string",
|
|
"format": "date-time"
|
|
},
|
|
"modified_at": {
|
|
"type": "string",
|
|
"format": "date-time"
|
|
}
|
|
},
|
|
"required": [
|
|
"id",
|
|
"type",
|
|
"created_by",
|
|
"created_at",
|
|
"modified_by",
|
|
"modified_at"
|
|
]
|
|
}
|
|
],
|
|
"hierarchy": [
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"id",
|
|
"type",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
],
|
|
"grouped_fields": {
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
]
|
|
},
|
|
"lookup_fields": [],
|
|
"historical": false,
|
|
"relationship": false
|
|
},
|
|
{
|
|
"name": "organization",
|
|
"schemas": [
|
|
{
|
|
"$id": "organization",
|
|
"$ref": "entity",
|
|
"properties": {
|
|
"name": {
|
|
"type": "string"
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"hierarchy": [
|
|
"organization",
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
],
|
|
"grouped_fields": {
|
|
"organization": [
|
|
"id",
|
|
"type",
|
|
"name"
|
|
],
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
]
|
|
},
|
|
"lookup_fields": [],
|
|
"historical": true,
|
|
"relationship": false
|
|
},
|
|
{
|
|
"name": "user",
|
|
"schemas": [
|
|
{
|
|
"$id": "user",
|
|
"$ref": "organization",
|
|
"properties": {}
|
|
}
|
|
],
|
|
"hierarchy": [
|
|
"user",
|
|
"organization",
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
],
|
|
"grouped_fields": {
|
|
"user": [
|
|
"id",
|
|
"type"
|
|
],
|
|
"organization": [
|
|
"id",
|
|
"type",
|
|
"name"
|
|
],
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
]
|
|
},
|
|
"lookup_fields": [],
|
|
"historical": true,
|
|
"relationship": false
|
|
},
|
|
{
|
|
"name": "person",
|
|
"schemas": [
|
|
{
|
|
"$id": "person",
|
|
"$ref": "user",
|
|
"properties": {
|
|
"first_name": {
|
|
"type": "string"
|
|
},
|
|
"last_name": {
|
|
"type": "string"
|
|
},
|
|
"date_of_birth": {
|
|
"type": "string"
|
|
},
|
|
"pronouns": {
|
|
"type": "string"
|
|
},
|
|
"contact_id": {
|
|
"type": "string"
|
|
},
|
|
"contacts": {
|
|
"type": "array",
|
|
"items": {
|
|
"$ref": "contact",
|
|
"properties": {
|
|
"target": {
|
|
"oneOf": [
|
|
{
|
|
"$ref": "phone_number"
|
|
},
|
|
{
|
|
"$ref": "email_address"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"hierarchy": [
|
|
"person",
|
|
"user",
|
|
"organization",
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"id",
|
|
"type",
|
|
"first_name",
|
|
"last_name",
|
|
"date_of_birth",
|
|
"pronouns",
|
|
"contact_id",
|
|
"name",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
],
|
|
"grouped_fields": {
|
|
"person": [
|
|
"id",
|
|
"type",
|
|
"first_name",
|
|
"last_name",
|
|
"date_of_birth",
|
|
"pronouns",
|
|
"contact_id"
|
|
],
|
|
"user": [
|
|
"id",
|
|
"type"
|
|
],
|
|
"organization": [
|
|
"id",
|
|
"type",
|
|
"name"
|
|
],
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
]
|
|
},
|
|
"lookup_fields": [
|
|
"first_name",
|
|
"last_name",
|
|
"date_of_birth",
|
|
"pronouns"
|
|
],
|
|
"historical": true,
|
|
"relationship": false
|
|
},
|
|
{
|
|
"name": "order",
|
|
"schemas": [
|
|
{
|
|
"$id": "order",
|
|
"$ref": "entity",
|
|
"properties": {
|
|
"total": {
|
|
"type": "number"
|
|
},
|
|
"customer_id": {
|
|
"type": "string"
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"hierarchy": [
|
|
"order",
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"id",
|
|
"type",
|
|
"total",
|
|
"customer_id",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
],
|
|
"grouped_fields": {
|
|
"order": [
|
|
"id",
|
|
"type",
|
|
"total",
|
|
"customer_id"
|
|
],
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
]
|
|
},
|
|
"lookup_fields": [
|
|
"id"
|
|
],
|
|
"historical": true,
|
|
"relationship": false
|
|
},
|
|
{
|
|
"name": "order_line",
|
|
"schemas": [
|
|
{
|
|
"$id": "order_line",
|
|
"$ref": "entity",
|
|
"properties": {
|
|
"order_id": {
|
|
"type": "string"
|
|
},
|
|
"product": {
|
|
"type": "string"
|
|
},
|
|
"price": {
|
|
"type": "number"
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"hierarchy": [
|
|
"order_line",
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"id",
|
|
"type",
|
|
"order_id",
|
|
"product",
|
|
"price",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
],
|
|
"grouped_fields": {
|
|
"order_line": [
|
|
"id",
|
|
"type",
|
|
"order_id",
|
|
"product",
|
|
"price"
|
|
],
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by",
|
|
"archived"
|
|
]
|
|
},
|
|
"lookup_fields": [],
|
|
"historical": true,
|
|
"relationship": false
|
|
},
|
|
{
|
|
"name": "relationship",
|
|
"relationship": true,
|
|
"hierarchy": [
|
|
"relationship",
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"source_id",
|
|
"source_type",
|
|
"target_id",
|
|
"target_type",
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"archived",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by"
|
|
],
|
|
"grouped_fields": {
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"archived",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by"
|
|
],
|
|
"relationship": [
|
|
"source_id",
|
|
"source_type",
|
|
"target_id",
|
|
"target_type"
|
|
]
|
|
},
|
|
"field_types": {
|
|
"id": "uuid",
|
|
"type": "text",
|
|
"archived": "boolean",
|
|
"source_id": "uuid",
|
|
"source_type": "text",
|
|
"target_id": "uuid",
|
|
"target_type": "text",
|
|
"name": "text",
|
|
"created_at": "timestamptz",
|
|
"created_by": "uuid",
|
|
"modified_at": "timestamptz",
|
|
"modified_by": "uuid"
|
|
},
|
|
"schemas": [
|
|
{
|
|
"$id": "relationship",
|
|
"$ref": "entity",
|
|
"properties": {}
|
|
}
|
|
],
|
|
"lookup_fields": [],
|
|
"historical": true
|
|
},
|
|
{
|
|
"name": "contact",
|
|
"relationship": true,
|
|
"hierarchy": [
|
|
"contact",
|
|
"relationship",
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"is_primary",
|
|
"source_id",
|
|
"source_type",
|
|
"target_id",
|
|
"target_type",
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"archived",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by"
|
|
],
|
|
"grouped_fields": {
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"archived",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by"
|
|
],
|
|
"relationship": [
|
|
"source_id",
|
|
"source_type",
|
|
"target_id",
|
|
"target_type"
|
|
],
|
|
"contact": [
|
|
"is_primary"
|
|
]
|
|
},
|
|
"field_types": {
|
|
"id": "uuid",
|
|
"type": "text",
|
|
"archived": "boolean",
|
|
"source_id": "uuid",
|
|
"source_type": "text",
|
|
"target_id": "uuid",
|
|
"target_type": "text",
|
|
"is_primary": "boolean",
|
|
"name": "text",
|
|
"created_at": "timestamptz",
|
|
"created_by": "uuid",
|
|
"modified_at": "timestamptz",
|
|
"modified_by": "uuid"
|
|
},
|
|
"schemas": [
|
|
{
|
|
"$id": "contact",
|
|
"$ref": "relationship",
|
|
"properties": {
|
|
"is_primary": {
|
|
"type": "boolean"
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"lookup_fields": [],
|
|
"historical": true
|
|
},
|
|
{
|
|
"name": "phone_number",
|
|
"hierarchy": [
|
|
"phone_number",
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"number",
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"archived",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by"
|
|
],
|
|
"grouped_fields": {
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"archived",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by"
|
|
],
|
|
"phone_number": [
|
|
"number"
|
|
]
|
|
},
|
|
"field_types": {
|
|
"id": "uuid",
|
|
"type": "text",
|
|
"archived": "boolean",
|
|
"number": "text",
|
|
"name": "text",
|
|
"created_at": "timestamptz",
|
|
"created_by": "uuid",
|
|
"modified_at": "timestamptz",
|
|
"modified_by": "uuid"
|
|
},
|
|
"schemas": [
|
|
{
|
|
"$id": "phone_number",
|
|
"$ref": "entity",
|
|
"properties": {
|
|
"number": {
|
|
"type": "string"
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"lookup_fields": [],
|
|
"historical": true,
|
|
"relationship": false
|
|
},
|
|
{
|
|
"name": "email_address",
|
|
"hierarchy": [
|
|
"email_address",
|
|
"entity"
|
|
],
|
|
"fields": [
|
|
"address",
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"archived",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by"
|
|
],
|
|
"grouped_fields": {
|
|
"entity": [
|
|
"id",
|
|
"type",
|
|
"name",
|
|
"archived",
|
|
"created_at",
|
|
"created_by",
|
|
"modified_at",
|
|
"modified_by"
|
|
],
|
|
"email_address": [
|
|
"address"
|
|
]
|
|
},
|
|
"field_types": {
|
|
"id": "uuid",
|
|
"type": "text",
|
|
"archived": "boolean",
|
|
"address": "text",
|
|
"name": "text",
|
|
"created_at": "timestamptz",
|
|
"created_by": "uuid",
|
|
"modified_at": "timestamptz",
|
|
"modified_by": "uuid"
|
|
},
|
|
"schemas": [
|
|
{
|
|
"$id": "email_address",
|
|
"$ref": "entity",
|
|
"properties": {
|
|
"address": {
|
|
"type": "string"
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"lookup_fields": [],
|
|
"historical": true,
|
|
"relationship": false
|
|
}
|
|
]
|
|
},
|
|
"tests": [
|
|
{
|
|
"description": "Insert person without id (no lookup)",
|
|
"action": "merge",
|
|
"data": {
|
|
"type": "person",
|
|
"first_name": "IncompleteFirst",
|
|
"last_name": "IncompleteLast"
|
|
},
|
|
"mocks": [
|
|
{
|
|
"id": "33333333-3333-3333-3333-333333333333",
|
|
"type": "person",
|
|
"first_name": "IncompleteFirst",
|
|
"last_name": "IncompleteLast",
|
|
"date_of_birth": "1990-01-01T00:00:00Z",
|
|
"pronouns": "they/them",
|
|
"contact_id": "old-contact"
|
|
}
|
|
],
|
|
"expect": {
|
|
"success": true,
|
|
"sql": [
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:person_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"organization\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"user\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"person\" (",
|
|
" \"first_name\",",
|
|
" \"id\",",
|
|
" \"last_name\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" 'IncompleteFirst',",
|
|
" '{{uuid:person_id}}',",
|
|
" 'IncompleteLast',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" '{",
|
|
" \"first_name\":\"IncompleteFirst\",",
|
|
" \"last_name\":\"IncompleteLast\",",
|
|
" \"type\":\"person\"",
|
|
" }',",
|
|
" '{{uuid:person_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"first_name\":\"IncompleteFirst\",",
|
|
" \"id\":\"{{uuid:person_id}}\",",
|
|
" \"last_name\":\"IncompleteLast\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"type\":\"person\"",
|
|
" }",
|
|
"}')"
|
|
]
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "Update existing person without id (lookup)",
|
|
"action": "merge",
|
|
"data": {
|
|
"type": "person",
|
|
"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",
|
|
"first_name": "LookupFirst",
|
|
"last_name": "LookupLast",
|
|
"date_of_birth": "1990-01-01T00:00:00Z",
|
|
"pronouns": "they/them",
|
|
"contact_id": "old-contact"
|
|
}
|
|
],
|
|
"expect": {
|
|
"success": true,
|
|
"sql": [
|
|
[
|
|
"SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
|
"FROM agreego.\"person\" t1",
|
|
"LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id",
|
|
"LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id",
|
|
"LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id",
|
|
"WHERE \"first_name\" = 'LookupFirst' AND \"last_name\" = 'LookupLast' AND \"date_of_birth\" = '1990-01-01T00:00:00Z' AND \"pronouns\" = 'they/them'"
|
|
],
|
|
[
|
|
"UPDATE agreego.\"person\"",
|
|
"SET",
|
|
" \"contact_id\" = 'abc-contact'",
|
|
"WHERE",
|
|
" id = '22222222-2222-2222-2222-222222222222'"
|
|
],
|
|
[
|
|
"UPDATE agreego.\"entity\"",
|
|
"SET",
|
|
" \"modified_at\" = '2026-03-10T00:00:00Z',",
|
|
" \"modified_by\" = '00000000-0000-0000-0000-000000000000'",
|
|
"WHERE",
|
|
" id = '22222222-2222-2222-2222-222222222222'"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" '{",
|
|
" \"contact_id\":\"abc-contact\",",
|
|
" \"type\":\"person\"",
|
|
" }',",
|
|
" '22222222-2222-2222-2222-222222222222',",
|
|
" '{{uuid}}',",
|
|
" 'update',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"changes\":{",
|
|
" \"contact_id\":\"abc-contact\",",
|
|
" \"type\":\"person\"",
|
|
" },",
|
|
" \"complete\":{",
|
|
" \"contact_id\":\"abc-contact\",",
|
|
" \"date_of_birth\":\"1990-01-01T00:00:00Z\",",
|
|
" \"first_name\":\"LookupFirst\",",
|
|
" \"id\":\"22222222-2222-2222-2222-222222222222\",",
|
|
" \"last_name\":\"LookupLast\",",
|
|
" \"modified_at\":\"2026-03-10T00:00:00Z\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"pronouns\":\"they/them\",",
|
|
" \"type\":\"person\"",
|
|
" }",
|
|
"}')"
|
|
]
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "Update existing person with id (no lookup)",
|
|
"action": "merge",
|
|
"data": {
|
|
"id": "11111111-1111-1111-1111-111111111111",
|
|
"type": "person",
|
|
"first_name": "NewFirst",
|
|
"last_name": "NewLast"
|
|
},
|
|
"mocks": [
|
|
{
|
|
"id": "11111111-1111-1111-1111-111111111111",
|
|
"type": "person",
|
|
"first_name": "OldFirst",
|
|
"last_name": "OldLast"
|
|
}
|
|
],
|
|
"expect": {
|
|
"success": true,
|
|
"sql": [
|
|
[
|
|
"SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
|
"FROM agreego.\"person\" t1",
|
|
"LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id",
|
|
"LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id",
|
|
"LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id",
|
|
"WHERE t1.id = '11111111-1111-1111-1111-111111111111'"
|
|
],
|
|
[
|
|
"UPDATE agreego.\"person\"",
|
|
"SET",
|
|
" \"first_name\" = 'NewFirst',",
|
|
" \"last_name\" = 'NewLast'",
|
|
"WHERE",
|
|
" id = '11111111-1111-1111-1111-111111111111'"
|
|
],
|
|
[
|
|
"UPDATE agreego.\"entity\"",
|
|
"SET",
|
|
" \"modified_at\" = '2026-03-10T00:00:00Z',",
|
|
" \"modified_by\" = '00000000-0000-0000-0000-000000000000'",
|
|
"WHERE",
|
|
" id = '11111111-1111-1111-1111-111111111111'"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" '{",
|
|
" \"first_name\":\"NewFirst\",",
|
|
" \"last_name\":\"NewLast\",",
|
|
" \"type\":\"person\"",
|
|
" }',",
|
|
" '11111111-1111-1111-1111-111111111111',",
|
|
" '{{uuid}}',",
|
|
" 'update',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"changes\":{",
|
|
" \"first_name\":\"NewFirst\",",
|
|
" \"last_name\":\"NewLast\",",
|
|
" \"type\":\"person\"",
|
|
" },",
|
|
" \"complete\":{",
|
|
" \"first_name\":\"NewFirst\",",
|
|
" \"id\":\"11111111-1111-1111-1111-111111111111\",",
|
|
" \"last_name\":\"NewLast\",",
|
|
" \"modified_at\":\"2026-03-10T00:00:00Z\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"type\":\"person\"",
|
|
" }",
|
|
"}')"
|
|
]
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "Empty strings null out fields",
|
|
"action": "merge",
|
|
"data": {
|
|
"id": "123",
|
|
"type": "person",
|
|
"first_name": "John",
|
|
"last_name": "Doe",
|
|
"date_of_birth": "1990-01-01T00:00:00Z",
|
|
"pronouns": ""
|
|
},
|
|
"expect": {
|
|
"success": true,
|
|
"sql": [
|
|
[
|
|
"SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
|
"FROM agreego.\"person\" t1",
|
|
"LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id",
|
|
"LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id",
|
|
"LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id",
|
|
"WHERE t1.id = '123'"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '123',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"organization\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '123',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"user\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '123',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"person\" (",
|
|
" \"date_of_birth\",",
|
|
" \"first_name\",",
|
|
" \"id\",",
|
|
" \"last_name\",",
|
|
" \"pronouns\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '1990-01-01T00:00:00Z',",
|
|
" 'John',",
|
|
" '123',",
|
|
" 'Doe',",
|
|
" NULL,",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" '{",
|
|
" \"date_of_birth\":\"1990-01-01T00:00:00Z\",",
|
|
" \"first_name\":\"John\",",
|
|
" \"last_name\":\"Doe\",",
|
|
" \"pronouns\":\"\",",
|
|
" \"type\":\"person\"",
|
|
" }',",
|
|
" '123',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"date_of_birth\":\"1990-01-01T00:00:00Z\",",
|
|
" \"first_name\":\"John\",",
|
|
" \"id\":\"123\",",
|
|
" \"last_name\":\"Doe\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"pronouns\":\"\",",
|
|
" \"type\":\"person\"",
|
|
" }",
|
|
"}')"
|
|
]
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "Insert order with nested customer person",
|
|
"action": "merge",
|
|
"data": {
|
|
"type": "order",
|
|
"total": 100.0,
|
|
"customer": {
|
|
"type": "person",
|
|
"first_name": "Bob",
|
|
"last_name": "Smith",
|
|
"date_of_birth": "2000-01-01"
|
|
}
|
|
},
|
|
"expect": {
|
|
"success": true,
|
|
"sql": [
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:customer_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"organization\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:customer_id}}',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"user\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:customer_id}}',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"person\" (",
|
|
" \"date_of_birth\",",
|
|
" \"first_name\",",
|
|
" \"id\",",
|
|
" \"last_name\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '2000-01-01',",
|
|
" 'Bob',",
|
|
" '{{uuid:customer_id}}',",
|
|
" 'Smith',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" '{",
|
|
" \"date_of_birth\":\"2000-01-01\",",
|
|
" \"first_name\":\"Bob\",",
|
|
" \"last_name\":\"Smith\",",
|
|
" \"type\":\"person\"",
|
|
" }',",
|
|
" '{{uuid:customer_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:order_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'order'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"order\" (",
|
|
" \"customer_id\",",
|
|
" \"id\",",
|
|
" \"total\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:customer_id}}',",
|
|
" '{{uuid:order_id}}',",
|
|
" 100,",
|
|
" 'order'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" '{",
|
|
" \"customer_id\":\"{{uuid:customer_id}}\",",
|
|
" \"total\":100.0,",
|
|
" \"type\":\"order\"",
|
|
" }',",
|
|
" '{{uuid:order_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"customer_id\":\"{{uuid:customer_id}}\",",
|
|
" \"id\":\"{{uuid:order_id}}\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"total\":100.0,",
|
|
" \"type\":\"order\"",
|
|
" }",
|
|
"}')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"date_of_birth\":\"2000-01-01\",",
|
|
" \"first_name\":\"Bob\",",
|
|
" \"id\":\"{{uuid:customer_id}}\",",
|
|
" \"last_name\":\"Smith\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"type\":\"person\"",
|
|
" }",
|
|
"}')"
|
|
]
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "Insert order with nested order lines",
|
|
"action": "merge",
|
|
"data": {
|
|
"id": "abc",
|
|
"type": "order",
|
|
"total": 99.0,
|
|
"lines": [
|
|
{
|
|
"type": "order_line",
|
|
"product": "Widget",
|
|
"price": 99.0
|
|
}
|
|
]
|
|
},
|
|
"expect": {
|
|
"success": true,
|
|
"sql": [
|
|
[
|
|
"SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
|
"FROM agreego.\"order\" t1",
|
|
"LEFT JOIN agreego.\"entity\" t2 ON t2.id = t1.id",
|
|
"WHERE t1.id = 'abc'"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'abc',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'order'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"order\" (",
|
|
" \"id\",",
|
|
" \"total\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" 'abc',",
|
|
" 99,",
|
|
" 'order'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:line_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'order_line'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"order_line\" (",
|
|
" \"id\",",
|
|
" \"order_id\",",
|
|
" \"price\",",
|
|
" \"product\",",
|
|
" \"type\")",
|
|
"VALUES (",
|
|
" '{{uuid:line_id}}',",
|
|
" 'abc',",
|
|
" 99,",
|
|
" 'Widget',",
|
|
" 'order_line'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" '{",
|
|
" \"order_id\":\"abc\",",
|
|
" \"price\":99.0,",
|
|
" \"product\":\"Widget\",",
|
|
" \"type\":\"order_line\"",
|
|
" }',",
|
|
" '{{uuid:line_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" '{",
|
|
" \"total\":99.0,",
|
|
" \"type\":\"order\"",
|
|
" }',",
|
|
" 'abc',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"abc\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"total\":99.0,",
|
|
" \"type\":\"order\"",
|
|
" }",
|
|
"}')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:line_id}}\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"order_id\":\"abc\",",
|
|
" \"price\":99.0,",
|
|
" \"product\":\"Widget\",",
|
|
" \"type\":\"order_line\"",
|
|
" }",
|
|
"}')"
|
|
]
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "Insert person with contacts and phone numbers (M:M)",
|
|
"action": "merge",
|
|
"data": {
|
|
"type": "person",
|
|
"first_name": "Relation",
|
|
"last_name": "Test",
|
|
"contacts": [
|
|
{
|
|
"type": "contact",
|
|
"is_primary": true,
|
|
"target": {
|
|
"type": "phone_number",
|
|
"number": "555-0001"
|
|
}
|
|
},
|
|
{
|
|
"type": "contact",
|
|
"is_primary": false,
|
|
"target": {
|
|
"type": "phone_number",
|
|
"number": "555-0002"
|
|
}
|
|
},
|
|
{
|
|
"type": "contact",
|
|
"is_primary": false,
|
|
"target": {
|
|
"type": "email_address",
|
|
"address": "test@example.com"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"expect": {
|
|
"success": true,
|
|
"sql": [
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:person_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"organization\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"user\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"person\" (",
|
|
" \"first_name\",",
|
|
" \"id\",",
|
|
" \"last_name\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" 'Relation',",
|
|
" '{{uuid:person_id}}',",
|
|
" 'Test',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:phone1_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'phone_number'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"phone_number\" (",
|
|
" \"number\"",
|
|
") VALUES (",
|
|
" '555-0001'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
") VALUES (",
|
|
" '{\"number\":\"555-0001\",\"type\":\"phone_number\"}',",
|
|
" '{{uuid:phone1_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:contact1_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'contact'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"relationship\" (",
|
|
" \"source_id\",",
|
|
" \"source_type\",",
|
|
" \"target_id\",",
|
|
" \"target_type\"",
|
|
") VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" 'person',",
|
|
" '{{uuid:phone1_id}}',",
|
|
" 'phone_number'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"contact\" (",
|
|
" \"is_primary\"",
|
|
") VALUES (",
|
|
" true",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
") VALUES (",
|
|
" '{",
|
|
" \"is_primary\":true,",
|
|
" \"source_id\":\"{{uuid:person_id}}\",",
|
|
" \"source_type\":\"person\",",
|
|
" \"target_id\":\"{{uuid:phone1_id}}\",",
|
|
" \"target_type\":\"phone_number\",",
|
|
" \"type\":\"contact\"",
|
|
" }',",
|
|
" '{{uuid:contact1_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:phone2_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'phone_number'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"phone_number\" (",
|
|
" \"number\"",
|
|
") VALUES (",
|
|
" '555-0002'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
") VALUES (",
|
|
" '{",
|
|
" \"number\":\"555-0002\",",
|
|
" \"type\":\"phone_number\"",
|
|
" }',",
|
|
" '{{uuid:phone2_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:contact2_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'contact'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"relationship\" (",
|
|
" \"source_id\",",
|
|
" \"source_type\",",
|
|
" \"target_id\",",
|
|
" \"target_type\"",
|
|
") VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" 'person',",
|
|
" '{{uuid:phone2_id}}',",
|
|
" 'phone_number'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"contact\" (",
|
|
" \"is_primary\"",
|
|
") VALUES (",
|
|
" false",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
") VALUES (",
|
|
" '{",
|
|
" \"is_primary\":false,",
|
|
" \"source_id\":\"{{uuid:person_id}}\",",
|
|
" \"source_type\":\"person\",",
|
|
" \"target_id\":\"{{uuid:phone2_id}}\",",
|
|
" \"target_type\":\"phone_number\",",
|
|
" \"type\":\"contact\"",
|
|
" }',",
|
|
" '{{uuid:contact2_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:email1_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'email_address'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"email_address\" (",
|
|
" \"address\"",
|
|
") VALUES (",
|
|
" 'test@example.com'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
") VALUES (",
|
|
" '{",
|
|
" \"address\":\"test@example.com\",",
|
|
" \"type\":\"email_address\"",
|
|
" }',",
|
|
" '{{uuid:email1_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"type\"",
|
|
") VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:contact3_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'contact'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"relationship\" (",
|
|
" \"source_id\",",
|
|
" \"source_type\",",
|
|
" \"target_id\",",
|
|
" \"target_type\"",
|
|
") VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" 'person',",
|
|
" '{{uuid:email1_id}}',",
|
|
" 'email_address'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"contact\" (",
|
|
" \"is_primary\"",
|
|
") VALUES (",
|
|
" false",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
") VALUES (",
|
|
" '{",
|
|
" \"is_primary\":false,",
|
|
" \"source_id\":\"{{uuid:person_id}}\",",
|
|
" \"source_type\":\"person\",",
|
|
" \"target_id\":\"{{uuid:email1_id}}\",",
|
|
" \"target_type\":\"email_address\",",
|
|
" \"type\":\"contact\"",
|
|
" }',",
|
|
" '{{uuid:contact3_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
") VALUES (",
|
|
" '{",
|
|
" \"first_name\":\"Relation\",",
|
|
" \"last_name\":\"Test\",",
|
|
" \"type\":\"person\"",
|
|
" }',",
|
|
" '{{uuid:person_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"first_name\":\"Relation\",",
|
|
" \"id\":\"{{uuid:person_id}}\",",
|
|
" \"last_name\":\"Test\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"type\":\"person\"",
|
|
" }",
|
|
"}')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:contact1_id}}\",",
|
|
" \"is_primary\":true,",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"source_id\":\"{{uuid:person_id}}\",",
|
|
" \"source_type\":\"person\",",
|
|
" \"target_id\":\"{{uuid:phone1_id}}\",",
|
|
" \"target_type\":\"phone_number\",",
|
|
" \"type\":\"contact\"",
|
|
" }",
|
|
"}')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:phone1_id}}\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"number\":\"555-0001\",",
|
|
" \"type\":\"phone_number\"",
|
|
" }",
|
|
"}')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:contact2_id}}\",",
|
|
" \"is_primary\":false,",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"source_id\":\"{{uuid:person_id}}\",",
|
|
" \"source_type\":\"person\",",
|
|
" \"target_id\":\"{{uuid:phone2_id}}\",",
|
|
" \"target_type\":\"phone_number\",",
|
|
" \"type\":\"contact\"",
|
|
" }",
|
|
"}')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:phone2_id}}\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"number\":\"555-0002\",",
|
|
" \"type\":\"phone_number\"",
|
|
" }",
|
|
"}')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:contact3_id}}\",",
|
|
" \"is_primary\":false,",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"source_id\":\"{{uuid:person_id}}\",",
|
|
" \"source_type\":\"person\",",
|
|
" \"target_id\":\"{{uuid:email1_id}}\",",
|
|
" \"target_type\":\"email_address\",",
|
|
" \"type\":\"contact\"",
|
|
" }",
|
|
"}')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"address\":\"test@example.com\",",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:email1_id}}\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"type\":\"email_address\"",
|
|
" }",
|
|
"}')"
|
|
]
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "Archive a person",
|
|
"action": "merge",
|
|
"data": {
|
|
"id": "abc-archived",
|
|
"type": "person",
|
|
"archived": true
|
|
},
|
|
"mocks": [
|
|
{
|
|
"id": "abc-archived",
|
|
"type": "person",
|
|
"first_name": "ArchivedFirst",
|
|
"last_name": "ArchivedLast",
|
|
"archived": false
|
|
}
|
|
],
|
|
"expect": {
|
|
"success": true,
|
|
"sql": [
|
|
[
|
|
"SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
|
"FROM agreego.\"person\" t1",
|
|
"LEFT JOIN agreego.\"user\" t2 ON t2.id = t1.id",
|
|
"LEFT JOIN agreego.\"organization\" t3 ON t3.id = t1.id",
|
|
"LEFT JOIN agreego.\"entity\" t4 ON t4.id = t1.id",
|
|
"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.change (",
|
|
" changes,",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
") VALUES (",
|
|
" '{\"archived\":true,\"type\":\"person\"}',",
|
|
" 'abc-archived',",
|
|
" '{{uuid}}',",
|
|
" 'delete',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"changes\":{",
|
|
" \"archived\":true,\"type\":\"person\"},",
|
|
" \"complete\":{",
|
|
" \"archived\":true,",
|
|
" \"first_name\":\"ArchivedFirst\",",
|
|
" \"id\":\"abc-archived\",",
|
|
" \"last_name\":\"ArchivedLast\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"type\":\"person\"",
|
|
" }",
|
|
"}')"
|
|
]
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
] |