Repeat mapping CTEs per UPDATE in lease posting rule category sync#187
Repeat mapping CTEs per UPDATE in lease posting rule category sync#187
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2641c07ef2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| UPDATE trx_account_posting_rule_condition condition | ||
| SET condition_value = mapping.lease_contract_id::text | ||
| FROM lease_rule_map mapping | ||
| WHERE condition.posting_rule_id = mapping.posting_rule_id | ||
| AND condition.condition_key = 'leaseContractId'; |
There was a problem hiding this comment.
Limit leaseContractId normalization to EQUALS conditions
The CTE map is built only from trx_account_posting_rule_condition rows where condition_operator = 'EQUALS', but the final UPDATE normalizes all leaseContractId conditions for those posting rules regardless of operator. If a rule has multiple leaseContractId conditions (e.g., an additional NOT_EQUALS or CONTAINS operator), this statement will overwrite those values with the single mapped contract id, changing the rule’s matching semantics. Restrict the update to condition_operator = 'EQUALS' or to the specific condition rows used in the mapping to avoid corrupting other operators.
Useful? React with 👍 / 👎.
Motivation
Description
ta_rules/lease_rule_mapCTE block so eachUPDATEinerp-system/queries/lease-posting-rule-category-sync.sqlrebuilds its mapping data and can run independently.trx_account_posting_rule_conditionentries withcondition_key = 'leaseContractId'andcondition_operator = 'EQUALS'when building the map.erp-system/man_pages/lease-posting-rules/lease-posting-rule-category-sync.mdandman_pages/lease-posting-rules/lease-posting-rule-category-sync.mdthat explains the script repeats CTEs so it can be executed as-is in tools that run each statement independently.user-pages/lease-posting-rule-config.mdand add user-story and operational docs undererp-system/user-storiesto clarify that the full script should be executed so each statement can rebuild its mapping data.Testing
Codex Task