Skip to content

Commit

Permalink
new repo: added missing triggers for org_closure handling on m_org
Browse files Browse the repository at this point in the history
After the design of closure was changed to include identity rows,
it is necessary to mark closure for refresh even when m_org is inserted
or deleted - and this was missing.
  • Loading branch information
virgo47 committed Jan 13, 2022
1 parent bf476e9 commit 6a9626a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
4 changes: 2 additions & 2 deletions config/sql/native-new/postgres-new-upgrade-audit.sql
Expand Up @@ -77,8 +77,8 @@ BEGIN

END loop;
END $$;
$aac$, false);
$aac$);

-- WRITE CHANGES ABOVE ^^
-- IMPORTANT: update apply_audit_change number at the end of postgres-new-upgrade-audit.sql
-- IMPORTANT: update apply_audit_change number at the end of postgres-new-audit.sql
-- to match the number used in the last change here!
27 changes: 25 additions & 2 deletions config/sql/native-new/postgres-new-upgrade.sql
Expand Up @@ -19,8 +19,31 @@ call apply_change(0, $$ SELECT 1 $$, true);

-- changes for 4.4.1

-- REPLACE THIS WITH THE FIRST CHANGE
-- adding trigger to mark org closure for refresh when org is inserted/deleted
call apply_change(1, $aa$
-- The trigger that flags the view for refresh after m_org changes.
CREATE OR REPLACE FUNCTION mark_org_closure_for_refresh_org()
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO m_global_metadata VALUES ('orgClosureRefreshNeeded', 'true')
ON CONFLICT (name) DO UPDATE SET value = 'true';

-- after trigger returns null
RETURN NULL;
END $$;

-- Update is not necessary, it does not change relations between orgs.
-- If it does, it is handled by trigger on m_ref_object_parent_org.
CREATE TRIGGER m_org_mark_refresh_tr
AFTER INSERT OR DELETE ON m_org
FOR EACH ROW EXECUTE FUNCTION mark_org_closure_for_refresh_org();
CREATE TRIGGER m_org_mark_refresh_trunc_tr
AFTER TRUNCATE ON m_org
FOR EACH STATEMENT EXECUTE FUNCTION mark_org_closure_for_refresh_org();
$aa$);

-- WRITE CHANGES ABOVE ^^
-- IMPORTANT: update apply_change number at the end of postgres-new-upgrade.sql
-- IMPORTANT: update apply_change number at the end of postgres-new.sql
-- to match the number used in the last change here!
25 changes: 24 additions & 1 deletion config/sql/native-new/postgres-new.sql
Expand Up @@ -761,6 +761,28 @@ CREATE TRIGGER m_ref_object_parent_mark_refresh_trunc_tr
AFTER TRUNCATE ON m_ref_object_parent_org
FOR EACH STATEMENT EXECUTE FUNCTION mark_org_closure_for_refresh();

-- The trigger that flags the view for refresh after m_org changes.
CREATE OR REPLACE FUNCTION mark_org_closure_for_refresh_org()
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO m_global_metadata VALUES ('orgClosureRefreshNeeded', 'true')
ON CONFLICT (name) DO UPDATE SET value = 'true';

-- after trigger returns null
RETURN NULL;
END $$;

-- Update is not necessary, it does not change relations between orgs.
-- If it does, it is handled by trigger on m_ref_object_parent_org.
CREATE TRIGGER m_org_mark_refresh_tr
AFTER INSERT OR DELETE ON m_org
FOR EACH ROW EXECUTE FUNCTION mark_org_closure_for_refresh_org();
CREATE TRIGGER m_org_mark_refresh_trunc_tr
AFTER TRUNCATE ON m_org
FOR EACH STATEMENT EXECUTE FUNCTION mark_org_closure_for_refresh_org();

-- This procedure for conditional refresh when needed is called from the application code.
-- The refresh can be forced, e.g. after many changes with triggers off (or just to be sure).
CREATE OR REPLACE PROCEDURE m_refresh_org_closure(force boolean = false)
Expand Down Expand Up @@ -1842,4 +1864,5 @@ END $$;
-- endregion

-- Initializing the last change number used in postgres-new-upgrade.sql.
call apply_change(0, $$ SELECT 1 $$, true);
call apply_change(1, $$ SELECT 1 $$, true);

0 comments on commit 6a9626a

Please sign in to comment.