From ccd77a8ff7b0c15b116579d6dc6bf9da56654d16 Mon Sep 17 00:00:00 2001 From: joschne Date: Thu, 13 Jun 2024 12:16:19 +0200 Subject: [PATCH 01/15] allow fk_project=0 in get-outdate-* and get-target-labels-of-* functions --- ...240613085447-pgwar-community-statements.js | 53 +++++++++ ...0606082339-pgwar-project-statements-up.sql | 12 +- ...6151842-pgwar-project-entity-labels-up.sql | 4 +- .../sqls/20240612071824-pgwar-fulltext-up.sql | 87 +++++--------- ...085447-pgwar-community-statements-down.sql | 1 + ...13085447-pgwar-community-statements-up.sql | 107 ++++++++++++++++++ .../test-pgwar-project-statements.sql | 98 +++++++++------- ...-texts-in-objects-of-stmt-by-dfh-prop.sql} | 24 +++- ...ted-full-texts-in-objects-of-stmt-del.sql} | 26 +++-- ...utdated-full-texts-in-objects-of-stmt.sql} | 27 +++-- ...texts-in-subjects-of-stmt-by-dfh-prop.sql} | 28 ++++- ...ed-full-texts-in-subjects-of-stmt-del.sql} | 25 +++- ...tdated-full-texts-in-subjects-of-stmt.sql} | 23 +++- ...ar-get-target-labels-of-incoming-field.sql | 59 ++++++++-- ...ar-get-target-labels-of-outgoing-field.sql | 59 ++++++++-- server/package-lock.json | 101 ++++++++++------- server/package.json | 2 +- 17 files changed, 529 insertions(+), 207 deletions(-) create mode 100644 database/migrations/20240613085447-pgwar-community-statements.js create mode 100644 database/migrations/sqls/20240613085447-pgwar-community-statements-down.sql create mode 100644 database/migrations/sqls/20240613085447-pgwar-community-statements-up.sql rename database/test/units/functions/{pgwar-get-outdated-full-texts-in-objects-of-pstmt-by-dfh-prop.sql => pgwar-get-outdated-full-texts-in-objects-of-stmt-by-dfh-prop.sql} (67%) rename database/test/units/functions/{pgwar-get-outdated-full-texts-in-objects-of-pstmt-del.sql => pgwar-get-outdated-full-texts-in-objects-of-stmt-del.sql} (66%) rename database/test/units/functions/{pgwar-get-outdated-full-texts-in-objects-of-pstmt.sql => pgwar-get-outdated-full-texts-in-objects-of-stmt.sql} (65%) rename database/test/units/functions/{pgwar-get-outdated-full-texts-in-subjects-of-pstmt-by-dfh-prop.sql => pgwar-get-outdated-full-texts-in-subjects-of-stmt-by-dfh-prop.sql} (63%) rename database/test/units/functions/{pgwar-get-outdated-full-texts-in-subjects-of-pstmt-del.sql => pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql} (67%) rename database/test/units/functions/{pgwar-get-outdated-full-texts-in-subjects-of-pstmt.sql => pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql} (70%) diff --git a/database/migrations/20240613085447-pgwar-community-statements.js b/database/migrations/20240613085447-pgwar-community-statements.js new file mode 100644 index 000000000..807aea3a0 --- /dev/null +++ b/database/migrations/20240613085447-pgwar-community-statements.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240613085447-pgwar-community-statements-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240613085447-pgwar-community-statements-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql b/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql index 8298a0b4d..333daf8e7 100644 --- a/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql +++ b/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql @@ -7,8 +7,8 @@ CREATE TABLE IF NOT EXISTS pgwar.project_statements( fk_property integer NOT NULL, fk_object_info integer, fk_object_tables_cell bigint, - ord_num_of_domain integer, - ord_num_of_range integer, + ord_num_of_domain numeric, + ord_num_of_range numeric, object_label varchar(100), object_value jsonb, tmsp_last_modification timestamp with time zone, @@ -101,8 +101,8 @@ BEGIN statement.fk_property, statement.fk_object_info, statement.fk_object_tables_cell, - NEW.ord_num_of_domain, - NEW.ord_num_of_range, + NEW.ord_num_of_domain::numeric, + NEW.ord_num_of_range::numeric, statement.object_label, statement.object_value, NULL)::pgwar.project_statements @@ -148,8 +148,8 @@ BEGIN NEW.fk_property, NEW.fk_object_info, NEW.fk_object_tables_cell, - ord_num_of_domain, - ord_num_of_range, + ord_num_of_domain::numeric, + ord_num_of_range::numeric, NEW.object_label, NEW.object_value, NULL)::pgwar.project_statements diff --git a/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql b/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql index 1558c5cc9..30a17affb 100644 --- a/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql +++ b/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql @@ -74,7 +74,7 @@ BEGIN pep.entity_label, -- take the project entity label, cep.entity_label -- else the community entity label )::VARCHAR AS label - FROM pgwar.project_statements pstmt + FROM pgwar.v_statements_combined pstmt -- join the project entity LEFT JOIN pgwar.entity_preview pep ON pep.fk_project = project_id @@ -107,7 +107,7 @@ BEGIN pep.entity_label, -- else the project entity label, cep.entity_label -- else the community entity label )::VARCHAR AS label - FROM pgwar.project_statements pstmt + FROM pgwar.v_statements_combined pstmt -- join the project entity LEFT JOIN pgwar.entity_preview pep ON pep.fk_project = project_id diff --git a/database/migrations/sqls/20240612071824-pgwar-fulltext-up.sql b/database/migrations/sqls/20240612071824-pgwar-fulltext-up.sql index 9c07bb604..97b8f5aa9 100644 --- a/database/migrations/sqls/20240612071824-pgwar-fulltext-up.sql +++ b/database/migrations/sqls/20240612071824-pgwar-fulltext-up.sql @@ -216,17 +216,17 @@ CREATE OR REPLACE TRIGGER last_modification_tmsp /*** -* Find outdated full texts in subjects of project statements +* Find outdated full texts in subjects of statements ***/ -CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_pstmt(max_limit int) +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt(max_limit int) RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ BEGIN RETURN QUERY - -- find subjects of modified project statements + -- find subjects of modified statements SELECT DISTINCT s.pk_entity, s.fk_project FROM ( SELECT pstmt.fk_subject_info as pk_entity, pstmt.fk_project - FROM pgwar.project_statements pstmt + FROM pgwar.v_statements_combined pstmt LEFT JOIN pgwar.entity_full_text ftxt ON pstmt.fk_subject_info = ftxt.pk_entity AND pstmt.fk_project = ftxt.fk_project @@ -238,17 +238,17 @@ BEGIN END; $$ LANGUAGE plpgsql; /*** -* Find outdated full texts in objects of project statements +* Find outdated full texts in objects of statements ***/ -CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_objects_of_pstmt(max_limit int) +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt(max_limit int) RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ BEGIN RETURN QUERY - -- find objects of modified project statements + -- find objects of modified statements SELECT DISTINCT s.pk_entity, s.fk_project FROM ( SELECT pstmt.fk_object_info as pk_entity, pstmt.fk_project - FROM pgwar.project_statements pstmt + FROM pgwar.v_statements_combined pstmt LEFT JOIN pgwar.entity_full_text ftxt ON pstmt.fk_object_info = ftxt.pk_entity AND pstmt.fk_project = ftxt.fk_project @@ -263,17 +263,17 @@ $$ LANGUAGE plpgsql; /*** -* Find outdated full texts in subjects of project statements deleted +* Find outdated full texts in subjects of statements deleted ***/ -CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_pstmt_del(max_limit int) +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(max_limit int) RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ BEGIN RETURN QUERY - -- find subjects of modified project statements + -- find subjects of deleted statements SELECT DISTINCT s.pk_entity, s.fk_project FROM ( SELECT pstmt.fk_subject_info as pk_entity, pstmt.fk_project - FROM pgwar.project_statements_deleted pstmt + FROM pgwar.v_statements_deleted_combined pstmt LEFT JOIN pgwar.entity_full_text ftxt ON pstmt.fk_subject_info = ftxt.pk_entity AND pstmt.fk_project = ftxt.fk_project @@ -287,17 +287,17 @@ $$ LANGUAGE plpgsql; /*** -* Find outdated full texts in objects from project statements deleted +* Find outdated full texts in objects of statements deleted ***/ -CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_objects_of_pstmt_del(max_limit int) +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_del(max_limit int) RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ BEGIN RETURN QUERY - -- find objects of modified project statements + -- find objects of deleted statements SELECT DISTINCT s.pk_entity, s.fk_project FROM ( SELECT pstmt.fk_object_info as pk_entity, pstmt.fk_project - FROM pgwar.project_statements_deleted pstmt + FROM pgwar.v_statements_deleted_combined pstmt LEFT JOIN pgwar.entity_full_text ftxt ON pstmt.fk_object_info = ftxt.pk_entity AND pstmt.fk_project = ftxt.fk_project @@ -312,45 +312,18 @@ $$ LANGUAGE plpgsql; /*** -* Find outdated full texts in subjects of project statements with modified dfh-prop +* Find outdated full texts in subjects of statements with modified dfh-prop ***/ -CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_pstmt_by_dfh_prop(max_limit int) +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop(max_limit int) RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ BEGIN RETURN QUERY - -- find subjects of project statements with modified dfh-prop + -- find subjects of statements with modified dfh-prop SELECT DISTINCT s.pk_entity, s.fk_project FROM ( SELECT pstmt.fk_subject_info as pk_entity, pstmt.fk_project FROM - pgwar.project_statements pstmt, - data_for_history.api_property dfh_prop - LEFT JOIN pgwar.entity_full_text ftxt - ON pstmt.fk_subject_info = ftxt.pk_entity - AND pstmt.fk_project = ftxt.fk_project - WHERE - dfh_prop.dfh_pk_property = pstmt.fk_property - AND ftxt.tmsp_last_modification < dfh_prop.tmsp_last_modification - ORDER BY dfh_prop.tmsp_last_modification DESC - LIMIT max_limit - ) AS s; -END; -$$ LANGUAGE plpgsql; - - -/*** -* Find outdated full texts in subjects of project statements with modified dfh-prop -***/ -CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_pstmt_by_dfh_prop(max_limit int) -RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ -BEGIN - RETURN QUERY - -- find subjects of project statements with modified dfh-prop - SELECT DISTINCT s.pk_entity, s.fk_project - FROM ( - SELECT pstmt.fk_subject_info as pk_entity, pstmt.fk_project - FROM - pgwar.project_statements pstmt, + pgwar.v_statements_combined pstmt, data_for_history.api_property dfh_prop, pgwar.entity_full_text ftxt WHERE @@ -365,18 +338,18 @@ END; $$ LANGUAGE plpgsql; /*** -* Find outdated full texts in objects of project statements with modified dfh-prop +* Find outdated full texts in objects of statements with modified dfh-prop ***/ -CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_objects_of_pstmt_by_dfh_prop(max_limit int) +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop(max_limit int) RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ BEGIN RETURN QUERY - -- find objects of project statements with modified dfh-prop + -- find objects of statements with modified dfh-prop SELECT DISTINCT s.pk_entity, s.fk_project FROM ( SELECT pstmt.fk_object_info as pk_entity, pstmt.fk_project FROM - pgwar.project_statements pstmt, + pgwar.v_statements_combined pstmt, data_for_history.api_property dfh_prop, pgwar.entity_full_text ftxt WHERE @@ -416,12 +389,12 @@ BEGIN -- Execute functions sequentially and add unique pairs FOR current_set IN SELECT unnest(array[ - 'pgwar.get_outdated_full_texts_in_subjects_of_pstmt', - 'pgwar.get_outdated_full_texts_in_objects_of_pstmt', - 'pgwar.get_outdated_full_texts_in_subjects_of_pstmt_del', - 'pgwar.get_outdated_full_texts_in_objects_of_pstmt_del', - 'pgwar.get_outdated_full_texts_in_subjects_of_pstmt_by_dfh_prop', - 'pgwar.get_outdated_full_texts_in_objects_of_pstmt_by_dfh_prop' + 'pgwar.get_outdated_full_texts_in_subjects_of_stmt', + 'pgwar.get_outdated_full_texts_in_objects_of_stmt', + 'pgwar.get_outdated_full_texts_in_subjects_of_stmt_del', + 'pgwar.get_outdated_full_texts_in_objects_of_stmt_del', + 'pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop', + 'pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop' ]) AS function_name LOOP EXECUTE 'INSERT INTO temp_unique_pairs (pk_entity, fk_project) ' || diff --git a/database/migrations/sqls/20240613085447-pgwar-community-statements-down.sql b/database/migrations/sqls/20240613085447-pgwar-community-statements-down.sql new file mode 100644 index 000000000..44f074ea8 --- /dev/null +++ b/database/migrations/sqls/20240613085447-pgwar-community-statements-down.sql @@ -0,0 +1 @@ +/* Replace with your SQL commands */ \ No newline at end of file diff --git a/database/migrations/sqls/20240613085447-pgwar-community-statements-up.sql b/database/migrations/sqls/20240613085447-pgwar-community-statements-up.sql new file mode 100644 index 000000000..0c7930f55 --- /dev/null +++ b/database/migrations/sqls/20240613085447-pgwar-community-statements-up.sql @@ -0,0 +1,107 @@ +------ Table pgwar.community_statements ----------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS pgwar.community_statements( + pk_entity integer NOT NULL, + fk_subject_info integer, + fk_property integer NOT NULL, + fk_object_info integer, + fk_object_tables_cell bigint, + ord_num_of_domain numeric, + ord_num_of_range numeric, + object_label varchar(100), + object_value jsonb, + tmsp_last_modification timestamp with time zone, + PRIMARY KEY (pk_entity) +); + +------ Table pgwar.community_statements ---------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +-- this table is used by the fulltext cron job to find entities that need an fulltext update +-- because they are the subject or object of a deleted community statement +CREATE TABLE IF NOT EXISTS pgwar.community_statements_deleted( + pk_entity integer NOT NULL, + fk_subject_info integer, + fk_property integer NOT NULL, + fk_object_info integer, + object_value jsonb, + tmsp_deletion timestamp with time zone, + PRIMARY KEY (pk_entity) +); + +CREATE OR REPLACE FUNCTION pgwar.handle_community_statements_delete() +RETURNS TRIGGER AS $$ +BEGIN + -- Insert or update the deleted row in pgwar.community_statements + INSERT INTO pgwar.community_statements (pk_entity, fk_subject_info, fk_property, fk_object_info, object_value, tmsp_deletion) + VALUES (OLD.pk_entity, OLD.fk_subject_info, OLD.fk_property, OLD.fk_object_info, OLD.object_value, CURRENT_TIMESTAMP) + ON CONFLICT (pk_entity) + DO UPDATE SET + fk_subject_info = EXCLUDED.fk_subject_info, + fk_property = EXCLUDED.fk_property, + fk_object_info = EXCLUDED.fk_object_info, + object_value = EXCLUDED.object_value, + tmsp_deletion = EXCLUDED.tmsp_deletion; + + RETURN OLD; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER after_delete_community_statements +AFTER DELETE ON pgwar.community_statements +FOR EACH ROW +EXECUTE FUNCTION pgwar.handle_community_statements_delete(); + +------ View pgwar.v_statements_combined ----------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE OR REPLACE VIEW pgwar.v_statements_combined AS +SELECT + pk_entity, + 0 as fk_project, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + ord_num_of_domain, + ord_num_of_range, + object_label, + object_value, + tmsp_last_modification +FROM pgwar.community_statements +UNION ALL +SELECT + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + ord_num_of_domain, + ord_num_of_range, + object_label, + object_value, + tmsp_last_modification +FROM pgwar.project_statements; + + +------ View pgwar.v_statements_deleted_combined ----------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE OR REPLACE VIEW pgwar.v_statements_deleted_combined AS +SELECT + pk_entity, + 0 as fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value, + tmsp_deletion +FROM pgwar.community_statements_deleted +UNION ALL +SELECT + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value, + tmsp_deletion +FROM pgwar.project_statements_deleted; \ No newline at end of file diff --git a/database/test/integration/pgwar-project-statements/test-pgwar-project-statements.sql b/database/test/integration/pgwar-project-statements/test-pgwar-project-statements.sql index ef597455a..e1256a27b 100644 --- a/database/test/integration/pgwar-project-statements/test-pgwar-project-statements.sql +++ b/database/test/integration/pgwar-project-statements/test-pgwar-project-statements.sql @@ -6,45 +6,58 @@ SELECT plan(11); ------- Prepare required context data ------ -- Create and switch to a sink table for entity previews SELECT war.create_sink_table_entity_preview('war.e'); + SELECT war.switch_entity_preview_table('war.e'); PREPARE get_all_pgwar_project_statements AS - SELECT * - FROM pgwar.project_statements; +SELECT * +FROM pgwar.project_statements; -- Insert a language entry to be used in project -INSERT INTO information.language(pk_language) VALUES ('eng'); +INSERT INTO information.language(pk_language) +VALUES ('eng'); -- Insert a project associated with the language INSERT INTO projects.project(fk_language, notes) -SELECT pk_entity, '_p1' FROM information.language; +SELECT pk_entity, + '_p1' +FROM information.language; -- Insert one statement -INSERT INTO pgwar.statement(pk_entity, fk_subject_info, fk_property, fk_object_info, object_label, object_value) -VALUES (1,0,0,1,'foo', '{"foo":"bar"}'); +INSERT INTO pgwar.statement( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label, + object_value + ) +VALUES (1, 0, 0, 1, 'foo', '{"foo":"bar"}'); -- Add the statement to the project '_p1' in projects.info_proj_rel INSERT INTO projects.info_proj_rel(fk_project, fk_entity, is_in_project, notes) -SELECT proj.pk_entity, 1, TRUE, '_ipr1' +SELECT proj.pk_entity, + 1, + TRUE, + '_ipr1' FROM projects.project proj WHERE proj.notes = '_p1'; - SELECT isnt_empty( - 'get_all_pgwar_project_statements', - 'Assert pgwar project statement is not empty inserting a statement' + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is not empty inserting a statement' ); SELECT is( - object_label, - 'foo', - 'Assert project statement has correct object_label' + object_label, + 'foo', + 'Assert project statement has correct object_label' ) FROM pgwar.project_statements; SELECT ok( - object_value IS NOT NULL, - 'Assert project statement has an object_value' + object_value IS NOT NULL, + 'Assert project statement has an object_value' ) FROM pgwar.project_statements; @@ -54,9 +67,9 @@ SET object_label = 'bar' WHERE pk_entity = 1; SELECT is( - object_label, - 'bar', - 'Assert project statement object_label has been updated' + object_label, + 'bar', + 'Assert project statement object_label has been updated' ) FROM pgwar.project_statements; @@ -64,37 +77,43 @@ FROM pgwar.project_statements; DELETE FROM pgwar.statement; SELECT is_empty( - 'get_all_pgwar_project_statements', - 'Assert pgwar project statement is empty after deleting pgwar statement' + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is empty after deleting pgwar statement' ); -- Re-insert one statement -INSERT INTO pgwar.statement(pk_entity, fk_subject_info, fk_property, fk_object_info, object_label, object_value) -VALUES (1,0,0,1,'foo', '{"foo":"bar"}'); +INSERT INTO pgwar.statement( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label, + object_value + ) +VALUES (1, 0, 0, 1, 'foo', '{"foo":"bar"}'); SELECT isnt_empty( - 'get_all_pgwar_project_statements', - 'Assert pgwar project statement is not empty after re-inserting a statement' + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is not empty after re-inserting a statement' ); -- Update info_proj_rel _ipr1 ord_num_of_domain and ord_num_of_range UPDATE projects.info_proj_rel -SET ord_num_of_domain = 1, - ord_num_of_range = 2 +SET ord_num_of_domain = 1::numeric, + ord_num_of_range = 2::numeric WHERE notes = '_ipr1'; SELECT is( - ord_num_of_domain, - 1, - 'Assert project statement has correct ord_num_of_domain' + ord_num_of_domain, + 1::numeric, + 'Assert project statement has correct ord_num_of_domain' ) FROM pgwar.project_statements; - SELECT is( - ord_num_of_range, - 2, - 'Assert project statement has correct ord_num_of_range' + ord_num_of_range, + 2::numeric, + 'Assert project statement has correct ord_num_of_range' ) FROM pgwar.project_statements; @@ -104,8 +123,8 @@ SET is_in_project = FALSE WHERE notes = '_ipr1'; SELECT is_empty( - 'get_all_pgwar_project_statements', - 'Assert pgwar project statement is empty after setting is_in_project to FALSE in info_proj_rel' + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is empty after setting is_in_project to FALSE in info_proj_rel' ); -- Update info_proj_rel _ipr1 to add the statement to the project @@ -114,8 +133,8 @@ SET is_in_project = TRUE WHERE notes = '_ipr1'; SELECT isnt_empty( - 'get_all_pgwar_project_statements', - 'Assert pgwar project statement is not empty after setting is_in_project to TRUE in info_proj_rel' + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is not empty after setting is_in_project to TRUE in info_proj_rel' ); -- Delete info_proj_rel _ipr1 @@ -123,11 +142,10 @@ DELETE FROM projects.info_proj_rel WHERE notes = '_ipr1'; SELECT is_empty( - 'get_all_pgwar_project_statements', - 'Assert pgwar project statement is empty after deleting info_proj_rel _ipr1' + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is empty after deleting info_proj_rel _ipr1' ); - -- Finish the tests and clean up. SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-pstmt-by-dfh-prop.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-by-dfh-prop.sql similarity index 67% rename from database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-pstmt-by-dfh-prop.sql rename to database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-by-dfh-prop.sql index 95ac7aecc..64ea08fdb 100644 --- a/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-pstmt-by-dfh-prop.sql +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-by-dfh-prop.sql @@ -14,6 +14,17 @@ VALUES (1, 123, 31, 522, 11, NULL), (2, 999, 32, 523, 12, NULL), (3, 543, 33, 524, 13, '{}'); +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); + -- add full text for all entities INSERT INTO pgwar.entity_full_text ( pk_entity, @@ -24,12 +35,17 @@ VALUES (31, 123, 'full-text'), (11, 123, 'full-text'), (32, 999, 'full-text'), (12, 999, 'full-text'), - (33, 543, 'full-text'); + (33, 543, 'full-text'), + (31, 0, 'full-text'), + (11, 0, 'full-text'), + (32, 0, 'full-text'), + (12, 0, 'full-text'), + (33, 0, 'full-text'); PREPARE entities_for_update AS SELECT pk_entity, fk_project -FROM pgwar.get_outdated_full_texts_in_objects_of_pstmt_by_dfh_prop(100); +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop(100); -- assert no entity for update found SELECT is_empty( @@ -48,7 +64,7 @@ VALUES (clock_timestamp(), 522), SELECT bag_eq( 'entities_for_update', - 'VALUES (11, 123), (12, 999)', + 'VALUES (11, 123), (12, 999), (11, 0), (12, 0)', 'Contains the subject of the statement with modfied property.' ); @@ -57,7 +73,7 @@ SELECT is( 1, 'Assert the limit of 1 is respected' ) -FROM pgwar.get_outdated_full_texts_in_objects_of_pstmt_by_dfh_prop(1); +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop(1); SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-pstmt-del.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-del.sql similarity index 66% rename from database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-pstmt-del.sql rename to database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-del.sql index 4028529f9..174224e3b 100644 --- a/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-pstmt-del.sql +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-del.sql @@ -1,4 +1,5 @@ BEGIN; + SELECT plan(3); INSERT INTO pgwar.project_statements_deleted ( @@ -13,17 +14,27 @@ VALUES (1, 123, 31, 522, 11, NULL), (2, 999, 32, 523, 12, NULL), (3, 543, 33, 524, 13, '{}'); +INSERT INTO pgwar.community_statements_deleted ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); PREPARE entities_for_update AS SELECT pk_entity, fk_project -FROM pgwar.get_outdated_full_texts_in_objects_of_pstmt_del(100); +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt_del(100); --- Note that (13, 543) is an object_value and does therefore +-- Note that (13, 543), (13, 0) is an object_value and does therefore -- not show up amongst the entities_for_update SELECT bag_eq( 'entities_for_update', - 'VALUES (11, 123), (12, 999)', + 'VALUES (11, 123), (12, 999), (11, 0), (12, 0)', 'Contains all 2 pairs of project_id and object entity_id.' ); @@ -33,12 +44,13 @@ INSERT INTO pgwar.entity_full_text ( fk_project, full_text ) -VALUES (12, 999, 'full-text'); +VALUES (12, 999, 'full-text'), +(12, 0, 'full-text'); --- Assert that only one entity remains in entities_for_update +-- Assert that only two entities remains in entities_for_update SELECT bag_eq( 'entities_for_update', - 'VALUES (11, 123)', + 'VALUES (11, 123), (11, 0)', 'Assert that only one entity remains in entities_for_update.' ); @@ -62,7 +74,7 @@ SELECT is( 3, 'Assert the limit of 3 is respected' ) -FROM pgwar.get_outdated_full_texts_in_objects_of_pstmt_del(3); +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt_del(3); SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-pstmt.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt.sql similarity index 65% rename from database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-pstmt.sql rename to database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt.sql index 1d93e994a..077583a1d 100644 --- a/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-pstmt.sql +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt.sql @@ -13,33 +13,44 @@ VALUES (1, 123, 31, 522, 11, NULL), (2, 999, 32, 523, 12, NULL), (3, 543, 33, 524, 13, '{}'); +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); PREPARE entities_for_update AS SELECT pk_entity, fk_project -FROM pgwar.get_outdated_full_texts_in_objects_of_pstmt(100); +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt(100); -- Note that (13, 543) is an object_value and does therefore -- not show up amongst the entities_for_update SELECT bag_eq( 'entities_for_update', - 'VALUES (11, 123), (12, 999)', + 'VALUES (11, 123), (12, 999), (11, 0), (12, 0)', 'Contains all 2 pairs of project_id and object entity_id.' ); --- add full text one of the entities +-- add full text of two entities INSERT INTO pgwar.entity_full_text ( pk_entity, fk_project, full_text ) -VALUES (12, 999, 'full-text'); +VALUES (12, 999, 'full-text'), + (12, 0, 'full-text'); --- Assert that only one entity remains in entities_for_update +-- Assert that only two entity remains in entities_for_update SELECT bag_eq( 'entities_for_update', - 'VALUES (11, 123)', - 'Assert that only one entity remains in entities_for_update.' + 'VALUES (11, 123), (11, 0)', + 'Assert that only two entity remains in entities_for_update.' ); INSERT INTO pgwar.project_statements ( @@ -62,7 +73,7 @@ SELECT is( 3, 'Assert the limit of 3 is respected' ) -FROM pgwar.get_outdated_full_texts_in_objects_of_pstmt(3); +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt(3); SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-pstmt-by-dfh-prop.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-by-dfh-prop.sql similarity index 63% rename from database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-pstmt-by-dfh-prop.sql rename to database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-by-dfh-prop.sql index a682c137b..f551fa7b9 100644 --- a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-pstmt-by-dfh-prop.sql +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-by-dfh-prop.sql @@ -14,6 +14,17 @@ VALUES (1, 123, 31, 522, 11, NULL), (2, 999, 32, 523, 12, NULL), (3, 543, 33, 524, 13, '{}'); +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); + -- add full text for all entities INSERT INTO pgwar.entity_full_text ( pk_entity, @@ -24,12 +35,17 @@ VALUES (31, 123, 'full-text'), (11, 123, 'full-text'), (32, 999, 'full-text'), (12, 999, 'full-text'), - (33, 543, 'full-text'); + (33, 543, 'full-text'), + (31, 0, 'full-text'), + (11, 0, 'full-text'), + (32, 0, 'full-text'), + (12, 0, 'full-text'), + (33, 0, 'full-text'); PREPARE entities_for_update AS SELECT pk_entity, fk_project -FROM pgwar.get_outdated_full_texts_in_subjects_of_pstmt_by_dfh_prop(100); +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop(100); -- assert no entity for update found SELECT is_empty( @@ -42,21 +58,21 @@ INSERT INTO data_for_history.api_property( tmsp_last_dfh_update, dfh_pk_property ) -VALUES (clock_timestamp(), 523),(clock_timestamp(), 524); +VALUES (clock_timestamp(), 523), +(clock_timestamp(), 524); SELECT bag_eq( 'entities_for_update', - 'VALUES (32, 999), (33, 543)', + 'VALUES (32, 999), (33, 543), (32, 0), (33, 0)', 'Contains the subject of the statement with modfied property.' ); - SELECT is( count(*)::int, 1, 'Assert the limit of 1 is respected' ) -FROM pgwar.get_outdated_full_texts_in_subjects_of_pstmt_by_dfh_prop(1); +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop(1); SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-pstmt-del.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql similarity index 67% rename from database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-pstmt-del.sql rename to database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql index 469fe72b5..5ad25b6ff 100644 --- a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-pstmt-del.sql +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql @@ -13,16 +13,27 @@ VALUES (1, 123, 31, 522, 11, NULL), (2, 999, 32, 523, 12, NULL), (3, 543, 33, 524, 13, '{}'); +INSERT INTO pgwar.community_statements_deleted ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); + PREPARE entities_for_update AS SELECT pk_entity, fk_project -FROM pgwar.get_outdated_full_texts_in_subjects_of_pstmt_del(5); +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(10); SELECT bag_eq( 'entities_for_update', - 'VALUES (31, 123), (32, 999), (33, 543)', - 'Contains all 3 pairs of project_id and subject entity_id.' + 'VALUES (31, 123), (32, 999), (33, 543), (31, 0), (32, 0), (33, 0)', + 'Contains all 6 pairs of project_id and subject entity_id.' ); -- add full text for two of the entities @@ -32,12 +43,14 @@ INSERT INTO pgwar.entity_full_text ( full_text ) VALUES (32, 999, 'full-text'), - (33, 543, 'full-text'); + (33, 543, 'full-text'), + (32, 0, 'full-text'), + (33, 0, 'full-text'); -- Assert that only one entity remains in entities_for_update SELECT bag_eq( 'entities_for_update', - 'VALUES (31, 123)', + 'VALUES (31, 123), (31, 0)', 'Assert that only one entity remains in entities_for_update.' ); @@ -61,7 +74,7 @@ SELECT is( 3, 'Assert the limit of 3 is respected' ) -FROM pgwar.get_outdated_full_texts_in_subjects_of_pstmt_del(3); +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(3); SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-pstmt.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql similarity index 70% rename from database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-pstmt.sql rename to database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql index 603165f80..e72d0a318 100644 --- a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-pstmt.sql +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql @@ -1,4 +1,5 @@ BEGIN; + SELECT plan(3); INSERT INTO pgwar.project_statements ( @@ -13,15 +14,25 @@ VALUES (1, 123, 31, 522, 11, NULL), (2, 999, 32, 523, 12, NULL), (3, 543, 33, 524, 13, '{}'); +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); PREPARE entities_for_update AS SELECT pk_entity, fk_project -FROM pgwar.get_outdated_full_texts_in_subjects_of_pstmt(5); +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt(10); SELECT bag_eq( 'entities_for_update', - 'VALUES (31, 123), (32, 999), (33, 543)', + 'VALUES (31, 123), (32, 999), (33, 543), (31, 0), (32, 0), (33, 0)', 'Contains all 3 pairs of project_id and subject entity_id.' ); @@ -32,12 +43,14 @@ INSERT INTO pgwar.entity_full_text ( full_text ) VALUES (32, 999, 'full-text'), - (33, 543, 'full-text'); + (33, 543, 'full-text'), + (32, 0, 'full-text'), + (33, 0, 'full-text'); -- Assert that only one entity remains in entities_for_update SELECT bag_eq( 'entities_for_update', - 'VALUES (31, 123)', + 'VALUES (31, 123), (31, 0)', 'Assert that only one entity remains in entities_for_update.' ); @@ -61,7 +74,7 @@ SELECT is( 3, 'Assert the limit of 3 is respected' ) -FROM pgwar.get_outdated_full_texts_in_subjects_of_pstmt(3); +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt(3); SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-get-target-labels-of-incoming-field.sql b/database/test/units/functions/pgwar-get-target-labels-of-incoming-field.sql index 0eb426927..8418235ae 100644 --- a/database/test/units/functions/pgwar-get-target-labels-of-incoming-field.sql +++ b/database/test/units/functions/pgwar-get-target-labels-of-incoming-field.sql @@ -1,7 +1,8 @@ BEGIN; + /** -* Drop triggers that would reset the entity label to NULL and break the unit test -**/ + * Drop triggers that would reset the entity label to NULL and break the unit test + **/ -- Drop trigger on_modify_project_statement DROP TRIGGER IF EXISTS on_modify_project_statement ON pgwar.project_statements; @@ -14,12 +15,13 @@ DROP TRIGGER IF EXISTS on_upsert_entity_preview_entity_label ON pgwar.entity_pre -- Drop trigger on_upsert_entity_label_config DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; -SELECT plan(2); +SELECT plan(4); -CREATE TABLE pgwar.entity_preview_1 PARTITION OF pgwar.entity_preview FOR VALUES IN (1); +/****** test the project version *****/ +CREATE TABLE pgwar.entity_preview_1 PARTITION OF pgwar.entity_preview FOR +VALUES IN (1); -INSERT INTO pgwar.project_statements - ( +INSERT INTO pgwar.project_statements ( pk_entity, fk_project, fk_subject_info, @@ -35,11 +37,9 @@ VALUES (1, 1, 31, 22, 11, 'this has no influence'), (6, 1, 36, 22, 11, 'this has no influence'); INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) -VALUES -(31, 1, 88, 'Entity 31'), -(32, 1, 88, NULL), -(33, 1, 88, 'Entity 33'); - +VALUES (31, 1, 88, 'Entity 31'), + (32, 1, 88, NULL), + (33, 1, 88, 'Entity 33'); -- Test 1: Check if function returns the correct target labels for incoming field SELECT results_eq( @@ -58,6 +58,43 @@ SELECT is_empty( 'get_target_labels_of_incoming_field returns no labels for entity_id 99999, project_id 1, property_id 22, and limit_count 5' ); +/****** test the community version *****/ +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 31, 22, 11, 'this has no influence'), + (2, 32, 22, 11, 'this has no influence'), + (3, 33, 22, 11, 'this has no influence'), + (4, 34, 22, 11, 'this has no influence'), + (5, 35, 22, 11, 'this has no influence'), + (6, 36, 22, 11, 'this has no influence'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (31, 0, 88, 'Entity 31'), + (32, 0, 88, NULL), + (33, 0, 88, 'Entity 33'); + +-- Test 1: Check if function returns the correct target labels for incoming field +SELECT results_eq( + 'SELECT label::text FROM pgwar.get_target_labels_of_incoming_field(11, 0, 22, 5)', + ARRAY [ 'Entity 31', + NULL, + 'Entity 33', + NULL, + NULL ], + 'get_target_labels_of_incoming_field returns correct labels for entity_id 11, project_id 0, property_id 22, and limit_count 5' + ); + +-- Test 2: Check if function handles non-existing entity_id +SELECT is_empty( + 'SELECT label::text FROM pgwar.get_target_labels_of_incoming_field(99999, 0, 22, 5)', + 'get_target_labels_of_incoming_field returns no labels for entity_id 99999, project_id 0, property_id 22, and limit_count 5' + ); + SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-get-target-labels-of-outgoing-field.sql b/database/test/units/functions/pgwar-get-target-labels-of-outgoing-field.sql index 4709e1602..a8f5ede77 100644 --- a/database/test/units/functions/pgwar-get-target-labels-of-outgoing-field.sql +++ b/database/test/units/functions/pgwar-get-target-labels-of-outgoing-field.sql @@ -1,7 +1,8 @@ BEGIN; + /** -* Drop triggers that would reset the entity label to NULL and break the unit test -**/ + * Drop triggers that would reset the entity label to NULL and break the unit test + **/ -- Drop trigger on_modify_project_statement DROP TRIGGER IF EXISTS on_modify_project_statement ON pgwar.project_statements; @@ -14,12 +15,13 @@ DROP TRIGGER IF EXISTS on_upsert_entity_preview_entity_label ON pgwar.entity_pre -- Drop trigger on_upsert_entity_label_config DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; -SELECT plan(2); +SELECT plan(4); -CREATE TABLE pgwar.entity_preview_1 PARTITION OF pgwar.entity_preview FOR VALUES IN (1); +/****** test the project version *****/ +CREATE TABLE pgwar.entity_preview_1 PARTITION OF pgwar.entity_preview FOR +VALUES IN (1); -INSERT INTO pgwar.project_statements - ( +INSERT INTO pgwar.project_statements ( pk_entity, fk_project, fk_subject_info, @@ -35,14 +37,16 @@ VALUES (1, 1, 11, 22, 31, 'Label 1'), (6, 1, 11, 22, 36, 'Label 6'); INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) -VALUES -(33, 1, 88, 'Entity 33'); - +VALUES (33, 1, 88, 'Entity 33'); -- Test 1: Check if function returns the correct target labels for outgoing field SELECT results_eq( 'SELECT label::text FROM pgwar.get_target_labels_of_outgoing_field(11, 1, 22, 5)', - ARRAY['Label 1', 'Label 2', 'Entity 33', NULL, 'Label 5'], + ARRAY [ 'Label 1', + 'Label 2', + 'Entity 33', + NULL, + 'Label 5' ], 'get_target_labels_of_outgoing_field returns correct labels for entity_id 11, project_id 1, property_id 22, and limit_count 5' ); @@ -52,6 +56,41 @@ SELECT is_empty( 'get_target_labels_of_outgoing_field returns no labels for entity_id 99999, project_id 1, property_id 22, and limit_count 5' ); +/****** test the community version *****/ +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 11, 22, 31, 'Label 1'), + (2, 11, 22, 32, 'Label 2'), + (3, 11, 22, 33, NULL), + (4, 11, 22, 34, NULL), + (5, 11, 22, 35, 'Label 5'), + (6, 11, 22, 36, 'Label 6'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (33, 0, 88, 'Entity 33'); + +-- Test 1: Check if function returns the correct target labels for outgoing field +SELECT results_eq( + 'SELECT label::text FROM pgwar.get_target_labels_of_outgoing_field(11, 0, 22, 5)', + ARRAY [ 'Label 1', + 'Label 2', + 'Entity 33', + NULL, + 'Label 5' ], + 'get_target_labels_of_outgoing_field returns correct labels for entity_id 11, project_id 0, property_id 22, and limit_count 5' + ); + +-- Test 2: Check if function handles non-existing entity_id +SELECT is_empty( + 'SELECT label::text FROM pgwar.get_target_labels_of_outgoing_field(99999, 0, 22, 5)', + 'get_target_labels_of_outgoing_field returns no labels for entity_id 99999, project_id 0, property_id 22, and limit_count 5' + ); + SELECT * FROM finish(); diff --git a/server/package-lock.json b/server/package-lock.json index 22c22335b..f776bcffb 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -605,6 +605,11 @@ "to-fast-properties": "^2.0.0" } }, + "@colors/colors": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", + "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==" + }, "@cspotcode/source-map-consumer": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", @@ -4422,9 +4427,9 @@ "integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==" }, "db-migrate": { - "version": "0.11.12", - "resolved": "https://registry.npmjs.org/db-migrate/-/db-migrate-0.11.12.tgz", - "integrity": "sha512-HUS8T5A3sKGCi+hz9XMKMwAKfU9sqhpDufW9nbVSRc5wxDO695uxA5lDe+If0OdvwwQOVxOnEZqkzAAxgyeFWg==", + "version": "0.11.14", + "resolved": "https://registry.npmjs.org/db-migrate/-/db-migrate-0.11.14.tgz", + "integrity": "sha512-8e+/YsIlM3d69hj+cb6qG6WyubR8nwXfDf9gGLWl4AxHpI6mTomcqhRLNfPrs7Le7AZv2eEsgK8hkXDSQqfIvg==", "requires": { "balanced-match": "^1.0.0", "bluebird": "^3.1.1", @@ -4479,12 +4484,17 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-5.0.1.tgz", "integrity": "sha512-4As8uPrjfwb7VXC+WnLCbXK7y+Ueb2B3zgNCePYfhxS1PYeaO1YTeplffTEcbfLhvFNGLAz90VvJs9yomG7bow==" }, + "minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==" + }, "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", "requires": { - "minimist": "^1.2.5" + "minimist": "^1.2.6" } }, "wrap-ansi": { @@ -6022,7 +6032,7 @@ "final-fs": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/final-fs/-/final-fs-1.6.1.tgz", - "integrity": "sha1-1tzZLvb+T+jAer1WjHE1YQ7eMjY=", + "integrity": "sha512-r5dgz23H8qh1LxKVJK84zet2PhWSWkIOgbLVUd5PlNFAULD/kCDBH9JEMwJt9dpdTnLsSD4rEqS56p2MH7Wbvw==", "requires": { "node-fs": "~0.1.5", "when": "~2.0.1" @@ -10258,7 +10268,7 @@ "mongodb-uri": { "version": "0.9.7", "resolved": "https://registry.npmjs.org/mongodb-uri/-/mongodb-uri-0.9.7.tgz", - "integrity": "sha1-D3ca0W9IOuZfQoeWlCjp+8SqYYE=" + "integrity": "sha512-s6BdnqNoEYfViPJgkH85X5Nw5NpzxN8hoflKLweNa7vBxt2V7kaS06d74pAtqDxde8fn4r9h4dNdLiFGoNV0KA==" }, "ms": { "version": "2.1.3", @@ -10482,7 +10492,7 @@ "node-fs": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/node-fs/-/node-fs-0.1.7.tgz", - "integrity": "sha1-MjI8zLRsn78PwRgS1FAhzDHTJbs=" + "integrity": "sha512-XqDBlmUKgDGe76+lZ/0sRBF3XW2vVcK07+ZPvdpUTK8jrvtPahUd0aBqJ9+ZjB01ANjZLuvK3O/eoMVmz62rpA==" }, "node-gyp": { "version": "7.1.2", @@ -11530,7 +11540,7 @@ "parse-database-url": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/parse-database-url/-/parse-database-url-0.3.0.tgz", - "integrity": "sha1-NpZmMh6SfJreY838Gqr2+zdFPQ0=", + "integrity": "sha512-YRxDoVBAUk3ksGF9pud+aqWwXmThZzhX9Z1PPxKU03BB3/gu2RcgyMA4rktMYhkIJ9KxwW7lIj00U+TSNz80wg==", "requires": { "mongodb-uri": ">= 0.9.7" } @@ -11895,28 +11905,33 @@ } }, "prompt": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.2.0.tgz", - "integrity": "sha512-iGerYRpRUg5ZyC+FJ/25G5PUKuWAGRjW1uOlhX7Pi3O5YygdK6R+KEaBjRbHSkU5vfS5PZCltSPZdDtUYwRCZA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.3.0.tgz", + "integrity": "sha512-ZkaRWtaLBZl7KKAKndKYUL8WqNT+cQHKRZnT4RYYms48jQkFw3rrBL+/N5K/KtdEveHkxs982MX2BkDKub2ZMg==", "requires": { - "async": "~0.9.0", - "colors": "^1.1.2", + "@colors/colors": "1.5.0", + "async": "3.2.3", "read": "1.0.x", "revalidator": "0.1.x", "winston": "2.x" }, "dependencies": { "async": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", - "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=" + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz", + "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" + }, + "colors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", + "integrity": "sha512-pFGrxThWcWQ2MsAz6RtgeWe4NK2kUE1WfsrvvlctdII745EW9I0yflqhe7++M5LEc7bV2c/9/5zc8sFcpL0Drw==" }, "winston": { - "version": "2.4.5", - "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.5.tgz", - "integrity": "sha512-TWoamHt5yYvsMarGlGEQE59SbJHqGsZV8/lwC+iCcGeAe0vUaOh+Lv6SYM17ouzC/a/LB1/hz/7sxFBtlu1l4A==", + "version": "2.4.7", + "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.7.tgz", + "integrity": "sha512-vLB4BqzCKDnnZH9PHGoS2ycawueX4HLqENXQitvFHczhgW2vFpSOn31LZtVr1KU8YTw7DS4tM+cqyovxo8taVg==", "requires": { - "async": "~1.0.0", + "async": "^2.6.4", "colors": "1.0.x", "cycle": "1.0.x", "eyes": "0.1.x", @@ -11925,14 +11940,12 @@ }, "dependencies": { "async": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz", - "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k=" - }, - "colors": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", - "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=" + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "requires": { + "lodash": "^4.17.14" + } } } } @@ -13680,6 +13693,17 @@ "lodash": "^4.17.20" } }, + "ssh2": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.4.0.tgz", + "integrity": "sha512-XvXwcXKvS452DyQvCa6Ct+chpucwc/UyxgliYz+rWXJ3jDHdtBb9xgmxJdMmnIn5bpgGAEV3KaEsH98ZGPHqwg==", + "requires": { + "asn1": "^0.2.4", + "bcrypt-pbkdf": "^1.0.2", + "cpu-features": "0.0.2", + "nan": "^2.15.0" + } + }, "sshpk": { "version": "1.16.1", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", @@ -14748,18 +14772,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, - "ssh2": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.4.0.tgz", - "integrity": "sha512-XvXwcXKvS452DyQvCa6Ct+chpucwc/UyxgliYz+rWXJ3jDHdtBb9xgmxJdMmnIn5bpgGAEV3KaEsH98ZGPHqwg==", - "requires": { - "asn1": "^0.2.4", - "bcrypt-pbkdf": "^1.0.2", - "cpu-features": "0.0.2", - "nan": "^2.15.0" - } + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" } } }, @@ -15392,7 +15405,7 @@ "when": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/when/-/when-2.0.1.tgz", - "integrity": "sha1-jYcv4V5oQkyRtLck6EjggH2rZkI=" + "integrity": "sha512-h0l57vFJ4YQe1/U+C+oqBfAoopxXABUm6VqWM0x2gg4pARru4IUWo/PAxyawWgbGtndXrZbA41EzsfxacZVEXQ==" }, "which": { "version": "2.0.2", diff --git a/server/package.json b/server/package.json index 94b019fa7..0e57e089e 100644 --- a/server/package.json +++ b/server/package.json @@ -81,7 +81,7 @@ "aws-sdk": "^2.747.0", "bcryptjs": "^2.4.3", "cli-color": "^1.2.0", - "db-migrate": "^0.11.5", + "db-migrate": "^0.11.14", "db-migrate-pg": "^0.4.0", "express-sslify": "^1.2.0", "forever": "^0.15.3", From 748cf65feff73b6d3f3427a783a9e310f5097505 Mon Sep 17 00:00:00 2001 From: joschne Date: Thu, 13 Jun 2024 14:38:40 +0200 Subject: [PATCH 02/15] extract logic of pgwar.after_modify_info_proj_rel into pgwar.update_from_info_proj_rel --- .../sqls/20240529120605-pgwar-entity-up.sql | 63 ------------ ...0606082339-pgwar-project-statements-up.sql | 95 +++++++++++++++---- 2 files changed, 79 insertions(+), 79 deletions(-) diff --git a/database/migrations/sqls/20240529120605-pgwar-entity-up.sql b/database/migrations/sqls/20240529120605-pgwar-entity-up.sql index 0ccd51633..b533d9dc6 100644 --- a/database/migrations/sqls/20240529120605-pgwar-entity-up.sql +++ b/database/migrations/sqls/20240529120605-pgwar-entity-up.sql @@ -67,69 +67,6 @@ END; $$ LANGUAGE plpgsql; --- Trigger function after_modify_info_proj_rel ----------------------------------------------- -CREATE FUNCTION pgwar.after_modify_info_proj_rel() - RETURNS TRIGGER - LANGUAGE plpgsql - AS $$ -DECLARE - is_upsert boolean; - entity information.resource; -BEGIN - -- get the referenced information.resource - SELECT - * INTO entity - FROM - information.resource - WHERE - pk_entity = COALESCE(NEW.fk_entity, OLD.fk_entity); - -- if the referenced item is an entity - IF entity.pk_entity IS NOT NULL THEN - -- determine if this is an upsert action - SELECT - (NEW.is_in_project = TRUE - AND TG_OP != 'DELETE') INTO is_upsert; - -- if upsert ... - IF is_upsert = TRUE THEN - -- ... upsert the project entity - PERFORM - pgwar.upsert_entity_preview_fk_class(NEW.fk_entity, NEW.fk_project, entity.fk_class); - -- if allowed ... - IF (entity.community_visibility ->> 'toolbox')::bool = TRUE THEN - -- ... upsert the community entity - PERFORM - pgwar.upsert_entity_preview_fk_class(NEW.fk_entity, 0, entity.fk_class); - END IF; - ELSE - -- ... delete the project entity - DELETE FROM pgwar.entity_preview - WHERE pk_entity = COALESCE(NEW.fk_entity, OLD.fk_entity) - AND fk_project = COALESCE(NEW.fk_project, OLD.fk_project); - -- ... check if community entity has to be deleted - IF NOT EXISTS ( - SELECT - pk_entity - FROM - projects.info_proj_rel - WHERE - fk_entity = COALESCE(NEW.fk_entity, OLD.fk_entity) - AND is_in_project = TRUE) THEN - -- ... delete the community entity - DELETE FROM pgwar.entity_preview - WHERE pk_entity = COALESCE(NEW.fk_entity, OLD.fk_entity) - AND fk_project = 0; - END IF; - END IF; -END IF; - RETURN NEW; -END; -$$; - -CREATE TRIGGER after_modify_info_proj_rel - AFTER INSERT OR UPDATE OR DELETE ON projects.info_proj_rel - FOR EACH ROW - EXECUTE FUNCTION pgwar.after_modify_info_proj_rel(); -- Trigger function after_upsert_resource ---------------------------------------------- diff --git a/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql b/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql index 333daf8e7..f2df4e099 100644 --- a/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql +++ b/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql @@ -70,39 +70,39 @@ END; $$ LANGUAGE plpgsql; --- Trigger function after_modify_info_proj_rel +-- Function update_from_info_proj_rel ---------------------------------------------- -CREATE FUNCTION pgwar.after_modify_info_proj_rel_proj_stmt() - RETURNS TRIGGER +CREATE FUNCTION pgwar.update_from_info_proj_rel(NEW_OLD projects.info_proj_rel, is_upsert bool) + RETURNS void LANGUAGE plpgsql -AS $$ + AS $$ DECLARE - is_upsert boolean; + entity information.resource; statement pgwar.statement; BEGIN + -- get the referenced pgwar.statement SELECT * INTO statement FROM pgwar.statement stmt - WHERE stmt.pk_entity = COALESCE(NEW.fk_entity, OLD.fk_entity); + WHERE stmt.pk_entity = NEW_OLD.fk_entity; -- if pgwar.statement is referenced by info_proj_rel.fk_entity IF statement.pk_entity IS NOT NULL THEN - -- determine if this is an upsert action - SELECT (NEW.is_in_project = TRUE AND TG_OP != 'DELETE') INTO is_upsert; + -- if upsert ... IF is_upsert = TRUE THEN -- ... upsert the project statements PERFORM pgwar.upsert_project_statements(( - NEW.fk_entity, - NEW.fk_project, + NEW_OLD.fk_entity, + NEW_OLD.fk_project, statement.fk_subject_info, statement.fk_property, statement.fk_object_info, statement.fk_object_tables_cell, - NEW.ord_num_of_domain::numeric, - NEW.ord_num_of_range::numeric, + NEW_OLD.ord_num_of_domain::numeric, + NEW_OLD.ord_num_of_range::numeric, statement.object_label, statement.object_value, NULL)::pgwar.project_statements @@ -110,18 +110,81 @@ BEGIN ELSE -- ... delete the project_statements DELETE FROM pgwar.project_statements - WHERE pk_entity = COALESCE(NEW.fk_entity, OLD.fk_entity) - AND fk_project = COALESCE(NEW.fk_project, OLD.fk_project); + WHERE pk_entity = NEW_OLD.fk_entity + AND fk_project = NEW_OLD.fk_project; END IF; + ELSE + + -- get the referenced information.resource + SELECT * + INTO entity + FROM information.resource + WHERE pk_entity = NEW_OLD.fk_entity; + -- if the referenced item is an entity + IF entity.pk_entity IS NOT NULL THEN + + -- if upsert ... + IF is_upsert = TRUE THEN + -- ... upsert the project entity + PERFORM + pgwar.upsert_entity_preview_fk_class(NEW_OLD.fk_entity, NEW_OLD.fk_project, entity.fk_class); + -- if allowed ... + IF (entity.community_visibility ->> 'toolbox')::bool = TRUE THEN + -- ... upsert the community entity + PERFORM + pgwar.upsert_entity_preview_fk_class(NEW_OLD.fk_entity, 0, entity.fk_class); + END IF; + ELSE + -- ... delete the project entity + DELETE FROM pgwar.entity_preview + WHERE pk_entity = NEW_OLD.fk_entity + AND fk_project = NEW_OLD.fk_project; + -- ... check if community entity has to be deleted + IF NOT EXISTS ( + SELECT + pk_entity + FROM + projects.info_proj_rel + WHERE + fk_entity = NEW_OLD.fk_entity + AND is_in_project = TRUE) THEN + -- ... delete the community entity + DELETE FROM pgwar.entity_preview + WHERE pk_entity = NEW_OLD.fk_entity + AND fk_project = 0; + END IF; + END IF; + END IF; + END IF; +END; +$$; + +-- Trigger function after_modify_info_proj_rel +---------------------------------------------- +CREATE FUNCTION pgwar.after_modify_info_proj_rel() + RETURNS TRIGGER + LANGUAGE plpgsql +AS $$ +DECLARE + info_proj_rel projects.info_proj_rel; + is_upsert boolean; + statement pgwar.statement; +BEGIN + info_proj_rel := COALESCE(NEW,OLD); + + SELECT (NEW.is_in_project = TRUE AND TG_OP != 'DELETE') INTO is_upsert; + + PERFORM pgwar.update_from_info_proj_rel(info_proj_rel, is_upsert); + RETURN NEW; END; $$; -CREATE TRIGGER after_modify_info_proj_rel_proj_stmt +CREATE TRIGGER after_modify_info_proj_rel AFTER INSERT OR UPDATE OR DELETE ON projects.info_proj_rel FOR EACH ROW -EXECUTE FUNCTION pgwar.after_modify_info_proj_rel_proj_stmt(); + EXECUTE FUNCTION pgwar.after_modify_info_proj_rel(); -- Trigger function after_upsert_pgw_statement ---------------------------------------------- From c3b535bf420638e513ae7a3b3fbdac6e5eb89398 Mon Sep 17 00:00:00 2001 From: joschne Date: Thu, 13 Jun 2024 14:54:37 +0200 Subject: [PATCH 03/15] extract logic of pgwar.after_upsert_statement into pgwar.update_from_statement --- .../20240530193851-pgwar-statements-up.sql | 69 +++++++++++-------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/database/migrations/sqls/20240530193851-pgwar-statements-up.sql b/database/migrations/sqls/20240530193851-pgwar-statements-up.sql index a408bbf1a..d50e22bde 100644 --- a/database/migrations/sqls/20240530193851-pgwar-statements-up.sql +++ b/database/migrations/sqls/20240530193851-pgwar-statements-up.sql @@ -389,10 +389,10 @@ END; $$ LANGUAGE plpgsql; ------- Trigger after upsert statement table ------------------------------------------------- +------ Function to update pgwar from a statement -------------------------------------------- --------------------------------------------------------------------------------------------- -CREATE FUNCTION pgwar.after_upsert_statement() - RETURNS TRIGGER +CREATE FUNCTION pgwar.update_from_statement(NEW_STMT information.statement) + RETURNS void LANGUAGE plpgsql AS $$ DECLARE @@ -407,109 +407,120 @@ DECLARE BEGIN -- get the referenced appellation... - SELECT * INTO appellation FROM information.appellation WHERE pk_entity = NEW.fk_object_info; + SELECT * INTO appellation FROM information.appellation WHERE pk_entity = NEW_STMT.fk_object_info; -- ...if not null... IF appellation.pk_entity IS NOT NULL THEN -- create a pgwar.statement - PERFORM pgwar.upsert_statement((NEW.pk_entity,NEW.fk_subject_info,NEW.fk_property,NEW.fk_object_info,NEW.fk_object_tables_cell, + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, pgwar.get_value_label(appellation), pgwar.get_value_object(appellation) )::pgwar.statement); -- return! - RETURN NEW; + RETURN; END IF; -- get the referenced dimension... - SELECT * INTO dimension FROM information.dimension WHERE pk_entity = NEW.fk_object_info; + SELECT * INTO dimension FROM information.dimension WHERE pk_entity = NEW_STMT.fk_object_info; -- ...if not null... IF dimension.pk_entity IS NOT NULL THEN -- create a pgwar.statement - PERFORM pgwar.upsert_statement((NEW.pk_entity,NEW.fk_subject_info,NEW.fk_property,NEW.fk_object_info,NEW.fk_object_tables_cell, + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, pgwar.get_value_label(dimension), pgwar.get_value_object(dimension) )::pgwar.statement); -- return! - RETURN NEW; + RETURN; END IF; -- get the referenced lang_string... - SELECT * INTO lang_string FROM information.lang_string WHERE pk_entity = NEW.fk_object_info; + SELECT * INTO lang_string FROM information.lang_string WHERE pk_entity = NEW_STMT.fk_object_info; -- ...if not null... IF lang_string.pk_entity IS NOT NULL THEN -- create a pgwar.statement - PERFORM pgwar.upsert_statement((NEW.pk_entity,NEW.fk_subject_info,NEW.fk_property,NEW.fk_object_info,NEW.fk_object_tables_cell, + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, pgwar.get_value_label(lang_string), pgwar.get_value_object(lang_string) )::pgwar.statement); -- return! - RETURN NEW; + RETURN; END IF; -- get the referenced dimension... - SELECT * INTO language FROM information.language WHERE pk_entity = NEW.fk_object_info; + SELECT * INTO language FROM information.language WHERE pk_entity = NEW_STMT.fk_object_info; -- ...if not null... IF language.pk_entity IS NOT NULL THEN -- create a pgwar.statement - PERFORM pgwar.upsert_statement((NEW.pk_entity,NEW.fk_subject_info,NEW.fk_property,NEW.fk_object_info,NEW.fk_object_tables_cell, + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, pgwar.get_value_label(language), pgwar.get_value_object(language) )::pgwar.statement); -- return! - RETURN NEW; + RETURN; END IF; -- get the referenced place... - SELECT * INTO place FROM information.place WHERE pk_entity = NEW.fk_object_info; + SELECT * INTO place FROM information.place WHERE pk_entity = NEW_STMT.fk_object_info; -- ...if not null... IF place.pk_entity IS NOT NULL THEN -- create a pgwar.statement - PERFORM pgwar.upsert_statement((NEW.pk_entity,NEW.fk_subject_info,NEW.fk_property,NEW.fk_object_info,NEW.fk_object_tables_cell, + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, pgwar.get_value_label(place), pgwar.get_value_object(place) )::pgwar.statement); -- return! - RETURN NEW; + RETURN; END IF; -- get the referenced time_primitive... - SELECT * INTO time_primitive FROM information.time_primitive WHERE pk_entity = NEW.fk_object_info; + SELECT * INTO time_primitive FROM information.time_primitive WHERE pk_entity = NEW_STMT.fk_object_info; -- ...if not null... IF time_primitive.pk_entity IS NOT NULL THEN -- create a pgwar.statement - PERFORM pgwar.upsert_statement((NEW.pk_entity,NEW.fk_subject_info,NEW.fk_property,NEW.fk_object_info,NEW.fk_object_tables_cell, + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, pgwar.get_value_label(time_primitive), pgwar.get_value_object(time_primitive) )::pgwar.statement); -- return! - RETURN NEW; + RETURN; END IF; -- get the referenced cell... - SELECT * INTO cell FROM tables.cell WHERE pk_cell = NEW.fk_object_tables_cell; + SELECT * INTO cell FROM tables.cell WHERE pk_cell = NEW_STMT.fk_object_tables_cell; -- ...if not null... IF cell.pk_cell IS NOT NULL THEN -- create a pgwar.statement - PERFORM pgwar.upsert_statement((NEW.pk_entity,NEW.fk_subject_info,NEW.fk_property,NEW.fk_object_info,NEW.fk_object_tables_cell, + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, pgwar.get_value_label(cell), pgwar.get_value_object(cell) )::pgwar.statement); -- return! - RETURN NEW; + RETURN; END IF; -- get the referenced entity... - SELECT * INTO entity FROM information.resource WHERE pk_entity = NEW.fk_object_info; + SELECT * INTO entity FROM information.resource WHERE pk_entity = NEW_STMT.fk_object_info; -- ...if not null... IF entity.pk_entity IS NOT NULL THEN -- create a pgwar.statement - PERFORM pgwar.upsert_statement((NEW.pk_entity,NEW.fk_subject_info,NEW.fk_property,NEW.fk_object_info,NEW.fk_object_tables_cell,NULL,NULL)::pgwar.statement); + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell,NULL,NULL)::pgwar.statement); -- return! - RETURN NEW; + RETURN; END IF; - -- fallback +END; +$$; + +------ Trigger function after upsert statement table ------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE FUNCTION pgwar.after_upsert_statement() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + PERFORM pgwar.update_from_statement(NEW); + RETURN NEW; END; $$; @@ -519,7 +530,7 @@ CREATE TRIGGER after_upsert_statement FOR EACH ROW EXECUTE FUNCTION pgwar.after_upsert_statement(); - ------ Trigger after delete statement table ------------------------------------------------- +------ Trigger after delete statement table ------------------------------------------------- --------------------------------------------------------------------------------------------- CREATE FUNCTION pgwar.after_delete_statement() RETURNS TRIGGER From ee8b731a001a8e382428d853b678380ca0e4bc42 Mon Sep 17 00:00:00 2001 From: joschne Date: Thu, 13 Jun 2024 15:21:39 +0200 Subject: [PATCH 04/15] extract logic of pgwar.after_upsert_resource into pgwar.update_from_resource --- .../sqls/20240529120605-pgwar-entity-up.sql | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/database/migrations/sqls/20240529120605-pgwar-entity-up.sql b/database/migrations/sqls/20240529120605-pgwar-entity-up.sql index b533d9dc6..d7dd42fb5 100644 --- a/database/migrations/sqls/20240529120605-pgwar-entity-up.sql +++ b/database/migrations/sqls/20240529120605-pgwar-entity-up.sql @@ -68,10 +68,11 @@ $$ LANGUAGE plpgsql; --- Trigger function after_upsert_resource + +-- Function to update pgwar from resource ---------------------------------------------- -CREATE FUNCTION pgwar.after_upsert_resource() - RETURNS TRIGGER +CREATE FUNCTION pgwar.update_from_resource(NEW_RES information.resource) + RETURNS void LANGUAGE plpgsql AS $$ BEGIN @@ -82,27 +83,39 @@ BEGIN FROM projects.info_proj_rel WHERE - fk_entity = COALESCE(NEW.pk_entity) + fk_entity = NEW_RES.pk_entity AND is_in_project = TRUE) THEN - -- ... insert missing project entities or update existing, in case fk_class differs - PERFORM - pgwar.upsert_entity_preview_fk_class(fk_entity, fk_project, NEW.fk_class) - FROM - projects.info_proj_rel - WHERE - fk_entity = NEW.pk_entity - AND is_in_project = TRUE; - -- ... insert missing community entity or update existing, in case fk_class differs - PERFORM - pgwar.upsert_entity_preview_fk_class(NEW.pk_entity, 0, NEW.fk_class); -END IF; - -- if hidden for toolbox community ... - IF(NEW.community_visibility ->> 'toolbox')::bool = FALSE THEN - -- ... delete potentially unallowed community entities - DELETE FROM pgwar.entity_preview - WHERE fk_project = 0 - AND pk_entity = NEW.pk_entity; + -- ... insert missing project entities or update existing, in case fk_class differs + PERFORM + pgwar.upsert_entity_preview_fk_class(fk_entity, fk_project, NEW_RES.fk_class) + FROM + projects.info_proj_rel + WHERE + fk_entity = NEW_RES.pk_entity + AND is_in_project = TRUE; + -- ... insert missing community entity or update existing, in case fk_class differs + PERFORM + pgwar.upsert_entity_preview_fk_class(NEW_RES.pk_entity, 0, NEW_RES.fk_class); + END IF; + -- if hidden for toolbox community ... + IF(NEW_RES.community_visibility ->> 'toolbox')::bool = FALSE THEN + -- ... delete potentially unallowed community entities + DELETE FROM pgwar.entity_preview + WHERE fk_project = 0 + AND pk_entity = NEW_RES.pk_entity; END IF; +END; +$$; + +-- Trigger function after_upsert_resource +---------------------------------------------- +CREATE FUNCTION pgwar.after_upsert_resource() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + PERFORM pgwar.update_from_resource(NEW); + RETURN NEW; END; $$; From 863cd2e0ba37c2ccd02786dc07970c20d05022be Mon Sep 17 00:00:00 2001 From: joschne Date: Fri, 14 Jun 2024 08:48:15 +0200 Subject: [PATCH 05/15] add postgres image m-3 with multi-arch support --- database/postgres/heavy.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/postgres/heavy.Dockerfile b/database/postgres/heavy.Dockerfile index e9143b4ae..330768953 100644 --- a/database/postgres/heavy.Dockerfile +++ b/database/postgres/heavy.Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/geovistory/toolbox-dev-db:m-2 +FROM ghcr.io/geovistory/toolbox-dev-db:m-3 RUN rm -Rf /logs RUN mkdir /logs From 2050bd93b01d4e3692ddd2ac2ed2beb8e767acf7 Mon Sep 17 00:00:00 2001 From: joschne Date: Fri, 14 Jun 2024 08:48:38 +0200 Subject: [PATCH 06/15] add fk_class not null --- ...52-inf-t-resource-add-fk-class-not-null.js | 53 +++++++++++++++++++ ...-t-resource-add-fk-class-not-null-down.sql | 2 + ...nf-t-resource-add-fk-class-not-null-up.sql | 6 +++ 3 files changed, 61 insertions(+) create mode 100644 database/migrations/20240613180752-inf-t-resource-add-fk-class-not-null.js create mode 100644 database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-down.sql create mode 100644 database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-up.sql diff --git a/database/migrations/20240613180752-inf-t-resource-add-fk-class-not-null.js b/database/migrations/20240613180752-inf-t-resource-add-fk-class-not-null.js new file mode 100644 index 000000000..e3b9106be --- /dev/null +++ b/database/migrations/20240613180752-inf-t-resource-add-fk-class-not-null.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240613180752-inf-t-resource-add-fk-class-not-null-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240613180752-inf-t-resource-add-fk-class-not-null-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-down.sql b/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-down.sql new file mode 100644 index 000000000..dbe993a66 --- /dev/null +++ b/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-down.sql @@ -0,0 +1,2 @@ +ALTER TABLE information.resource +ALTER COLUMN fk_class DROP NOT NULL; diff --git a/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-up.sql b/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-up.sql new file mode 100644 index 000000000..3612f5074 --- /dev/null +++ b/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-up.sql @@ -0,0 +1,6 @@ +UPDATE information.resource +SET fk_class = 0 +WHERE fk_class IS NULL; + +ALTER TABLE information.resource +ALTER COLUMN fk_class SET NOT NULL; \ No newline at end of file From 1657f1584338fbcc693e4a02f8c0d813917ef4cf Mon Sep 17 00:00:00 2001 From: joschne Date: Fri, 14 Jun 2024 13:39:46 +0200 Subject: [PATCH 07/15] add m-4 --- database/postgres/heavy.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/postgres/heavy.Dockerfile b/database/postgres/heavy.Dockerfile index 330768953..90f0504cd 100644 --- a/database/postgres/heavy.Dockerfile +++ b/database/postgres/heavy.Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/geovistory/toolbox-dev-db:m-3 +FROM ghcr.io/geovistory/toolbox-dev-db:m-4 RUN rm -Rf /logs RUN mkdir /logs From fa931e725cb2353a854548952c297fd72d389fe8 Mon Sep 17 00:00:00 2001 From: joschne Date: Wed, 19 Jun 2024 12:18:31 +0200 Subject: [PATCH 08/15] add indexes --- .../20240618112815-pgwar-statement-indexes.js | 53 +++++++++++++++++++ ...6151842-pgwar-project-entity-labels-up.sql | 28 ++++++++-- ...618112815-pgwar-statement-indexes-down.sql | 7 +++ ...40618112815-pgwar-statement-indexes-up.sql | 27 ++++++++++ .../test-pgwar-entity-label.sql | 30 ++++++++++- 5 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 database/migrations/20240618112815-pgwar-statement-indexes.js create mode 100644 database/migrations/sqls/20240618112815-pgwar-statement-indexes-down.sql create mode 100644 database/migrations/sqls/20240618112815-pgwar-statement-indexes-up.sql diff --git a/database/migrations/20240618112815-pgwar-statement-indexes.js b/database/migrations/20240618112815-pgwar-statement-indexes.js new file mode 100644 index 000000000..349876b83 --- /dev/null +++ b/database/migrations/20240618112815-pgwar-statement-indexes.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240618112815-pgwar-statement-indexes-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240618112815-pgwar-statement-indexes-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql b/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql index 30a17affb..836d5d75c 100644 --- a/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql +++ b/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql @@ -184,6 +184,25 @@ BEGIN END; $$ LANGUAGE plpgsql; + + +-- get and update entity label or project entity +CREATE OR REPLACE FUNCTION pgwar.get_and_update_project_entity_label(entity_id int, project_id int) +RETURNS void AS $$ +BEGIN + IF EXISTS( + SELECT + pk_entity + FROM + pgwar.entity_preview + WHERE + pk_entity = entity_id + AND fk_project = project_id) THEN + PERFORM pgwar.update_project_entity_label(entity_id, project_id, pgwar.get_project_entity_label(entity_id, project_id)); + END IF; +END; +$$ LANGUAGE plpgsql; + /*** * Triggers ***/ @@ -201,12 +220,12 @@ BEGIN subject_entity_id := COALESCE(NEW.fk_subject_info, OLD.fk_subject_info); -- Update the label for the subject entity - PERFORM pgwar.update_project_entity_label(subject_entity_id, project_id, pgwar.get_project_entity_label(subject_entity_id, project_id)); + PERFORM pgwar.get_and_update_project_entity_label(subject_entity_id, project_id); -- Check if the object is an entity (object_label IS NULL) IF COALESCE(NEW.object_label, OLD.object_label) IS NULL THEN object_entity_id := COALESCE(NEW.fk_object_info, OLD.fk_object_info); - PERFORM pgwar.update_project_entity_label(object_entity_id, project_id, pgwar.get_project_entity_label(object_entity_id, project_id)); + PERFORM pgwar.get_and_update_project_entity_label(object_entity_id, project_id); END IF; RETURN NULL; @@ -219,7 +238,6 @@ FOR EACH ROW EXECUTE FUNCTION pgwar.update_entity_label_on_project_statement_change(); -- Update entity labels on change on entity preview fk_class - CREATE OR REPLACE FUNCTION pgwar.update_entity_label_on_fk_class_change() RETURNS TRIGGER AS $$ DECLARE @@ -253,14 +271,14 @@ BEGIN entity_id := COALESCE(NEW.pk_entity, OLD.pk_entity); -- Update the entity labels of the related object entities - PERFORM pgwar.update_project_entity_label(fk_object_info, project_id, pgwar.get_project_entity_label(fk_object_info, project_id)) + PERFORM pgwar.get_and_update_project_entity_label(fk_object_info, project_id) FROM pgwar.project_statements WHERE fk_subject_info = entity_id AND object_label IS NULL AND fk_project = project_id; -- Update the entity labels of the related subject entities - PERFORM pgwar.update_project_entity_label(fk_subject_info, project_id, pgwar.get_project_entity_label(fk_subject_info, project_id)) + PERFORM pgwar.get_and_update_project_entity_label(fk_subject_info, project_id) FROM pgwar.project_statements WHERE fk_object_info = entity_id AND fk_project = project_id; diff --git a/database/migrations/sqls/20240618112815-pgwar-statement-indexes-down.sql b/database/migrations/sqls/20240618112815-pgwar-statement-indexes-down.sql new file mode 100644 index 000000000..b4cff0dec --- /dev/null +++ b/database/migrations/sqls/20240618112815-pgwar-statement-indexes-down.sql @@ -0,0 +1,7 @@ +DROP INDEX IF EXISTS pgwar.project_statements_fk_subject_info_idx; +DROP INDEX IF EXISTS pgwar.project_statements_fk_object_info_idx; +DROP INDEX IF EXISTS pgwar.community_statements_fk_subject_info_idx; +DROP INDEX IF EXISTS pgwar.community_statements_fk_object_info_idx; +DROP INDEX IF EXISTS pgwar.project_statements_outgoing_order_idx; +DROP INDEX IF EXISTS pgwar.community_statements_fk_property_idx; +DROP INDEX IF EXISTS pgwar.project_statements_fk_property_idx; \ No newline at end of file diff --git a/database/migrations/sqls/20240618112815-pgwar-statement-indexes-up.sql b/database/migrations/sqls/20240618112815-pgwar-statement-indexes-up.sql new file mode 100644 index 000000000..10ff8375e --- /dev/null +++ b/database/migrations/sqls/20240618112815-pgwar-statement-indexes-up.sql @@ -0,0 +1,27 @@ +CREATE INDEX IF NOT EXISTS project_statements_fk_subject_info_idx + ON pgwar.project_statements USING btree + (fk_subject_info ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS project_statements_fk_object_info_idx + ON pgwar.project_statements USING btree + (fk_object_info ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS community_statements_fk_subject_info_idx + ON pgwar.community_statements USING btree + (fk_subject_info ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS community_statements_fk_object_info_idx + ON pgwar.community_statements USING btree + (fk_object_info ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS project_statements_outgoing_order_idx + ON pgwar.project_statements USING btree + (ord_num_of_range ASC NULLS LAST, tmsp_last_modification DESC NULLS FIRST); + +CREATE INDEX IF NOT EXISTS community_statements_fk_property_idx + ON pgwar.community_statements USING btree + (fk_property ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS project_statements_fk_property_idx + ON pgwar.project_statements USING btree + (fk_property ASC NULLS LAST); \ No newline at end of file diff --git a/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label.sql b/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label.sql index 50d3e4800..78fdc5f39 100644 --- a/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label.sql +++ b/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label.sql @@ -2,7 +2,7 @@ -- Start transaction and plan the tests. BEGIN; -SELECT plan(6); +SELECT plan(8); -- Create and switch to a sink table for entity previews SELECT war.create_sink_table_entity_preview('war.e'); @@ -201,6 +201,34 @@ WHERE ep.pk_entity = r.pk_entity AND r.notes = '_1' AND ep.fk_project = 1; +-- Update fk_class +UPDATE information.resource +SET fk_class = 99 +WHERE notes = '_1'; + + +SELECT IS ( + ep.fk_class, + 99, + 'Assert project entity preview has the changed class' + ) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 1; + +SELECT IS ( + ep.entity_label, + NULL, + 'Assert project entity preview has NULL after changed class' + ) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 1; + -- Finish the tests and clean up. SELECT * FROM finish(); From 41ebf4e8d8b8c701d815109a60f924418ef4b9d5 Mon Sep 17 00:00:00 2001 From: joschne Date: Wed, 19 Jun 2024 12:59:06 +0200 Subject: [PATCH 09/15] add more indexes --- ...statement-indexes.js => 20240618112815-pgwar-indexes.js} | 4 ++-- .../sqls/20240606151842-pgwar-project-entity-labels-up.sql | 4 ++++ ...dexes-down.sql => 20240618112815-pgwar-indexes-down.sql} | 3 ++- ...t-indexes-up.sql => 20240618112815-pgwar-indexes-up.sql} | 6 +++++- 4 files changed, 13 insertions(+), 4 deletions(-) rename database/migrations/{20240618112815-pgwar-statement-indexes.js => 20240618112815-pgwar-indexes.js} (94%) rename database/migrations/sqls/{20240618112815-pgwar-statement-indexes-down.sql => 20240618112815-pgwar-indexes-down.sql} (77%) rename database/migrations/sqls/{20240618112815-pgwar-statement-indexes-up.sql => 20240618112815-pgwar-indexes-up.sql} (86%) diff --git a/database/migrations/20240618112815-pgwar-statement-indexes.js b/database/migrations/20240618112815-pgwar-indexes.js similarity index 94% rename from database/migrations/20240618112815-pgwar-statement-indexes.js rename to database/migrations/20240618112815-pgwar-indexes.js index 349876b83..fb305a7da 100644 --- a/database/migrations/20240618112815-pgwar-statement-indexes.js +++ b/database/migrations/20240618112815-pgwar-indexes.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20240618112815-pgwar-statement-indexes-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240618112815-pgwar-indexes-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20240618112815-pgwar-statement-indexes-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240618112815-pgwar-indexes-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql b/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql index 836d5d75c..52eb54ccc 100644 --- a/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql +++ b/database/migrations/sqls/20240606151842-pgwar-project-entity-labels-up.sql @@ -267,6 +267,10 @@ DECLARE project_id int; entity_id int; BEGIN + IF TG_OP = 'INSERT' AND NEW.entity_label IS NULL THEN + RETURN NULL; + END IF; + project_id := COALESCE(NEW.fk_project, OLD.fk_project); entity_id := COALESCE(NEW.pk_entity, OLD.pk_entity); diff --git a/database/migrations/sqls/20240618112815-pgwar-statement-indexes-down.sql b/database/migrations/sqls/20240618112815-pgwar-indexes-down.sql similarity index 77% rename from database/migrations/sqls/20240618112815-pgwar-statement-indexes-down.sql rename to database/migrations/sqls/20240618112815-pgwar-indexes-down.sql index b4cff0dec..da33c0f35 100644 --- a/database/migrations/sqls/20240618112815-pgwar-statement-indexes-down.sql +++ b/database/migrations/sqls/20240618112815-pgwar-indexes-down.sql @@ -4,4 +4,5 @@ DROP INDEX IF EXISTS pgwar.community_statements_fk_subject_info_idx; DROP INDEX IF EXISTS pgwar.community_statements_fk_object_info_idx; DROP INDEX IF EXISTS pgwar.project_statements_outgoing_order_idx; DROP INDEX IF EXISTS pgwar.community_statements_fk_property_idx; -DROP INDEX IF EXISTS pgwar.project_statements_fk_property_idx; \ No newline at end of file +DROP INDEX IF EXISTS pgwar.project_statements_fk_property_idx; +DROP INDEX IF EXISTS pgwar.entity_preview_fk_class_idx; \ No newline at end of file diff --git a/database/migrations/sqls/20240618112815-pgwar-statement-indexes-up.sql b/database/migrations/sqls/20240618112815-pgwar-indexes-up.sql similarity index 86% rename from database/migrations/sqls/20240618112815-pgwar-statement-indexes-up.sql rename to database/migrations/sqls/20240618112815-pgwar-indexes-up.sql index 10ff8375e..ce767bd28 100644 --- a/database/migrations/sqls/20240618112815-pgwar-statement-indexes-up.sql +++ b/database/migrations/sqls/20240618112815-pgwar-indexes-up.sql @@ -24,4 +24,8 @@ CREATE INDEX IF NOT EXISTS community_statements_fk_property_idx CREATE INDEX IF NOT EXISTS project_statements_fk_property_idx ON pgwar.project_statements USING btree - (fk_property ASC NULLS LAST); \ No newline at end of file + (fk_property ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS entity_preview_fk_class_idx + ON pgwar.entity_preview USING btree + (fk_class ASC NULLS LAST); \ No newline at end of file From db8a96f7594382ecb0a3694c40952ba5f17a2c87 Mon Sep 17 00:00:00 2001 From: joschne Date: Wed, 19 Jun 2024 14:53:21 +0200 Subject: [PATCH 10/15] add index --- .../migrations/sqls/20240618112815-pgwar-indexes-down.sql | 3 ++- .../migrations/sqls/20240618112815-pgwar-indexes-up.sql | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/database/migrations/sqls/20240618112815-pgwar-indexes-down.sql b/database/migrations/sqls/20240618112815-pgwar-indexes-down.sql index da33c0f35..82e346beb 100644 --- a/database/migrations/sqls/20240618112815-pgwar-indexes-down.sql +++ b/database/migrations/sqls/20240618112815-pgwar-indexes-down.sql @@ -5,4 +5,5 @@ DROP INDEX IF EXISTS pgwar.community_statements_fk_object_info_idx; DROP INDEX IF EXISTS pgwar.project_statements_outgoing_order_idx; DROP INDEX IF EXISTS pgwar.community_statements_fk_property_idx; DROP INDEX IF EXISTS pgwar.project_statements_fk_property_idx; -DROP INDEX IF EXISTS pgwar.entity_preview_fk_class_idx; \ No newline at end of file +DROP INDEX IF EXISTS pgwar.entity_preview_fk_class_idx; +DROP INDEX IF EXISTS pgwar.entity_preview_entity_label_idx; \ No newline at end of file diff --git a/database/migrations/sqls/20240618112815-pgwar-indexes-up.sql b/database/migrations/sqls/20240618112815-pgwar-indexes-up.sql index ce767bd28..f57c5ac12 100644 --- a/database/migrations/sqls/20240618112815-pgwar-indexes-up.sql +++ b/database/migrations/sqls/20240618112815-pgwar-indexes-up.sql @@ -28,4 +28,8 @@ CREATE INDEX IF NOT EXISTS project_statements_fk_property_idx CREATE INDEX IF NOT EXISTS entity_preview_fk_class_idx ON pgwar.entity_preview USING btree - (fk_class ASC NULLS LAST); \ No newline at end of file + (fk_class ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS entity_preview_entity_label_idx + ON pgwar.entity_preview USING btree + (entity_label ASC NULLS LAST); \ No newline at end of file From fda21992dac8dde144e8280c53e9c9843a76b375 Mon Sep 17 00:00:00 2001 From: joschne Date: Thu, 20 Jun 2024 17:18:56 +0200 Subject: [PATCH 11/15] add logic to update community statements with cron job --- ...13085447-pgwar-community-statements-up.sql | 243 +++++++++++++++++- database/postgres/light.Dockerfile | 2 +- ...ted-full-texts-in-subjects-of-stmt-del.sql | 6 +- ...utdated-full-texts-in-subjects-of-stmt.sql | 6 +- ...date-community-statements-from-deletes.sql | 77 ++++++ ...date-community-statements-from-upserts.sql | 55 ++++ 6 files changed, 378 insertions(+), 11 deletions(-) create mode 100644 database/test/units/functions/pgwar-update-community-statements-from-deletes.sql create mode 100644 database/test/units/functions/pgwar-update-community-statements-from-upserts.sql diff --git a/database/migrations/sqls/20240613085447-pgwar-community-statements-up.sql b/database/migrations/sqls/20240613085447-pgwar-community-statements-up.sql index 0c7930f55..4257d2455 100644 --- a/database/migrations/sqls/20240613085447-pgwar-community-statements-up.sql +++ b/database/migrations/sqls/20240613085447-pgwar-community-statements-up.sql @@ -31,8 +31,8 @@ CREATE TABLE IF NOT EXISTS pgwar.community_statements_deleted( CREATE OR REPLACE FUNCTION pgwar.handle_community_statements_delete() RETURNS TRIGGER AS $$ BEGIN - -- Insert or update the deleted row in pgwar.community_statements - INSERT INTO pgwar.community_statements (pk_entity, fk_subject_info, fk_property, fk_object_info, object_value, tmsp_deletion) + -- Insert or update the deleted row in pgwar.community_statements_deleted + INSERT INTO pgwar.community_statements_deleted (pk_entity, fk_subject_info, fk_property, fk_object_info, object_value, tmsp_deletion) VALUES (OLD.pk_entity, OLD.fk_subject_info, OLD.fk_property, OLD.fk_object_info, OLD.object_value, CURRENT_TIMESTAMP) ON CONFLICT (pk_entity) DO UPDATE SET @@ -40,7 +40,7 @@ BEGIN fk_property = EXCLUDED.fk_property, fk_object_info = EXCLUDED.fk_object_info, object_value = EXCLUDED.object_value, - tmsp_deletion = EXCLUDED.tmsp_deletion; + tmsp_deletion = CURRENT_TIMESTAMP; RETURN OLD; END; @@ -104,4 +104,239 @@ SELECT fk_object_info, object_value, tmsp_deletion -FROM pgwar.project_statements_deleted; \ No newline at end of file +FROM pgwar.project_statements_deleted; + + +------ Table pgwar.offsets ------------------------------------------------------------------ +--------------------------------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS pgwar.offsets( + job_name text, + offset_tmsp timestamp with time zone, + PRIMARY KEY (job_name) +); + +CREATE INDEX IF NOT EXISTS project_statements_tmsp_last_modification_idx +ON pgwar.project_statements USING btree +(tmsp_last_modification ASC NULLS LAST); + +------ Function to update community statements from inserted or updated project statements -- +--------------------------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION pgwar.update_community_statements_from_upserts() +RETURNS void AS $$ +DECLARE + _job_name text; +BEGIN + _job_name := 'update-community-statements-from-upserts'; + + -- initialize offset, if needed + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- get current offset + WITH _offset AS ( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ), + -- identify updated project statements + upserted_p_stmts AS ( + SELECT pk_entity, + max(tmsp_last_modification) new_offset_tmsp + FROM ( + SELECT pk_entity, tmsp_last_modification + FROM + pgwar.project_statements, + _offset + WHERE tmsp_last_modification > _offset.offset_tmsp + ORDER BY tmsp_last_modification ASC + ) AS modified + GROUP BY pk_entity + ), + insert_community_statements AS ( + -- insert or update community statements + INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + ord_num_of_domain, + ord_num_of_range, + object_label, + object_value, + tmsp_last_modification + ) + SELECT + p_stmt.pk_entity, + p_stmt.fk_subject_info, + p_stmt.fk_property, + p_stmt.fk_object_info, + p_stmt.fk_object_tables_cell, + avg(p_stmt.ord_num_of_domain) AS ord_num_of_domain, + avg(p_stmt.ord_num_of_range) AS ord_num_of_range, + p_stmt.object_label, + p_stmt.object_value, + upserted_p_stmts.new_offset_tmsp AS tmsp_last_modification + FROM pgwar.project_statements p_stmt, + upserted_p_stmts + WHERE p_stmt.pk_entity = upserted_p_stmts.pk_entity + GROUP BY + p_stmt.pk_entity, + p_stmt.fk_subject_info, + p_stmt.fk_property, + p_stmt.fk_object_info, + p_stmt.fk_object_tables_cell, + p_stmt.object_label, + p_stmt.object_value, + upserted_p_stmts.new_offset_tmsp + ON CONFLICT (pk_entity) + DO UPDATE SET + fk_subject_info = EXCLUDED.fk_subject_info, + fk_property = EXCLUDED.fk_property, + fk_object_info = EXCLUDED.fk_object_info, + fk_object_tables_cell = EXCLUDED.fk_object_tables_cell, + ord_num_of_domain = EXCLUDED.ord_num_of_domain, + ord_num_of_range = EXCLUDED.ord_num_of_range, + object_label = EXCLUDED.object_label, + object_value = EXCLUDED.object_value, + tmsp_last_modification = EXCLUDED.tmsp_last_modification + -- return the tmsp_last_modification which equals new_offset_tmsp + RETURNING tmsp_last_modification + ) + -- set the offset + UPDATE pgwar.offsets + SET offset_tmsp = new_offset.tmsp_last_modification + FROM ( + SELECT tmsp_last_modification + FROM insert_community_statements + LIMIT 1 + ) new_offset + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; + + +CREATE INDEX IF NOT EXISTS project_statements_deleted_tmsp_deletion_idx +ON pgwar.project_statements_deleted USING btree +(tmsp_deletion ASC NULLS LAST); + +------ Function to update community statements from deleted project statements -- +--------------------------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION pgwar.update_community_statements_from_deletes() +RETURNS void AS $$ +DECLARE + _job_name text; +BEGIN + _job_name := 'update-community-statements-from-deletes'; + + -- initialize offset, if needed + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- get current offset + WITH _offset AS ( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ), + -- identify updated project statements + deleted_p_stmts AS ( + SELECT + pk_entity, + max(tmsp_deletion) new_offset_tmsp + FROM ( + SELECT pk_entity, tmsp_deletion + FROM + pgwar.project_statements_deleted, + _offset + WHERE tmsp_deletion > _offset.offset_tmsp + ORDER BY tmsp_deletion ASC + ) AS modified + GROUP BY pk_entity + ), + insert_community_statements AS ( + -- insert or update community statements + INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + ord_num_of_domain, + ord_num_of_range, + object_label, + object_value, + tmsp_last_modification + ) + SELECT + p_stmt.pk_entity, + p_stmt.fk_subject_info, + p_stmt.fk_property, + p_stmt.fk_object_info, + p_stmt.fk_object_tables_cell, + avg(p_stmt.ord_num_of_domain) AS ord_num_of_domain, + avg(p_stmt.ord_num_of_range) AS ord_num_of_range, + p_stmt.object_label, + p_stmt.object_value, + deleted_p_stmts.new_offset_tmsp AS tmsp_last_modification + FROM pgwar.project_statements p_stmt, + deleted_p_stmts + WHERE p_stmt.pk_entity = deleted_p_stmts.pk_entity + GROUP BY + p_stmt.pk_entity, + p_stmt.fk_subject_info, + p_stmt.fk_property, + p_stmt.fk_object_info, + p_stmt.fk_object_tables_cell, + p_stmt.object_label, + p_stmt.object_value, + deleted_p_stmts.new_offset_tmsp + ON CONFLICT (pk_entity) + DO UPDATE SET + fk_subject_info = EXCLUDED.fk_subject_info, + fk_property = EXCLUDED.fk_property, + fk_object_info = EXCLUDED.fk_object_info, + fk_object_tables_cell = EXCLUDED.fk_object_tables_cell, + ord_num_of_domain = EXCLUDED.ord_num_of_domain, + ord_num_of_range = EXCLUDED.ord_num_of_range, + object_label = EXCLUDED.object_label, + object_value = EXCLUDED.object_value, + tmsp_last_modification = EXCLUDED.tmsp_last_modification + -- return the tmsp_last_modification which equals new_offset_tmsp + RETURNING tmsp_last_modification + ), + delete_community_statements AS ( + DELETE FROM pgwar.community_statements + WHERE pk_entity IN (SELECT pk_entity FROM deleted_p_stmts) + AND pk_entity NOT IN ( + SELECT DISTINCT ps.pk_entity + FROM pgwar.project_statements ps, + deleted_p_stmts d + WHERE ps.pk_entity = d.pk_entity + ) + ) + -- set the offset + UPDATE pgwar.offsets + SET offset_tmsp = new_offset.tmsp_last_modification + FROM ( + SELECT tmsp_last_modification + FROM insert_community_statements + LIMIT 1 + ) new_offset + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/database/postgres/light.Dockerfile b/database/postgres/light.Dockerfile index a5a9246d1..9658ec470 100644 --- a/database/postgres/light.Dockerfile +++ b/database/postgres/light.Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/geovistory/toolbox-dev-db:s-2 +FROM ghcr.io/geovistory/toolbox-dev-db:s-3 RUN rm -Rf /logs RUN mkdir /logs diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql index 5ad25b6ff..299e3ade2 100644 --- a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql @@ -71,10 +71,10 @@ VALUES (4, 44, 31, 522, 11, NULL), SELECT is( count(*)::int, - 3, - 'Assert the limit of 3 is respected' + 1, + 'Assert the limit of 1 is respected' ) -FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(3); +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(1); SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql index e72d0a318..19489f9ec 100644 --- a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql @@ -71,10 +71,10 @@ VALUES (4, 44, 31, 522, 11, NULL), SELECT is( count(*)::int, - 3, - 'Assert the limit of 3 is respected' + 1, + 'Assert the limit of 1 is respected' ) -FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt(3); +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt(1); SELECT * FROM finish(); diff --git a/database/test/units/functions/pgwar-update-community-statements-from-deletes.sql b/database/test/units/functions/pgwar-update-community-statements-from-deletes.sql new file mode 100644 index 000000000..59d89aead --- /dev/null +++ b/database/test/units/functions/pgwar-update-community-statements-from-deletes.sql @@ -0,0 +1,77 @@ +BEGIN; + +SELECT plan(3); + +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + ord_num_of_domain, + ord_num_of_range, + object_label + ) +VALUES + (1, 99, 22, 11, 0, 0, 'LABEL'), + (2, 66, 22, 11, 4, 3, 'LABEL'), + (3, 44, 22, 11, 4, 3, 'LABEL'); + + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + ord_num_of_domain, + ord_num_of_range, + object_label + ) +VALUES + (1, 31, 99, 22, 11, 4, 3, 'LABEL'), + (1, 32, 99, 22, 11, 8, 1, 'LABEL'), + (2, 31, 66, 22, 11, 4, 3, 'LABEL'), + (2, 32, 66, 22, 11, 4, 3, 'LABEL'); + + +INSERT INTO pgwar.project_statements_deleted ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + tmsp_deletion + ) +VALUES + (1, 8765, 99, 22, 11, CURRENT_TIMESTAMP), + (3, 8765, 44, 22, 11, CURRENT_TIMESTAMP); + + +-- run the update task +SELECT pgwar.update_community_statements_from_deletes(); + +SELECT is( + ord_num_of_domain, + 6::numeric, + 'Assert the ord nums are recalculated for community statement with pk_entity 1' +) +FROM pgwar.community_statements +WHERE pk_entity = 1; + +SELECT is_empty( + 'SELECT * FROM pgwar.community_statements WHERE pk_entity = 3;', + 'Assert community statement with pk_entity 3 is deleted' +); + +SELECT is( + offset_tmsp, + CURRENT_TIMESTAMP, + 'Assert that offset is updated' +) +FROM pgwar.offsets +WHERE job_name = 'update-community-statements-from-deletes'; + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-update-community-statements-from-upserts.sql b/database/test/units/functions/pgwar-update-community-statements-from-upserts.sql new file mode 100644 index 000000000..a34299168 --- /dev/null +++ b/database/test/units/functions/pgwar-update-community-statements-from-upserts.sql @@ -0,0 +1,55 @@ +BEGIN; + +SELECT plan(3); + + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + ord_num_of_domain, + ord_num_of_range, + object_label + ) +VALUES + (1, 31, 99, 22, 11, 4, 3, 'LABEL'), + (1, 32, 99, 22, 11, 8, 1, 'LABEL'), + (2, 31, 66, 22, 11, 4, 3, 'LABEL'), + (2, 32, 66, 22, 11, 4, 3, 'LABEL'), + (3, 31, 44, 22, 11, 4, 3, 'LABEL'), + (3, 32, 44, 22, 11, 4, 3, 'LABEL'), + (3, 33, 44, 22, 11, 4, 3, 'LABEL'); + +-- run the update task +SELECT pgwar.update_community_statements_from_upserts(); + +SELECT is( + count(*), + 3::bigint, + 'Assert that 3 community statments were created' +) +FROM pgwar.community_statements; + +SELECT is( + ord_num_of_domain, + 6::numeric, + 'Assert that ord_num_of_domain is correctly calulated' +) +FROM pgwar.community_statements +WHERE pk_entity = 1; + + +SELECT is( + offset_tmsp, + CURRENT_TIMESTAMP, + 'Assert that offset is updated' +) +FROM pgwar.offsets +WHERE job_name = 'update-community-statements-from-upserts'; + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file From 1bcc562de9d35372d985f2c3afaa0854e0f330b1 Mon Sep 17 00:00:00 2001 From: joschne Date: Thu, 20 Jun 2024 21:18:18 +0200 Subject: [PATCH 12/15] update docker images --- database/postgres/heavy.Dockerfile | 2 +- database/postgres/light.Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/database/postgres/heavy.Dockerfile b/database/postgres/heavy.Dockerfile index 90f0504cd..f777f0d95 100644 --- a/database/postgres/heavy.Dockerfile +++ b/database/postgres/heavy.Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/geovistory/toolbox-dev-db:m-4 +FROM ghcr.io/geovistory/toolbox-dev-db:m-5 RUN rm -Rf /logs RUN mkdir /logs diff --git a/database/postgres/light.Dockerfile b/database/postgres/light.Dockerfile index 9658ec470..1f1d37377 100644 --- a/database/postgres/light.Dockerfile +++ b/database/postgres/light.Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/geovistory/toolbox-dev-db:s-3 +FROM ghcr.io/geovistory/toolbox-dev-db:s-4 RUN rm -Rf /logs RUN mkdir /logs From b15c9665bf20038e048383579580542bdcb6d3c1 Mon Sep 17 00:00:00 2001 From: joschne Date: Thu, 20 Jun 2024 21:28:56 +0200 Subject: [PATCH 13/15] test without performance --- .github/workflows/01-dockerize.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/01-dockerize.yml b/.github/workflows/01-dockerize.yml index 1ba8829a6..e2e0d8b83 100644 --- a/.github/workflows/01-dockerize.yml +++ b/.github/workflows/01-dockerize.yml @@ -26,7 +26,7 @@ jobs: cd database chmod -R 777 logs export POSTGRES_PORT=5432 - bash test.sh -i -u -p + bash test.sh -i -u set-version: runs-on: ubuntu-latest From 82b67fb927f420b65e31034d94b0a676eae0f647 Mon Sep 17 00:00:00 2001 From: joschne Date: Thu, 20 Jun 2024 22:00:24 +0200 Subject: [PATCH 14/15] add docker images for amd --- .github/workflows/01-dockerize.yml | 2 +- database/postgres/heavy.Dockerfile | 2 +- database/postgres/light.Dockerfile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/01-dockerize.yml b/.github/workflows/01-dockerize.yml index e2e0d8b83..1ba8829a6 100644 --- a/.github/workflows/01-dockerize.yml +++ b/.github/workflows/01-dockerize.yml @@ -26,7 +26,7 @@ jobs: cd database chmod -R 777 logs export POSTGRES_PORT=5432 - bash test.sh -i -u + bash test.sh -i -u -p set-version: runs-on: ubuntu-latest diff --git a/database/postgres/heavy.Dockerfile b/database/postgres/heavy.Dockerfile index f777f0d95..e9143b4ae 100644 --- a/database/postgres/heavy.Dockerfile +++ b/database/postgres/heavy.Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/geovistory/toolbox-dev-db:m-5 +FROM ghcr.io/geovistory/toolbox-dev-db:m-2 RUN rm -Rf /logs RUN mkdir /logs diff --git a/database/postgres/light.Dockerfile b/database/postgres/light.Dockerfile index 1f1d37377..a5a9246d1 100644 --- a/database/postgres/light.Dockerfile +++ b/database/postgres/light.Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/geovistory/toolbox-dev-db:s-4 +FROM ghcr.io/geovistory/toolbox-dev-db:s-2 RUN rm -Rf /logs RUN mkdir /logs From 06a96cecb70a4cf55bf6f7085029baac2451ea92 Mon Sep 17 00:00:00 2001 From: joschne Date: Thu, 20 Jun 2024 20:02:48 +0000 Subject: [PATCH 15/15] chore(): update prerelease version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2c0639240..ef77944d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "geovistory-root", - "version": "0.7.1-pr-359.1", + "version": "0.7.1-pr-364.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "geovistory-root", - "version": "0.7.1-pr-359.1" + "version": "0.7.1-pr-364.0" } } } diff --git a/package.json b/package.json index 5be14dd0f..6c31f22e1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "geovistory-root", "description": "root package.json of the monorepo", - "version": "0.7.1-pr-359.1", + "version": "0.7.1-pr-364.0", "scripts": {}, "private": true }