Skip to content

Comments

Repeat mapping CTEs per UPDATE in lease posting rule category sync#187

Open
ghacupha wants to merge 1 commit intomasterfrom
codex/update-lease-posting-rules-in-postgresql-wioyak
Open

Repeat mapping CTEs per UPDATE in lease posting rule category sync#187
ghacupha wants to merge 1 commit intomasterfrom
codex/update-lease-posting-rules-in-postgresql-wioyak

Conversation

@ghacupha
Copy link
Owner

Motivation

  • Avoid CTE scope errors when the lease posting rule sync script is executed statement-by-statement by tools that do not preserve CTE scope across separate statements.
  • Make the operational expectations for running the script explicit in both technical and user-facing documentation.

Description

  • Duplicate the ta_rules / lease_rule_map CTE block so each UPDATE in erp-system/queries/lease-posting-rule-category-sync.sql rebuilds its mapping data and can run independently.
  • Constrain rule matching to trx_account_posting_rule_condition entries with condition_key = 'leaseContractId' and condition_operator = 'EQUALS' when building the map.
  • Add a technical note at erp-system/man_pages/lease-posting-rules/lease-posting-rule-category-sync.md and man_pages/lease-posting-rules/lease-posting-rule-category-sync.md that explains the script repeats CTEs so it can be executed as-is in tools that run each statement independently.
  • Update the user guide at user-pages/lease-posting-rule-config.md and add user-story and operational docs under erp-system/user-stories to clarify that the full script should be executed so each statement can rebuild its mapping data.

Testing

  • No automated tests were run for this change because it is an SQL and documentation-only update.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +145 to +149
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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant