deep-foundation / deep-foundation/deeplinks
Selector is not updated when SelectorInclude link is inserted
- Dominant language
- TypeScript
- Stars
- 13
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description

Expected behavior: 57 is included in 463 rule.
Actual behavior: 57 is not included in 463 rule.
The root cause:
Here are first level of code of triggers for `selectors_cache` table:
https://github.com/deep-foundation/deeplinks/blob/7295fbc2feabe8cdd128f7a5381734480226644a/migrations/1616701513790-selectors-cashe.ts#L79-L246
```sql
CREATE OR REPLACE FUNCTION ${TABLE_NAME}__insert__function() RETURNS TRIGGER AS $trigger$
DECLARE
selectorTree RECORD;
selectorCursor RECORD;
selectorFilter bigint = 0;
boolExpId bigint = 0;
selectorId bigint;
ruleAction RECORD;
ruleObject RECORD;
caches RECORD;
ruleSubject RECORD;
insertedIncludeId bigint = 0;
insertedExcludeId bigint = 0;
BEGIN
IF (NEW."type_id" = ${deep.idLocal('@deep-foundation/core', 'SelectorTree')}) THEN
-- ...
END IF;
IF (NEW."type_id" = ${deep.idLocal('@deep-foundation/core', 'SelectorFilter')}) THEN
UPDATE "${TABLE_NAME}" SET "selector_filter_bool_exp_id" = NEW."to_id" WHERE "selector_id" = NEW."from_id";
END IF;
IF (NEW."type_id" = ${deep.idLocal('@deep-foundation/core', 'RuleAction')}) THEN
-- ...
END IF;
IF (NEW."type_id" = ${deep.idLocal('@deep-foundation/core', 'RuleObject')}) THEN
-- ...
END IF;
IF (NEW."type_id" = ${deep.idLocal('@deep-foundation/core', 'RuleSubject')}) THEN
-- ...
END IF;
RETURN NEW;
END; $trigger$ LANGUAGE plpgsql;
```
https://github.com/deep-foundation/deeplinks/blob/7295fbc2feabe8cdd128f7a5381734480226644a/migrations/1616701513790-selectors-cashe.ts#L248-L285
```sql
CREATE OR REPLACE FUNCTION ${TABLE_NAME}__delete__function() RETURNS TRIGGER AS $trigger$
BEGIN
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'Selector')}) THEN
DELETE FROM ${TABLE_NAME} WHERE "selector_id" = OLD."id";
END IF;
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'SelectorInclude')}) THEN
DELETE FROM ${TABLE_NAME} WHERE "selector_include_id" = OLD."id";
END IF;
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'SelectorExclude')}) THEN
DELETE FROM ${TABLE_NAME} WHERE "selector_exclude_id" = OLD."id";
END IF;
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'SelectorTree')}) THEN
DELETE FROM ${TABLE_NAME} WHERE "selector_tree_id" = OLD."id";
END IF;
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'Tree')}) THEN
DELETE FROM ${TABLE_NAME} WHERE "tree_id" = OLD."id";
END IF;
DELETE FROM ${TABLE_NAME} WHERE "link_id" = OLD."id";
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'SelectorFilter')}) THEN
UPDATE "${TABLE_NAME}" SET "selector_filter_bool_exp_id" = 0 WHERE "selector_id" = OLD."from_id";
END IF;
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'Query')}) THEN
UPDATE "${TABLE_NAME}" SET "selector_filter_bool_exp_id" = 0 WHERE "selector_filter_bool_exp_id" = OLD."id";
END IF;
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'Rule')}) THEN
DELETE FROM ${TABLE_NAME} WHERE "rule_id" = OLD."id";
END IF;
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'RuleAction')}) THEN
DELETE FROM ${TABLE_NAME} WHERE "rule_action_id" = OLD."id";
END IF;
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'RuleObject')}) THEN
DELETE FROM ${TABLE_NAME} WHERE "rule_object_id" = OLD."id";
END IF;
IF (OLD."type_id" = ${deep.idLocal('@deep-foundation/core', 'RuleSubject')}) THEN
DELETE FROM ${TABLE_NAME} WHERE "rule_subject_id" = OLD."id";
END IF;
RETURN OLD;
END; $trigger$ LANGUAGE plpgsql;
```
These types are not used in insert trigger, but used in delete trigger:
* Selector
* SelectorInclude
* SelectorExclude
* Tree
* Query
* Rule
As a workaround for changing the selectors at the moment, would be:
Recreation of `RuleObject/RuleSubject/RuleActions` links.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.