Skip to content

Commit

Permalink
update the down migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
joschne committed Jul 17, 2024
1 parent 91e9669 commit dc19ef9
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 161 deletions.
40 changes: 22 additions & 18 deletions database/migrations/sqls/20240529120605-pgwar-entity-down.sql
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
41 changes: 19 additions & 22 deletions database/migrations/sqls/20240612071824-pgwar-fulltext-down.sql
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;

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;
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/* Replace with your SQL commands */
-- NO WAY BACK
Original file line number Diff line number Diff line change
@@ -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;
DROP FUNCTION IF EXISTS projects.add_entity_preview_partition;
37 changes: 15 additions & 22 deletions database/migrations/sqls/20240627084826-pgwar-field-change-down.sql
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/* Replace with your SQL commands */
-- Drop Functions
-------------------------------------------------------------
DROP FUNCTION pgwar.update_type_label;
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit dc19ef9

Please sign in to comment.