added defaults support for lookups

This commit is contained in:
2026-08-03 21:22:27 -04:00
parent d43be1def4
commit 53776fc696
5 changed files with 76 additions and 11 deletions

View File

@ -132,6 +132,15 @@
"columns": [
"name"
]
},
{
"table": "relationship",
"columns": [
"type",
"source_id",
"target_id",
"start_date"
]
}
],
"types": [
@ -573,6 +582,8 @@
"source_type",
"target_id",
"target_type",
"start_date",
"end_date",
"id",
"type",
"name",
@ -597,7 +608,9 @@
"source_id",
"source_type",
"target_id",
"target_type"
"target_type",
"start_date",
"end_date"
]
},
"field_types": {
@ -608,6 +621,8 @@
"source_type": "text",
"target_id": "uuid",
"target_type": "text",
"start_date": "timestamptz",
"end_date": "timestamptz",
"name": "text",
"created_at": "timestamptz",
"created_by": "uuid",
@ -620,7 +635,16 @@
"properties": {}
}
},
"lookup_fields": [],
"lookup_fields": [
"type",
"source_id",
"target_id",
"start_date"
],
"field_defaults": {
"start_date": "0001-01-01T00:00:00Z",
"end_date": "9999-12-31T23:59:59Z"
},
"historical": true,
"notify": true
},
@ -2766,6 +2790,17 @@
" '00000000-0000-0000-0000-000000000000'",
")"
],
[
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}')",
"FROM agreego.\"entity\" t1",
"LEFT JOIN agreego.\"relationship\" t2 ON t2.id = t1.id",
"LEFT JOIN agreego.\"contact\" t3 ON t3.id = t1.id",
"WHERE",
" (t1.\"type\" = 'contact'",
" AND \"source_id\" = '{{uuid:generated_0}}'",
" AND \"target_id\" = '{{uuid:generated_1}}'",
" AND \"start_date\" = '{{timestamp}}'))"
],
[
"INSERT INTO agreego.\"entity\" (",
" \"created_at\",",
@ -2887,6 +2922,17 @@
" '00000000-0000-0000-0000-000000000000'",
")"
],
[
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}')",
"FROM agreego.\"entity\" t1",
"LEFT JOIN agreego.\"relationship\" t2 ON t2.id = t1.id",
"LEFT JOIN agreego.\"contact\" t3 ON t3.id = t1.id",
"WHERE",
" (t1.\"type\" = 'contact'",
" AND \"source_id\" = '{{uuid:generated_0}}'",
" AND \"target_id\" = '{{uuid:generated_5}}'",
" AND \"start_date\" = '{{timestamp}}'))"
],
[
"INSERT INTO agreego.\"entity\" (",
" \"created_at\",",
@ -3008,6 +3054,17 @@
" '00000000-0000-0000-0000-000000000000'",
")"
],
[
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}')",
"FROM agreego.\"entity\" t1",
"LEFT JOIN agreego.\"relationship\" t2 ON t2.id = t1.id",
"LEFT JOIN agreego.\"contact\" t3 ON t3.id = t1.id",
"WHERE",
" (t1.\"type\" = 'contact'",
" AND \"source_id\" = '{{uuid:generated_0}}'",
" AND \"target_id\" = '{{uuid:generated_9}}'",
" AND \"start_date\" = '{{timestamp}}'))"
],
[
"INSERT INTO agreego.\"entity\" (",
" \"created_at\",",

View File

@ -260,12 +260,9 @@
},
"lookup_fields": [],
"null_fields": [],
"default_fields": [
"id",
"type",
"created_at",
"archived"
],
"field_defaults": {
"archived": false
},
"variations": [
"bot",
"organization",

View File

@ -36,7 +36,7 @@ pub struct Type {
#[serde(default)]
pub null_fields: Vec<String>,
#[serde(default)]
pub default_fields: Vec<String>,
pub field_defaults: IndexMap<String, Value>,
pub field_types: Option<Value>,
#[serde(default)]
pub schemas: IndexMap<String, Arc<Schema>>,

View File

@ -335,6 +335,17 @@ impl Merger {
}
}
// Hydrate missing fields from field_defaults for entity_type and its hierarchy
for parent_type_name in &type_def.hierarchy {
if let Some(parent_type) = self.db.types.get(parent_type_name) {
for (k, v) in &parent_type.field_defaults {
if !entity_fields.contains_key(k) {
entity_fields.insert(k.clone(), v.clone());
}
}
}
}
let mut current_org_id = None;
if let Some(compiled_props) = schema.obj.compiled_properties.get() {
if let Some(org_schema) = compiled_props.get("organization_id") {

View File

@ -104,7 +104,7 @@ fn test_library_api() {
},
"types": {
"source_schema": {
"default_fields": [],
"field_defaults": {},
"field_types": null,
"fields": [],
"grouped_fields": null,
@ -169,7 +169,7 @@ fn test_library_api() {
"variations": ["source_schema"]
},
"target_schema": {
"default_fields": [],
"field_defaults": {},
"field_types": null,
"fields": [],
"grouped_fields": null,