Skip to content

Commit

Permalink
Fix trimming issue and save to name field
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Nov 29, 2023
1 parent 366f5a0 commit ee07138
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.4 on 2023-11-29 11:48
# Generated by Django 4.2.4 on 2023-11-29 13:48

from django.db import migrations
import pgtrigger.compiler
Expand Down Expand Up @@ -38,8 +38,8 @@ class Migration(migrations.Migration):
name="calculate_multicard_primary_descriptor_all",
sql=pgtrigger.compiler.UpsertTriggerSql(
condition='WHEN (NEW."config" IS NOT NULL AND NEW."functionid" = \'00b2d15a-fda0-4578-b79a-784e4138664b\'::uuid)',
func="\nDECLARE\n fn_config jsonb;\n name_template text;\n map_popup_template text;\n description_template text;\n all_templates text[];\n this_template text;\n loop_index int;\n descriptor_key text;\n\n graph UUID;\n resourceid UUID;\n node_alias text;\n alias_with_separators text;\n node_for_alias UUID;\n nodegroup_for_alias UUID;\n localized_string_node_value jsonb;\n lang text;\n inner18n_obj_for_lang jsonb;\n resolved_node_value_for_lang text;\n working_string text;\n localized_calculated_result jsonb;\n\nBEGIN\n\nSELECT NEW.config, NEW.graphid\nINTO fn_config, graph;\n\nFOR resourceid IN (SELECT resourceinstanceid FROM resource_instances WHERE graphid = graph)\nLOOP\n SELECT JSONB_OBJECT('{}') INTO localized_calculated_result;\n SELECT fn_config -> 'descriptor_types' -> 'name' -> 'string_template' INTO name_template;\n SELECT fn_config -> 'descriptor_types' -> 'map_popup' -> 'string_template' INTO map_popup_template;\n SELECT fn_config -> 'descriptor_types' -> 'description' -> 'string_template' INTO description_template;\n\n SELECT ARRAY[name_template, map_popup_template, description_template] INTO all_templates;\n SELECT 0 INTO loop_index;\n FOR this_template IN SELECT UNNEST(all_templates)\n LOOP\n SELECT loop_index + 1 INTO loop_index;\n SELECT\n CASE\n WHEN loop_index = 1 THEN 'name'\n WHEN loop_index = 2 THEN 'map_popup'\n ELSE 'description'\n END\n INTO descriptor_key;\n\n -- Resolve node values to localized strings\n FOR alias_with_separators IN SELECT UNNEST(REGEXP_MATCHES(this_template, '<\\w+>', 'g'))\n LOOP\n SELECT TRIM(BOTH '<>' FROM alias_with_separators) INTO node_alias;\n\n SELECT nodeid, nodegroupid INTO node_for_alias, nodegroup_for_alias\n FROM nodes\n WHERE alias = node_alias\n AND graphid = graph;\n\n SELECT tiledata ->> node_for_alias::text INTO localized_string_node_value\n FROM tiles\n WHERE resourceinstanceid = resourceid\n AND nodegroupid = nodegroup_for_alias\n AND sortorder = 0\n LIMIT 1;\n\n -- Replace template with localized string\n FOR lang, inner18n_obj_for_lang IN SELECT * FROM jsonb_each(localized_string_node_value) \n LOOP\n -- Initialize language key if missing\n IF localized_calculated_result -> lang IS NULL THEN\n SELECT jsonb_set(\n localized_calculated_result,\n ARRAY[lang],\n JSONB_OBJECT('{}')\n ) INTO localized_calculated_result;\n END IF;\n\n -- Retrieve the current working value, or start from the template\n SELECT\n CASE\n WHEN localized_calculated_result -> lang -> descriptor_key IS NULL\n THEN this_template\n ELSE (localized_calculated_result -> lang -> descriptor_key)::text\n END\n INTO working_string;\n\n SELECT TRIM(\n REPLACE(\n working_string,\n alias_with_separators,\n (inner18n_obj_for_lang -> 'value')::text\n )\n , '\"')\n INTO resolved_node_value_for_lang;\n\n -- Update the working value\n SELECT jsonb_set(\n localized_calculated_result,\n ARRAY[lang, descriptor_key],\n TO_JSONB(resolved_node_value_for_lang)\n ) INTO localized_calculated_result;\n\n END LOOP;\n\n END LOOP;\n\n END LOOP;\n\n UPDATE resource_instances\n SET descriptors = localized_calculated_result\n WHERE resourceinstanceid = resourceid;\n\nEND LOOP;\nEND;\nRETURN NULL;\n",
hash="66fb3ae091e1c43f755d4b870bd14cc9881de864",
func="\nDECLARE\n fn_config jsonb;\n name_template text;\n map_popup_template text;\n description_template text;\n all_templates text[];\n this_template text;\n loop_index int;\n descriptor_key text;\n\n graph UUID;\n resourceid UUID;\n node_alias text;\n alias_with_separators text;\n node_for_alias UUID;\n nodegroup_for_alias UUID;\n localized_string_node_value jsonb;\n lang text;\n inner18n_obj_for_lang jsonb;\n resolved_node_value_for_lang text;\n working_string text;\n localized_result_all jsonb;\n localized_result_name_only jsonb;\n\nBEGIN\n\nSELECT NEW.config, NEW.graphid\nINTO fn_config, graph;\n\nFOR resourceid IN (SELECT resourceinstanceid FROM resource_instances WHERE graphid = graph)\nLOOP\n SELECT JSONB_OBJECT('{}') INTO localized_result_all;\n SELECT JSONB_OBJECT('{}') INTO localized_result_name_only;\n SELECT fn_config -> 'descriptor_types' -> 'name' -> 'string_template' INTO name_template;\n SELECT fn_config -> 'descriptor_types' -> 'map_popup' -> 'string_template' INTO map_popup_template;\n SELECT fn_config -> 'descriptor_types' -> 'description' -> 'string_template' INTO description_template;\n\n SELECT ARRAY[name_template, map_popup_template, description_template] INTO all_templates;\n SELECT 0 INTO loop_index;\n FOR this_template IN SELECT UNNEST(all_templates)\n LOOP\n SELECT loop_index + 1 INTO loop_index;\n SELECT\n CASE\n WHEN loop_index = 1 THEN 'name'\n WHEN loop_index = 2 THEN 'map_popup'\n ELSE 'description'\n END\n INTO descriptor_key;\n\n -- Resolve node values to localized strings\n FOR alias_with_separators IN SELECT UNNEST(REGEXP_MATCHES(this_template, '<\\w+>', 'g'))\n LOOP\n SELECT TRIM(BOTH '<>' FROM alias_with_separators) INTO node_alias;\n\n SELECT nodeid, nodegroupid INTO node_for_alias, nodegroup_for_alias\n FROM nodes\n WHERE alias = node_alias\n AND graphid = graph;\n\n SELECT tiledata ->> node_for_alias::text INTO localized_string_node_value\n FROM tiles\n WHERE resourceinstanceid = resourceid\n AND nodegroupid = nodegroup_for_alias\n AND sortorder = 0\n LIMIT 1;\n\n -- Replace template with localized string\n FOR lang, inner18n_obj_for_lang IN SELECT * FROM jsonb_each(localized_string_node_value) \n LOOP\n -- Initialize language key if missing\n IF localized_result_all -> lang IS NULL THEN\n SELECT jsonb_set(\n localized_result_all,\n ARRAY[lang],\n JSONB_OBJECT('{}')\n ) INTO localized_result_all;\n END IF;\n\n -- Retrieve the current working value, or start from the template\n SELECT\n CASE\n WHEN localized_result_all -> lang -> descriptor_key IS NULL\n THEN this_template\n ELSE TRIM((localized_result_all -> lang -> descriptor_key)::text, '\\\"')\n END\n INTO working_string;\n\n SELECT REPLACE(\n working_string,\n alias_with_separators,\n TRIM((inner18n_obj_for_lang -> 'value')::text, '\"')\n )\n INTO resolved_node_value_for_lang;\n\n -- Update the working value\n SELECT jsonb_set(\n localized_result_all,\n ARRAY[lang, descriptor_key],\n TO_JSONB(resolved_node_value_for_lang)\n ) INTO localized_result_all;\n\n IF descriptor_key = 'name' THEN\n SELECT jsonb_set(\n localized_result_name_only,\n ARRAY[lang],\n TO_JSONB(resolved_node_value_for_lang)\n ) INTO localized_result_name_only;\n END IF;\n\n END LOOP;\n\n END LOOP;\n\n END LOOP;\n\n UPDATE resource_instances\n SET descriptors = localized_result_all, name = localized_result_name_only\n WHERE resourceinstanceid = resourceid;\n\nEND LOOP;\nEND;\nRETURN NULL;\n",
hash="4fa923b9bb279654c25cdf95a42b3620d974385e",
operation="INSERT OR UPDATE",
pgid="pgtrigger_calculate_multicard_primary_descriptor_all_3029e",
table="functions_x_graphs",
Expand All @@ -53,8 +53,8 @@ class Migration(migrations.Migration):
name="calculate_multicard_primary_descriptor_single",
sql=pgtrigger.compiler.UpsertTriggerSql(
constraint="CONSTRAINT",
func="\nDECLARE\n fn_config jsonb;\n name_template text;\n map_popup_template text;\n description_template text;\n all_templates text[];\n this_template text;\n loop_index int;\n descriptor_key text;\n\n graph UUID;\n resourceid UUID;\n node_alias text;\n alias_with_separators text;\n node_for_alias UUID;\n nodegroup_for_alias UUID;\n localized_string_node_value jsonb;\n lang text;\n inner18n_obj_for_lang jsonb;\n resolved_node_value_for_lang text;\n working_string text;\n localized_calculated_result jsonb;\n\nBEGIN\n\nSELECT NEW.resourceinstanceid INTO resourceid;\n\nSELECT functions_x_graphs.config, g.graphid\nINTO fn_config, graph\nFROM functions_x_graphs\nINNER JOIN resource_instances AS r ON r.resourceinstanceid = resourceid\nINNER JOIN graphs AS g on r.graphid = g.graphid\nWHERE\n functionid = '00b2d15a-fda0-4578-b79a-784e4138664b'\n AND functions_x_graphs.config IS NOT NULL\n AND functions_x_graphs.graphid = g.graphid;\n\nIF FOUND THEN\n SELECT JSONB_OBJECT('{}') INTO localized_calculated_result;\n SELECT fn_config -> 'descriptor_types' -> 'name' -> 'string_template' INTO name_template;\n SELECT fn_config -> 'descriptor_types' -> 'map_popup' -> 'string_template' INTO map_popup_template;\n SELECT fn_config -> 'descriptor_types' -> 'description' -> 'string_template' INTO description_template;\n\n SELECT ARRAY[name_template, map_popup_template, description_template] INTO all_templates;\n SELECT 0 INTO loop_index;\n FOR this_template IN SELECT UNNEST(all_templates)\n LOOP\n SELECT loop_index + 1 INTO loop_index;\n SELECT\n CASE\n WHEN loop_index = 1 THEN 'name'\n WHEN loop_index = 2 THEN 'map_popup'\n ELSE 'description'\n END\n INTO descriptor_key;\n\n -- Resolve node values to localized strings\n FOR alias_with_separators IN SELECT UNNEST(REGEXP_MATCHES(this_template, '<\\w+>', 'g'))\n LOOP\n SELECT TRIM(BOTH '<>' FROM alias_with_separators) INTO node_alias;\n\n SELECT nodeid, nodegroupid INTO node_for_alias, nodegroup_for_alias\n FROM nodes\n WHERE alias = node_alias\n AND graphid = graph;\n\n SELECT tiledata ->> node_for_alias::text INTO localized_string_node_value\n FROM tiles\n WHERE resourceinstanceid = resourceid\n AND nodegroupid = nodegroup_for_alias\n AND sortorder = 0\n LIMIT 1;\n\n -- Replace template with localized string\n FOR lang, inner18n_obj_for_lang IN SELECT * FROM jsonb_each(localized_string_node_value) \n LOOP\n -- Initialize language key if missing\n IF localized_calculated_result -> lang IS NULL THEN\n SELECT jsonb_set(\n localized_calculated_result,\n ARRAY[lang],\n JSONB_OBJECT('{}')\n ) INTO localized_calculated_result;\n END IF;\n\n -- Retrieve the current working value, or start from the template\n SELECT\n CASE\n WHEN localized_calculated_result -> lang -> descriptor_key IS NULL\n THEN this_template\n ELSE (localized_calculated_result -> lang -> descriptor_key)::text\n END\n INTO working_string;\n\n SELECT TRIM(\n REPLACE(\n working_string,\n alias_with_separators,\n (inner18n_obj_for_lang -> 'value')::text\n )\n , '\"')\n INTO resolved_node_value_for_lang;\n\n -- Update the working value\n SELECT jsonb_set(\n localized_calculated_result,\n ARRAY[lang, descriptor_key],\n TO_JSONB(resolved_node_value_for_lang)\n ) INTO localized_calculated_result;\n\n END LOOP;\n\n END LOOP;\n\n END LOOP;\n\n UPDATE resource_instances\n SET descriptors = localized_calculated_result\n WHERE resourceinstanceid = resourceid;\n\nEND IF;\nEND;\nRETURN NULL;\n",
hash="857299365c67071f2e7863f766aaba21b941fb33",
func="\nDECLARE\n fn_config jsonb;\n name_template text;\n map_popup_template text;\n description_template text;\n all_templates text[];\n this_template text;\n loop_index int;\n descriptor_key text;\n\n graph UUID;\n resourceid UUID;\n node_alias text;\n alias_with_separators text;\n node_for_alias UUID;\n nodegroup_for_alias UUID;\n localized_string_node_value jsonb;\n lang text;\n inner18n_obj_for_lang jsonb;\n resolved_node_value_for_lang text;\n working_string text;\n localized_result_all jsonb;\n localized_result_name_only jsonb;\n\nBEGIN\n\nSELECT NEW.resourceinstanceid INTO resourceid;\nSELECT graphid INTO graph FROM resource_instances WHERE resourceinstanceid = resourceid;\n\nSELECT config\nINTO fn_config\nFROM functions_x_graphs\nWHERE\n functionid = '00b2d15a-fda0-4578-b79a-784e4138664b'\n AND functions_x_graphs.config IS NOT NULL\n AND graph = graphid;\n\nIF FOUND THEN\n SELECT JSONB_OBJECT('{}') INTO localized_result_all;\n SELECT JSONB_OBJECT('{}') INTO localized_result_name_only;\n SELECT fn_config -> 'descriptor_types' -> 'name' -> 'string_template' INTO name_template;\n SELECT fn_config -> 'descriptor_types' -> 'map_popup' -> 'string_template' INTO map_popup_template;\n SELECT fn_config -> 'descriptor_types' -> 'description' -> 'string_template' INTO description_template;\n\n SELECT ARRAY[name_template, map_popup_template, description_template] INTO all_templates;\n SELECT 0 INTO loop_index;\n FOR this_template IN SELECT UNNEST(all_templates)\n LOOP\n SELECT loop_index + 1 INTO loop_index;\n SELECT\n CASE\n WHEN loop_index = 1 THEN 'name'\n WHEN loop_index = 2 THEN 'map_popup'\n ELSE 'description'\n END\n INTO descriptor_key;\n\n -- Resolve node values to localized strings\n FOR alias_with_separators IN SELECT UNNEST(REGEXP_MATCHES(this_template, '<\\w+>', 'g'))\n LOOP\n SELECT TRIM(BOTH '<>' FROM alias_with_separators) INTO node_alias;\n\n SELECT nodeid, nodegroupid INTO node_for_alias, nodegroup_for_alias\n FROM nodes\n WHERE alias = node_alias\n AND graphid = graph;\n\n SELECT tiledata ->> node_for_alias::text INTO localized_string_node_value\n FROM tiles\n WHERE resourceinstanceid = resourceid\n AND nodegroupid = nodegroup_for_alias\n AND sortorder = 0\n LIMIT 1;\n\n -- Replace template with localized string\n FOR lang, inner18n_obj_for_lang IN SELECT * FROM jsonb_each(localized_string_node_value) \n LOOP\n -- Initialize language key if missing\n IF localized_result_all -> lang IS NULL THEN\n SELECT jsonb_set(\n localized_result_all,\n ARRAY[lang],\n JSONB_OBJECT('{}')\n ) INTO localized_result_all;\n END IF;\n\n -- Retrieve the current working value, or start from the template\n SELECT\n CASE\n WHEN localized_result_all -> lang -> descriptor_key IS NULL\n THEN this_template\n ELSE TRIM((localized_result_all -> lang -> descriptor_key)::text, '\\\"')\n END\n INTO working_string;\n\n SELECT REPLACE(\n working_string,\n alias_with_separators,\n TRIM((inner18n_obj_for_lang -> 'value')::text, '\"')\n )\n INTO resolved_node_value_for_lang;\n\n -- Update the working value\n SELECT jsonb_set(\n localized_result_all,\n ARRAY[lang, descriptor_key],\n TO_JSONB(resolved_node_value_for_lang)\n ) INTO localized_result_all;\n\n IF descriptor_key = 'name' THEN\n SELECT jsonb_set(\n localized_result_name_only,\n ARRAY[lang],\n TO_JSONB(resolved_node_value_for_lang)\n ) INTO localized_result_name_only;\n END IF;\n\n END LOOP;\n\n END LOOP;\n\n END LOOP;\n\n UPDATE resource_instances\n SET descriptors = localized_result_all, name = localized_result_name_only\n WHERE resourceinstanceid = resourceid;\n\nEND IF;\nEND;\nRETURN NULL;\n",
hash="b29436e21dec77b4e176cc0f31227029a15d9b5b",
operation="INSERT OR UPDATE OR DELETE",
pgid="pgtrigger_calculate_multicard_primary_descriptor_single_26494",
table="tiles",
Expand Down
Loading

0 comments on commit ee07138

Please sign in to comment.