From dc19ef93813d0028eba3a03ded4071a70653403b Mon Sep 17 00:00:00 2001 From: joschne Date: Wed, 17 Jul 2024 17:47:01 +0200 Subject: [PATCH] update the down migrations --- .../sqls/20240529120605-pgwar-entity-down.sql | 40 ++++++----- ...06082339-pgwar-project-statements-down.sql | 44 +++++------- .../20240612071824-pgwar-fulltext-down.sql | 41 +++++------ ...71825-pgwar-project-entity-labels-down.sql | 69 ++++++++++--------- ...2071825-pgwar-project-entity-labels-up.sql | 34 --------- .../20240625144815-war-drop-schema-down.sql | 2 +- .../20240625144815-war-drop-schema-up.sql | 6 +- ...20240627084826-pgwar-field-change-down.sql | 37 ++++------ .../20240628133110-pgwar-type-label-down.sql | 4 +- ...ect-entity-label-by-entity-and-project.sql | 3 - 10 files changed, 119 insertions(+), 161 deletions(-) diff --git a/database/migrations/sqls/20240529120605-pgwar-entity-down.sql b/database/migrations/sqls/20240529120605-pgwar-entity-down.sql index c72d97c42..f9257ca9d 100644 --- a/database/migrations/sqls/20240529120605-pgwar-entity-down.sql +++ b/database/migrations/sqls/20240529120605-pgwar-entity-down.sql @@ -1,25 +1,29 @@ --- Drop triggers ----------------- -DROP TRIGGER add_pgwar_entity_preview_partition ON projects.project; -DROP TRIGGER after_upsert_resource ON information.resource; +-- Revert trigger and trigger function for after_delete_resource +------------------------------------------------------------- DROP TRIGGER after_delete_resource ON information.resource; --- Drop functions ------------------ -DROP FUNCTION pgwar.add_entity_preview_partition; -DROP FUNCTION pgwar.upsert_entity_preview_fk_class; -DROP FUNCTION pgwar.update_from_resource; -DROP FUNCTION pgwar.after_upsert_resource; DROP FUNCTION pgwar.after_delete_resource; --- Drop partitions ------------------- -DROP TABLE pgwar.entity_preview_0; +-- Revert triggers and trigger function for after_upsert_resource +-------------------------------------------------------------- +DROP TRIGGER after_update_resource ON information.resource; + +DROP TRIGGER after_insert_resource ON information.resource; + +DROP FUNCTION pgwar.after_upsert_resource; + +-- Revert function to update pgwar from resource +---------------------------------------------- +DROP FUNCTION pgwar.update_from_resource; + +-- Revert function to upsert fk_project, pk_entity, fk_class on pgwar.entity_preview +----------------------------------------------------------------------------- +DROP FUNCTION pgwar.upsert_entity_preview_fk_class; --- Drop tables --------------- +-- Revert table pgwar.entity_preview +------------------------------ DROP TABLE pgwar.entity_preview; --- Drop schema --------------- -DROP SCHEMA pgwar; +-- Revert schema pgwar +------------------------------ +DROP SCHEMA pgwar; \ No newline at end of file diff --git a/database/migrations/sqls/20240606082339-pgwar-project-statements-down.sql b/database/migrations/sqls/20240606082339-pgwar-project-statements-down.sql index 8d2f15878..592a27906 100644 --- a/database/migrations/sqls/20240606082339-pgwar-project-statements-down.sql +++ b/database/migrations/sqls/20240606082339-pgwar-project-statements-down.sql @@ -1,29 +1,21 @@ --- Drop trigger after_delete_pgw_statement -DROP TRIGGER after_delete_pgw_statement ON pgwar.statement; - --- Drop function pgwar.after_delete_pgw_statement -DROP FUNCTION pgwar.after_delete_pgw_statement; - --- Drop trigger after_upsert_pgw_statement -DROP TRIGGER after_upsert_pgw_statement ON pgwar.statement; - --- Drop function pgwar.after_upsert_pgw_statement -DROP FUNCTION pgwar.after_upsert_pgw_statement; - --- Drop trigger after_modify_info_proj_rel +-- Triggers +---------------------------------------------- DROP TRIGGER after_modify_info_proj_rel ON projects.info_proj_rel; - --- Drop function pgwar.after_modify_info_proj_rel -DROP FUNCTION pgwar.after_modify_info_proj_rel; - --- Drop function pgwar.update_from_info_proj_rel -DROP FUNCTION pgwar.update_from_info_proj_rel; - --- Drop function pgwar.upsert_project_statements -DROP FUNCTION pgwar.upsert_project_statements; - --- Drop trigger last_modification_tmsp on pgwar.project_statements +DROP TRIGGER after_upsert_pgw_statement ON pgwar.statement; +DROP TRIGGER after_delete_pgw_statement ON pgwar.statement; DROP TRIGGER last_modification_tmsp ON pgwar.project_statements; - --- Drop table pgwar.project_statements +DROP TRIGGER after_delete_project_statements ON pgwar.project_statements; + +-- Functions +---------------------------------------------- +DROP FUNCTION pgwar.after_modify_info_proj_rel(); +DROP FUNCTION pgwar.update_from_info_proj_rel(projects.info_proj_rel, boolean); +DROP FUNCTION pgwar.after_upsert_pgw_statement(); +DROP FUNCTION pgwar.after_delete_pgw_statement(); +DROP FUNCTION pgwar.handle_project_statements_delete(); +DROP FUNCTION pgwar.upsert_project_statements(pgwar.project_statements); + +-- Tables +---------------------------------------------- DROP TABLE pgwar.project_statements; +DROP TABLE pgwar.project_statements_deleted; \ No newline at end of file diff --git a/database/migrations/sqls/20240612071824-pgwar-fulltext-down.sql b/database/migrations/sqls/20240612071824-pgwar-fulltext-down.sql index 1486ec4fa..65c9bed3d 100644 --- a/database/migrations/sqls/20240612071824-pgwar-fulltext-down.sql +++ b/database/migrations/sqls/20240612071824-pgwar-fulltext-down.sql @@ -1,31 +1,28 @@ -- Drop triggers -DROP TRIGGER after_delete_project_statements ON pgwar.project_statements; -DROP TRIGGER last_modification_tmsp ON pgwar.entity_full_text; DROP TRIGGER after_upsert_entity_full_text ON pgwar.entity_full_text; --- Drop trigger functions -DROP FUNCTION pgwar.handle_project_statements_delete; -DROP FUNCTION pgwar.update_entity_preview_full_text; - -- Drop functions -DROP FUNCTION pgwar.get_label_of_outgoing_field; -DROP FUNCTION pgwar.get_label_of_incoming_field; -DROP FUNCTION pgwar.get_property_label; -DROP FUNCTION pgwar.get_property_inverse_label; -DROP FUNCTION pgwar.get_project_lang_code; -DROP FUNCTION pgwar.get_project_full_text; -DROP FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt; -DROP FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt; -DROP FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_del; -DROP FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_del; -DROP FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop; -DROP FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop; -DROP FUNCTION pgwar.get_outdated_full_texts; -DROP FUNCTION pgwar.update_full_texts; +DROP FUNCTION pgwar.update_entity_preview_full_text(); +DROP FUNCTION pgwar.update_full_texts(int); +DROP FUNCTION pgwar.get_outdated_full_texts(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_del(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt(int); +DROP FUNCTION pgwar.get_project_full_text(int, int); +DROP FUNCTION pgwar.get_project_lang_code(int); +DROP FUNCTION pgwar.get_property_inverse_label(int, text); +DROP FUNCTION pgwar.get_property_label(int, text); +DROP FUNCTION pgwar.get_label_of_incoming_field(int, int, int, int); +DROP FUNCTION pgwar.get_label_of_outgoing_field(int, int, int, int); +DROP FUNCTION pgwar.get_target_label_of_field(int, int, jsonb); +DROP FUNCTION pgwar.get_target_labels_of_incoming_field(int, int, int, int); +DROP FUNCTION pgwar.get_target_labels_of_outgoing_field(int, int, int, int); -- Drop tables -DROP TABLE pgwar.project_statements_deleted; DROP TABLE pgwar.entity_full_text; --- Drop dblink extension +-- Drop extension DROP EXTENSION dblink; diff --git a/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-down.sql b/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-down.sql index cfcfb0292..07857e05d 100644 --- a/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-down.sql +++ b/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-down.sql @@ -1,42 +1,49 @@ -/*** -* Drop Triggers -***/ - --- Drop trigger on pgwar.project_statements -DROP TRIGGER on_modify_project_statement ON pgwar.project_statements; +/** +* Triggers +**/ --- Drop triggers on pgwar.entity_preview -DROP TRIGGER on_upsert_entity_preview_fk_class ON pgwar.entity_preview; -DROP TRIGGER after_upsert_entity_preview_entity_label_01 ON pgwar.entity_preview; +DROP TRIGGER after_insert_entity_preview ON pgwar.entity_preview; +DROP TRIGGER after_update_entity_preview ON pgwar.entity_preview; DROP TRIGGER after_delete_entity_preview_01 ON pgwar.entity_preview; - --- Drop trigger on projects.entity_label_config +DROP TRIGGER after_insert_project_statement ON pgwar.project_statements; +DROP TRIGGER after_update_project_statement ON pgwar.project_statements; +DROP TRIGGER after_delete_project_statement ON pgwar.project_statements; DROP TRIGGER on_upsert_entity_label_config ON projects.entity_label_config; /*** -* Drop Functions +* Trigger Functions ***/ --- Drop functions for label retrieval and update -DROP FUNCTION pgwar.get_project_entity_label(entity_id int, project_id int); -DROP FUNCTION pgwar.update_entity_label_of_entity_preview; -DROP FUNCTION pgwar.get_and_update_project_entity_label; - --- Drop functions for label calculation -DROP FUNCTION pgwar.get_target_labels_of_incoming_field; -DROP FUNCTION pgwar.get_target_labels_of_outgoing_field; -DROP FUNCTION pgwar.get_target_label_of_field; - --- Drop trigger functions for label update on changes -DROP FUNCTION pgwar.update_entity_label_on_project_statement_change; -DROP FUNCTION pgwar.update_entity_label_on_fk_class_change; -DROP FUNCTION pgwar.update_entity_label_on_entity_label_change; +DROP FUNCTION pgwar.update_entity_label_on_project_statement_upsert; +DROP FUNCTION pgwar.update_entity_label_on_project_statement_delete; +DROP FUNCTION pgwar.update_entity_labels_after_insert; +DROP FUNCTION pgwar.update_entity_labels_after_update; +DROP FUNCTION pgwar.update_entity_labels_after_delete; DROP FUNCTION pgwar.update_entity_label_on_entity_label_config_change; /*** -* Drop Indexes +* Functions ***/ -DROP INDEX pgwar.entity_label_config_fk_class_idx; -DROP INDEX pgwar.entity_label_config_fk_project_idx; -DROP INDEX pgwar.project_statements_fk_project_fk_object_info_fk_project_idx; -DROP INDEX pgwar.project_statements_fk_project_fk_subject_info_fk_project_idx; \ No newline at end of file + +DROP FUNCTION pgwar.get_entity_label_config(int, int); +DROP FUNCTION pgwar.get_project_entity_label(int, int); +DROP FUNCTION pgwar.get_project_entity_label(int, int, int); +DROP FUNCTION pgwar.get_project_entity_label(int, int, jsonb); +DROP FUNCTION pgwar.update_entity_label_of_entity_preview(int, int, text); +DROP FUNCTION pgwar.get_and_update_project_entity_label(int, int); + +/** +* Views +**/ + +DROP VIEW pgwar.v_community_entity_label; + +/** +* Indexes used by get_project_entity_label +**/ + +DROP INDEX pgwar.project_statements_fk_object_info_fk_project_fk_property_idx; +DROP INDEX pgwar.project_statements_fk_subject_info_fk_project_fk_property_dx; +DROP INDEX pgwar.project_statements_fk_project_fk_property_dx; +DROP INDEX pgwar.project_statements_fk_project_dx; +DROP INDEX information.resource_pk_entity_fk_class_dx; diff --git a/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-up.sql b/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-up.sql index b63540cea..936716953 100644 --- a/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-up.sql +++ b/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-up.sql @@ -20,38 +20,6 @@ CREATE INDEX IF NOT EXISTS resource_pk_entity_fk_class_dx /** * Views **/ -CREATE MATERIALIZED VIEW pgwar.project_label_config AS -SELECT subquery.fk_project, - subquery.fk_class, - (field->'fkProperty')::int fk_property, - (field->'isOutgoing')::bool is_outgoing, - (field->'nrOfStatementsInLabel')::int nr_of_stmts, - ROW_NUMBER() OVER ( - PARTITION BY subquery.fk_class, subquery.fk_project - ) AS ord_num -FROM ( - SELECT - COALESCE(default_elc.fk_project, elc.fk_project) AS fk_project, - COALESCE(elc.fk_class, default_elc.fk_class) AS fk_class, - jsonb_array_elements(COALESCE(elc.config, default_elc.config)->'labelParts')->'field' field - FROM ( - SELECT p.pk_entity AS fk_project, fk_class, config - FROM projects.project p - JOIN projects.entity_label_config default_elc - ON default_elc.fk_project = 375669 - ) default_elc - FULL OUTER JOIN projects.entity_label_config elc - ON elc.fk_project = default_elc.fk_project - AND elc.fk_class = default_elc.fk_class -) subquery; - - -CREATE INDEX project_label_config_fk_class_idx -ON pgwar.project_label_config (fk_class); - -CREATE INDEX project_label_config_idx -ON pgwar.project_label_config (fk_project, fk_property, is_outgoing, nr_of_stmts); - CREATE VIEW pgwar.v_community_entity_label AS WITH entity_label_counts AS ( @@ -540,8 +508,6 @@ DECLARE class_id int; BEGIN - REFRESH MATERIALIZED VIEW pgwar.project_label_config; - project_id := COALESCE(NEW.fk_project, OLD.fk_project); class_id := COALESCE(NEW.fk_class, OLD.fk_class); diff --git a/database/migrations/sqls/20240625144815-war-drop-schema-down.sql b/database/migrations/sqls/20240625144815-war-drop-schema-down.sql index 44f074ea8..01cc935d0 100644 --- a/database/migrations/sqls/20240625144815-war-drop-schema-down.sql +++ b/database/migrations/sqls/20240625144815-war-drop-schema-down.sql @@ -1 +1 @@ -/* Replace with your SQL commands */ \ No newline at end of file +-- NO WAY BACK \ No newline at end of file diff --git a/database/migrations/sqls/20240625144815-war-drop-schema-up.sql b/database/migrations/sqls/20240625144815-war-drop-schema-up.sql index e25e6eba5..c7bafbf40 100644 --- a/database/migrations/sqls/20240625144815-war-drop-schema-up.sql +++ b/database/migrations/sqls/20240625144815-war-drop-schema-up.sql @@ -1,5 +1,5 @@ -DROP SCHEMA war CASCADE; +DROP SCHEMA IF EXISTS war CASCADE; -DROP TRIGGER add_entity_preview_partition ON projects.project; +DROP TRIGGER IF EXISTS add_entity_preview_partition ON projects.project; -DROP FUNCTION projects.add_entity_preview_partition; \ No newline at end of file +DROP FUNCTION IF EXISTS projects.add_entity_preview_partition; \ No newline at end of file diff --git a/database/migrations/sqls/20240627084826-pgwar-field-change-down.sql b/database/migrations/sqls/20240627084826-pgwar-field-change-down.sql index 3062a9886..65cd2b57c 100644 --- a/database/migrations/sqls/20240627084826-pgwar-field-change-down.sql +++ b/database/migrations/sqls/20240627084826-pgwar-field-change-down.sql @@ -1,22 +1,15 @@ --- Function pgwar.field_change_notify_upsert ----------------------------------------------- -DROP FUNCTION IF EXISTS pgwar.field_change_notify_upser; -DROP TRIGGER IF EXISTS after_insert_field_change ON pgwar.field_change; -DROP TRIGGER IF EXISTS after_update_field_change ON pgwar.field_change; - --- Trigger after_modify_project_statements ----------------------------------------------- -DROP TRIGGER IF EXISTS after_modify_project_statements ON pgwar.project_statements; - --- Function upsert_field_change ----------------------------------------------- -DROP FUNCTION IF EXISTS pgwar.upsert_field_change; -DROP FUNCTION IF EXISTS pgwar.update_field_change_on_project_statements_modification; - ------- Table pgwar.field_change ----------------------------------------------------- ---------------------------------------------------------------------------------------------- -DROP TABLE IF EXISTS pgwar.field_change; - - - - +-- Drop Triggers +------------------------------------------------------------- +DROP TRIGGER after_update_field_change ON pgwar.field_change; +DROP TRIGGER after_insert_field_change ON pgwar.field_change; +DROP TRIGGER after_modify_project_statements ON pgwar.project_statements; + +-- Drop Functions +------------------------------------------------------------- +DROP FUNCTION pgwar.field_change_notify_upsert; +DROP FUNCTION pgwar.update_field_change_on_project_statements_modification; +DROP FUNCTION pgwar.upsert_field_change; + +-- Drop Table +------------------------------------------------------------- +DROP TABLE pgwar.field_change; diff --git a/database/migrations/sqls/20240628133110-pgwar-type-label-down.sql b/database/migrations/sqls/20240628133110-pgwar-type-label-down.sql index 44f074ea8..2b69836b5 100644 --- a/database/migrations/sqls/20240628133110-pgwar-type-label-down.sql +++ b/database/migrations/sqls/20240628133110-pgwar-type-label-down.sql @@ -1 +1,3 @@ -/* Replace with your SQL commands */ \ No newline at end of file +-- Drop Functions +------------------------------------------------------------- +DROP FUNCTION pgwar.update_type_label; diff --git a/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project.sql b/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project.sql index 7f48f3d07..4e27f210f 100644 --- a/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project.sql +++ b/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project.sql @@ -73,9 +73,6 @@ VALUES ( }'::jsonb ); --- this is normally done by on_upsert_entity_label_config trigger -REFRESH MATERIALIZED VIEW pgwar.project_label_config; - -- Test 1: Check if function returns the correct entity label SELECT is( pgwar.get_project_entity_label(123, 1),