added defaults support for lookups
This commit is contained in:
@ -132,6 +132,15 @@
|
|||||||
"columns": [
|
"columns": [
|
||||||
"name"
|
"name"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"table": "relationship",
|
||||||
|
"columns": [
|
||||||
|
"type",
|
||||||
|
"source_id",
|
||||||
|
"target_id",
|
||||||
|
"start_date"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"types": [
|
"types": [
|
||||||
@ -573,6 +582,8 @@
|
|||||||
"source_type",
|
"source_type",
|
||||||
"target_id",
|
"target_id",
|
||||||
"target_type",
|
"target_type",
|
||||||
|
"start_date",
|
||||||
|
"end_date",
|
||||||
"id",
|
"id",
|
||||||
"type",
|
"type",
|
||||||
"name",
|
"name",
|
||||||
@ -597,7 +608,9 @@
|
|||||||
"source_id",
|
"source_id",
|
||||||
"source_type",
|
"source_type",
|
||||||
"target_id",
|
"target_id",
|
||||||
"target_type"
|
"target_type",
|
||||||
|
"start_date",
|
||||||
|
"end_date"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"field_types": {
|
"field_types": {
|
||||||
@ -608,6 +621,8 @@
|
|||||||
"source_type": "text",
|
"source_type": "text",
|
||||||
"target_id": "uuid",
|
"target_id": "uuid",
|
||||||
"target_type": "text",
|
"target_type": "text",
|
||||||
|
"start_date": "timestamptz",
|
||||||
|
"end_date": "timestamptz",
|
||||||
"name": "text",
|
"name": "text",
|
||||||
"created_at": "timestamptz",
|
"created_at": "timestamptz",
|
||||||
"created_by": "uuid",
|
"created_by": "uuid",
|
||||||
@ -620,7 +635,16 @@
|
|||||||
"properties": {}
|
"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,
|
"historical": true,
|
||||||
"notify": true
|
"notify": true
|
||||||
},
|
},
|
||||||
@ -2766,6 +2790,17 @@
|
|||||||
" '00000000-0000-0000-0000-000000000000'",
|
" '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\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
" \"created_at\",",
|
" \"created_at\",",
|
||||||
@ -2887,6 +2922,17 @@
|
|||||||
" '00000000-0000-0000-0000-000000000000'",
|
" '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\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
" \"created_at\",",
|
" \"created_at\",",
|
||||||
@ -3008,6 +3054,17 @@
|
|||||||
" '00000000-0000-0000-0000-000000000000'",
|
" '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\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
" \"created_at\",",
|
" \"created_at\",",
|
||||||
|
|||||||
@ -260,12 +260,9 @@
|
|||||||
},
|
},
|
||||||
"lookup_fields": [],
|
"lookup_fields": [],
|
||||||
"null_fields": [],
|
"null_fields": [],
|
||||||
"default_fields": [
|
"field_defaults": {
|
||||||
"id",
|
"archived": false
|
||||||
"type",
|
},
|
||||||
"created_at",
|
|
||||||
"archived"
|
|
||||||
],
|
|
||||||
"variations": [
|
"variations": [
|
||||||
"bot",
|
"bot",
|
||||||
"organization",
|
"organization",
|
||||||
|
|||||||
@ -36,7 +36,7 @@ pub struct Type {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub null_fields: Vec<String>,
|
pub null_fields: Vec<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub default_fields: Vec<String>,
|
pub field_defaults: IndexMap<String, Value>,
|
||||||
pub field_types: Option<Value>,
|
pub field_types: Option<Value>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub schemas: IndexMap<String, Arc<Schema>>,
|
pub schemas: IndexMap<String, Arc<Schema>>,
|
||||||
|
|||||||
@ -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;
|
let mut current_org_id = None;
|
||||||
if let Some(compiled_props) = schema.obj.compiled_properties.get() {
|
if let Some(compiled_props) = schema.obj.compiled_properties.get() {
|
||||||
if let Some(org_schema) = compiled_props.get("organization_id") {
|
if let Some(org_schema) = compiled_props.get("organization_id") {
|
||||||
|
|||||||
@ -104,7 +104,7 @@ fn test_library_api() {
|
|||||||
},
|
},
|
||||||
"types": {
|
"types": {
|
||||||
"source_schema": {
|
"source_schema": {
|
||||||
"default_fields": [],
|
"field_defaults": {},
|
||||||
"field_types": null,
|
"field_types": null,
|
||||||
"fields": [],
|
"fields": [],
|
||||||
"grouped_fields": null,
|
"grouped_fields": null,
|
||||||
@ -169,7 +169,7 @@ fn test_library_api() {
|
|||||||
"variations": ["source_schema"]
|
"variations": ["source_schema"]
|
||||||
},
|
},
|
||||||
"target_schema": {
|
"target_schema": {
|
||||||
"default_fields": [],
|
"field_defaults": {},
|
||||||
"field_types": null,
|
"field_types": null,
|
||||||
"fields": [],
|
"fields": [],
|
||||||
"grouped_fields": null,
|
"grouped_fields": null,
|
||||||
|
|||||||
Reference in New Issue
Block a user