#835 — Add volume calculations to merchants table after syncing batches

Repo: Twill-AI/facade State: closed | Status: done Assignee: Ahmad1809

Created: 2025-12-16 · Updated: 2025-12-26

Description

AC:

  • There is a new raw SQL query that is run on the the same job as batch sync (after materialized views are updated). The query should update the ** mtd_payment_volume** in the merchants table from the values in the materialized view.
  • There is a new raw SQL query that is run on the the same job as batch sync (after materialized views are updated). The query should update the total_payment_volume in the merchants table from the values in the materialized view.
  • The code for the hourly syncs (from PE, luqra, and EMS) has been checked to make sure volume values are not overwritten.

Possible SQL query:

UPDATE "{master_schema_name}".merchant m
        SET mtd_volume = COALESCE(
            (
                SELECT total_volume
                FROM "{master_schema_name}".merchant_volume_monthly_mv mvmv
                WHERE mvmv.merchant_id = m.id
                AND mvmv.period_start = {{}}
            ),
            0
        );

Please note that the mtd_volume column will be introduced after https://github.com/Twill-AI/facade/pull/829/commits/0a1a09942cb87e6b40524d925442defaf853c4ce is merged

Notes

Add implementation notes, blockers, and context here

Add wikilinks to related people, meetings, or other tickets