diff --git a/docs/directus/directus_key_autogen.sql b/docs/directus/directus_key_autogen.sql index 58721ba..9764f36 100644 --- a/docs/directus/directus_key_autogen.sql +++ b/docs/directus/directus_key_autogen.sql @@ -1,5 +1,5 @@ -- Directus key auto-generation triggers --- Target tables: companies, sites, users, systems, roles +-- Target tables: companies, sites, users, roles -- Key format: PREFIX + yyyymmdd + 'X' + 4 digits -- Example: CP20260404X1234 @@ -47,34 +47,35 @@ BEGIN END; $$; -DROP TRIGGER IF EXISTS trg_companies_company_key_autogen ON public.companies; -CREATE TRIGGER trg_companies_company_key_autogen +DROP TRIGGER IF EXISTS trg_companies_key_autogen ON public.companies; +CREATE TRIGGER trg_companies_key_autogen BEFORE INSERT ON public.companies FOR EACH ROW -EXECUTE FUNCTION public.directus_autogen_entity_key('company_key', 'CP'); +EXECUTE FUNCTION public.directus_autogen_entity_key('key', 'CP'); -DROP TRIGGER IF EXISTS trg_sites_site_key_autogen ON public.sites; -CREATE TRIGGER trg_sites_site_key_autogen +DROP TRIGGER IF EXISTS trg_sites_key_autogen ON public.sites; +CREATE TRIGGER trg_sites_key_autogen BEFORE INSERT ON public.sites FOR EACH ROW -EXECUTE FUNCTION public.directus_autogen_entity_key('site_key', 'ST'); +EXECUTE FUNCTION public.directus_autogen_entity_key('key', 'ST'); -DROP TRIGGER IF EXISTS trg_users_user_key_autogen ON public.users; -CREATE TRIGGER trg_users_user_key_autogen +DROP TRIGGER IF EXISTS trg_users_key_autogen ON public.users; +CREATE TRIGGER trg_users_key_autogen BEFORE INSERT ON public.users FOR EACH ROW -EXECUTE FUNCTION public.directus_autogen_entity_key('user_key', 'UE'); +EXECUTE FUNCTION public.directus_autogen_entity_key('key', 'UE'); -DROP TRIGGER IF EXISTS trg_systems_system_key_autogen ON public.systems; -CREATE TRIGGER trg_systems_system_key_autogen -BEFORE INSERT ON public.systems -FOR EACH ROW -EXECUTE FUNCTION public.directus_autogen_entity_key('system_key', 'SY'); - -DROP TRIGGER IF EXISTS trg_roles_role_key_autogen ON public.roles; -CREATE TRIGGER trg_roles_role_key_autogen +DROP TRIGGER IF EXISTS trg_roles_key_autogen ON public.roles; +CREATE TRIGGER trg_roles_key_autogen BEFORE INSERT ON public.roles FOR EACH ROW -EXECUTE FUNCTION public.directus_autogen_entity_key('role_key', 'RL'); +EXECUTE FUNCTION public.directus_autogen_entity_key('key', 'RL'); + +-- cleanup old trigger names to avoid duplicates from previous scripts +DROP TRIGGER IF EXISTS trg_companies_company_key_autogen ON public.companies; +DROP TRIGGER IF EXISTS trg_sites_site_key_autogen ON public.sites; +DROP TRIGGER IF EXISTS trg_users_user_key_autogen ON public.users; +DROP TRIGGER IF EXISTS trg_systems_system_key_autogen ON public.systems; +DROP TRIGGER IF EXISTS trg_roles_role_key_autogen ON public.roles; COMMIT; diff --git a/docs/directus/member-schema.directus.json b/docs/directus/member-schema.directus.json index 4a87544..060db58 100644 --- a/docs/directus/member-schema.directus.json +++ b/docs/directus/member-schema.directus.json @@ -258,10 +258,10 @@ }, { "collection": "companies", - "field": "company_key", + "field": "key", "type": "string", "schema": { - "name": "company_key", + "name": "key", "table": "companies", "data_type": "character varying", "default_value": null, @@ -270,7 +270,7 @@ "numeric_precision": null, "numeric_scale": null, "is_generated": false, - "is_nullable": false, + "is_nullable": true, "is_unique": true, "is_indexed": false, "is_primary_key": false, @@ -282,20 +282,20 @@ }, "meta": { "collection": "companies", - "field": "company_key", + "field": "key", "special": null, "interface": "input", "options": null, "display": null, "display_options": null, - "readonly": false, + "readonly": true, "hidden": false, - "sort": 2, + "sort": 1, "width": "half", "translations": null, "note": null, "conditions": null, - "required": true, + "required": false, "group": null, "validation": null, "validation_message": null, @@ -363,7 +363,7 @@ }, "readonly": false, "hidden": false, - "sort": 1, + "sort": 2, "width": "half", "translations": null, "note": null, @@ -459,8 +459,8 @@ "display_options": null, "readonly": false, "hidden": false, - "sort": 2, - "width": "half", + "sort": 3, + "width": "full", "translations": null, "note": null, "conditions": null, @@ -521,43 +521,6 @@ "searchable": true } }, - { - "collection": "companies", - "field": "sites", - "type": "alias", - "schema": null, - "meta": { - "collection": "companies", - "field": "sites", - "special": [ - "o2m" - ], - "interface": "list-o2m", - "options": { - "layout": "table", - "fields": [ - "name", - "status", - "users", - "roles" - ] - }, - "display": "related-values", - "display_options": null, - "readonly": false, - "hidden": false, - "sort": 3, - "width": "full", - "translations": null, - "note": null, - "conditions": null, - "required": false, - "group": null, - "validation": null, - "validation_message": null, - "searchable": true - } - }, { "collection": "companies", "field": "date_updated", @@ -610,20 +573,26 @@ }, { "collection": "companies", - "field": "system_info", + "field": "sites", "type": "alias", "schema": null, "meta": { "collection": "companies", - "field": "system_info", + "field": "sites", "special": [ - "alias", - "no-data", - "group" + "o2m" ], - "interface": "group-raw", - "options": null, - "display": null, + "interface": "list-o2m", + "options": { + "layout": "table", + "fields": [ + "name", + "status", + "users", + "roles" + ] + }, + "display": "related-values", "display_options": null, "readonly": false, "hidden": false, @@ -689,6 +658,37 @@ "searchable": true } }, + { + "collection": "companies", + "field": "system_info", + "type": "alias", + "schema": null, + "meta": { + "collection": "companies", + "field": "system_info", + "special": [ + "alias", + "no-data", + "group" + ], + "interface": "group-raw", + "options": null, + "display": null, + "display_options": null, + "readonly": false, + "hidden": false, + "sort": 5, + "width": "full", + "translations": null, + "note": null, + "conditions": null, + "required": false, + "group": null, + "validation": null, + "validation_message": null, + "searchable": true + } + }, { "collection": "roles", "field": "id", @@ -749,7 +749,7 @@ "numeric_precision": null, "numeric_scale": null, "is_generated": false, - "is_nullable": true, + "is_nullable": false, "is_unique": false, "is_indexed": false, "is_primary_key": false, @@ -768,11 +768,12 @@ "interface": "select-dropdown-m2o", "options": { "template": "{{name}}", - "enableCreate": false + "enableCreate": false, + "enableLink": true }, "display": null, "display_options": null, - "readonly": false, + "readonly": true, "hidden": false, "sort": 1, "width": "half", @@ -838,10 +839,10 @@ }, { "collection": "roles", - "field": "role_key", + "field": "key", "type": "string", "schema": { - "name": "role_key", + "name": "key", "table": "roles", "data_type": "character varying", "default_value": null, @@ -850,7 +851,7 @@ "numeric_precision": null, "numeric_scale": null, "is_generated": false, - "is_nullable": false, + "is_nullable": true, "is_unique": true, "is_indexed": false, "is_primary_key": false, @@ -862,20 +863,20 @@ }, "meta": { "collection": "roles", - "field": "role_key", + "field": "key", "special": null, "interface": "input", "options": null, "display": null, "display_options": null, - "readonly": false, + "readonly": true, "hidden": false, "sort": 2, "width": "half", "translations": null, "note": null, "conditions": null, - "required": true, + "required": false, "group": null, "validation": null, "validation_message": null, @@ -932,6 +933,52 @@ "searchable": true } }, + { + "collection": "roles", + "field": "role_code", + "type": "string", + "schema": { + "name": "role_code", + "table": "roles", + "data_type": "character varying", + "default_value": null, + "generation_expression": null, + "max_length": 255, + "numeric_precision": null, + "numeric_scale": null, + "is_generated": false, + "is_nullable": false, + "is_unique": true, + "is_indexed": false, + "is_primary_key": false, + "has_auto_increment": false, + "foreign_key_schema": null, + "foreign_key_table": null, + "foreign_key_column": null, + "comment": null + }, + "meta": { + "collection": "roles", + "field": "role_code", + "special": null, + "interface": "input", + "options": null, + "display": null, + "display_options": null, + "readonly": false, + "hidden": false, + "sort": 3, + "width": "full", + "translations": null, + "note": null, + "conditions": null, + "required": true, + "group": null, + "validation": null, + "validation_message": null, + "searchable": true + } + }, { "collection": "roles", "field": "status", @@ -993,7 +1040,7 @@ }, "readonly": false, "hidden": false, - "sort": 3, + "sort": 4, "width": "half", "translations": null, "note": null, @@ -1089,7 +1136,7 @@ "display_options": null, "readonly": false, "hidden": false, - "sort": 4, + "sort": 5, "width": "half", "translations": null, "note": null, @@ -1175,7 +1222,7 @@ "display_options": null, "readonly": false, "hidden": false, - "sort": 5, + "sort": 6, "width": "full", "translations": null, "note": null, @@ -1206,7 +1253,7 @@ "display_options": null, "readonly": false, "hidden": false, - "sort": 6, + "sort": 7, "width": "full", "translations": null, "note": null, @@ -1402,52 +1449,6 @@ "searchable": true } }, - { - "collection": "sites", - "field": "site_key", - "type": "string", - "schema": { - "name": "site_key", - "table": "sites", - "data_type": "character varying", - "default_value": null, - "generation_expression": null, - "max_length": 255, - "numeric_precision": null, - "numeric_scale": null, - "is_generated": false, - "is_nullable": false, - "is_unique": true, - "is_indexed": false, - "is_primary_key": false, - "has_auto_increment": false, - "foreign_key_schema": null, - "foreign_key_table": null, - "foreign_key_column": null, - "comment": null - }, - "meta": { - "collection": "sites", - "field": "site_key", - "special": null, - "interface": "input", - "options": null, - "display": null, - "display_options": null, - "readonly": false, - "hidden": false, - "sort": 2, - "width": "half", - "translations": null, - "note": null, - "conditions": null, - "required": true, - "group": null, - "validation": null, - "validation_message": null, - "searchable": true - } - }, { "collection": "sites", "field": "company_id", @@ -1488,10 +1489,10 @@ "display_options": { "template": "{{name}}" }, - "readonly": false, + "readonly": true, "hidden": false, "sort": 1, - "width": "full", + "width": "half", "translations": null, "note": null, "conditions": null, @@ -1538,6 +1539,52 @@ "searchable": true } }, + { + "collection": "sites", + "field": "key", + "type": "string", + "schema": { + "name": "key", + "table": "sites", + "data_type": "character varying", + "default_value": null, + "generation_expression": null, + "max_length": 255, + "numeric_precision": null, + "numeric_scale": null, + "is_generated": false, + "is_nullable": true, + "is_unique": true, + "is_indexed": false, + "is_primary_key": false, + "has_auto_increment": false, + "foreign_key_schema": null, + "foreign_key_table": null, + "foreign_key_column": null, + "comment": null + }, + "meta": { + "collection": "sites", + "field": "key", + "special": null, + "interface": "input", + "options": null, + "display": null, + "display_options": null, + "readonly": true, + "hidden": false, + "sort": 2, + "width": "half", + "translations": null, + "note": null, + "conditions": null, + "required": false, + "group": null, + "validation": null, + "validation_message": null, + "searchable": true + } + }, { "collection": "sites", "field": "date_created", @@ -2001,52 +2048,6 @@ "searchable": true } }, - { - "collection": "users", - "field": "user_key", - "type": "string", - "schema": { - "name": "user_key", - "table": "users", - "data_type": "character varying", - "default_value": null, - "generation_expression": null, - "max_length": 255, - "numeric_precision": null, - "numeric_scale": null, - "is_generated": false, - "is_nullable": false, - "is_unique": true, - "is_indexed": false, - "is_primary_key": false, - "has_auto_increment": false, - "foreign_key_schema": null, - "foreign_key_table": null, - "foreign_key_column": null, - "comment": null - }, - "meta": { - "collection": "users", - "field": "user_key", - "special": null, - "interface": "input", - "options": null, - "display": null, - "display_options": null, - "readonly": false, - "hidden": false, - "sort": 2, - "width": "half", - "translations": null, - "note": null, - "conditions": null, - "required": true, - "group": null, - "validation": null, - "validation_message": null, - "searchable": true - } - }, { "collection": "users", "field": "sub", @@ -2093,6 +2094,52 @@ "searchable": true } }, + { + "collection": "users", + "field": "key", + "type": "string", + "schema": { + "name": "key", + "table": "users", + "data_type": "character varying", + "default_value": null, + "generation_expression": null, + "max_length": 255, + "numeric_precision": null, + "numeric_scale": null, + "is_generated": false, + "is_nullable": true, + "is_unique": true, + "is_indexed": false, + "is_primary_key": false, + "has_auto_increment": false, + "foreign_key_schema": null, + "foreign_key_table": null, + "foreign_key_column": null, + "comment": null + }, + "meta": { + "collection": "users", + "field": "key", + "special": null, + "interface": "input", + "options": null, + "display": null, + "display_options": null, + "readonly": true, + "hidden": false, + "sort": 2, + "width": "half", + "translations": null, + "note": null, + "conditions": null, + "required": false, + "group": null, + "validation": null, + "validation_message": null, + "searchable": true + } + }, { "collection": "users", "field": "date_created", @@ -2493,7 +2540,7 @@ "readonly": false, "hidden": false, "sort": 5, - "width": "full", + "width": "half", "translations": null, "note": null, "conditions": null, @@ -2758,10 +2805,10 @@ }, { "collection": "systems", - "field": "system_key", + "field": "key", "type": "string", "schema": { - "name": "system_key", + "name": "key", "table": "systems", "data_type": "character varying", "default_value": null, @@ -2782,7 +2829,7 @@ }, "meta": { "collection": "systems", - "field": "system_key", + "field": "key", "special": null, "interface": "input", "options": null, @@ -3071,6 +3118,42 @@ "searchable": true } }, + { + "collection": "systems", + "field": "roles", + "type": "alias", + "schema": null, + "meta": { + "collection": "systems", + "field": "roles", + "special": [ + "o2m" + ], + "interface": "list-o2m", + "options": { + "layout": "table", + "fields": [ + "name", + "status", + "role_code" + ] + }, + "display": null, + "display_options": null, + "readonly": false, + "hidden": false, + "sort": 4, + "width": "full", + "translations": null, + "note": null, + "conditions": null, + "required": false, + "group": null, + "validation": null, + "validation_message": null, + "searchable": true + } + }, { "collection": "systems", "field": "user_updated", @@ -3151,35 +3234,6 @@ "validation_message": null, "searchable": true } - }, - { - "collection": "systems", - "field": "roles", - "type": "alias", - "schema": null, - "meta": { - "collection": "systems", - "field": "roles", - "special": [ - "o2m" - ], - "interface": "list-o2m", - "options": null, - "display": null, - "display_options": null, - "readonly": false, - "hidden": false, - "sort": null, - "width": "full", - "translations": null, - "note": null, - "conditions": null, - "required": false, - "group": null, - "validation": null, - "validation_message": null, - "searchable": true - } } ], "relations": [ @@ -3313,6 +3367,32 @@ "one_deselect_action": "nullify" } }, + { + "collection": "roles_sites", + "field": "roles_id", + "related_collection": "roles", + "schema": { + "constraint_name": "roles_sites_roles_id_foreign", + "table": "roles_sites", + "column": "roles_id", + "foreign_key_schema": "public", + "foreign_key_table": "roles", + "foreign_key_column": "id", + "on_update": "NO ACTION", + "on_delete": "CASCADE" + }, + "meta": { + "many_collection": "roles_sites", + "many_field": "roles_id", + "one_collection": "roles", + "one_field": "sites", + "one_collection_field": null, + "one_allowed_collections": null, + "junction_field": "sites_id", + "sort_field": null, + "one_deselect_action": "delete" + } + }, { "collection": "roles_sites", "field": "sites_id", @@ -3340,29 +3420,29 @@ } }, { - "collection": "roles_sites", - "field": "roles_id", - "related_collection": "roles", + "collection": "sites", + "field": "company_id", + "related_collection": "companies", "schema": { - "constraint_name": "roles_sites_roles_id_foreign", - "table": "roles_sites", - "column": "roles_id", + "constraint_name": "sites_company_id_foreign", + "table": "sites", + "column": "company_id", "foreign_key_schema": "public", - "foreign_key_table": "roles", + "foreign_key_table": "companies", "foreign_key_column": "id", "on_update": "NO ACTION", - "on_delete": "CASCADE" + "on_delete": "NO ACTION" }, "meta": { - "many_collection": "roles_sites", - "many_field": "roles_id", - "one_collection": "roles", + "many_collection": "sites", + "many_field": "company_id", + "one_collection": "companies", "one_field": "sites", "one_collection_field": null, "one_allowed_collections": null, - "junction_field": "sites_id", + "junction_field": null, "sort_field": null, - "one_deselect_action": "delete" + "one_deselect_action": "nullify" } }, { @@ -3417,32 +3497,6 @@ "one_deselect_action": "nullify" } }, - { - "collection": "sites", - "field": "company_id", - "related_collection": "companies", - "schema": { - "constraint_name": "sites_company_id_foreign", - "table": "sites", - "column": "company_id", - "foreign_key_schema": "public", - "foreign_key_table": "companies", - "foreign_key_column": "id", - "on_update": "NO ACTION", - "on_delete": "NO ACTION" - }, - "meta": { - "many_collection": "sites", - "many_field": "company_id", - "one_collection": "companies", - "one_field": "sites", - "one_collection_field": null, - "one_allowed_collections": null, - "junction_field": null, - "sort_field": null, - "one_deselect_action": "nullify" - } - }, { "collection": "users", "field": "user_updated",