You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,38 @@ pnpm run build && pnpm start
74
74
- Lookup the matching `user_account` by `user_account_id`, then query the Members DB by `user_name` (handle)
75
75
- Upsert `BillingAccountAccess` for the resolved `userId`
76
76
77
+
- Engagement payment consumed backfill:
78
+
- Required env:
79
+
-`DATABASE_URL` for billing-accounts-api-v6.
80
+
-`FINANCE_DB_URL` for tc-finance-api (`winnings` and `payment`).
81
+
-`ENGAGEMENTS_DB_URL` for engagements-api-v6 (`EngagementAssignment` and `Engagement`).
82
+
-`PROJECTS_DB_URL` for projects-api-v6 (`projects.billingAccountId`, matching the trusted project lookup used by engagements-api-v6).
83
+
- Optional `TGBillingAccounts` for finance-compatible TopGear exemptions. If unset, the script uses finance's default exempt accounts `80000062,80002800`.
84
+
- Dry run:
85
+
-`pnpm run backfill:engagementPayments -- --dry-run`
86
+
- Dry run is the default. It reads finance engagement payments, resolves assignment/project/billing account context, plans inserts/updates, and writes a JSON audit report under `scripts/output/`.
87
+
- Apply:
88
+
-`pnpm run backfill:engagementPayments -- --apply`
- Uses `payment.challenge_markup` first as a markup rate and computes `total_amount + (total_amount * challenge_markup)`.
92
+
- If `payment.challenge_markup` is absent and `payment.challenge_fee` is present, treats `challenge_fee` as an absolute fee amount, computes `total_amount + challenge_fee`, and records the row in the `absoluteFee` audit bucket.
93
+
- If neither finance value is present, falls back to the current `BillingAccount.markup` and records that fallback in the audit report.
94
+
- Skips automated consumed-row planning for TopGear-exempt billing accounts and records those payments in the `exemptBillingAccounts` audit bucket.
95
+
- Apply mode runs billing mutations, post-apply total calculation, and report writing inside one billing database transaction. If a write, verification read, or report write fails before commit, the billing mutations are rolled back.
96
+
- Reconciles one assignment-level aggregate row for historical idempotency. Existing correct rows are left alone; a single incorrect row is updated; multiple existing rows are only moved when their total already matches the legacy expected amount.
97
+
- Exceptions such as missing assignments, missing project billing accounts, missing billing accounts, and ambiguous consumed duplicates are reported without blocking resolvable assignments.
98
+
- Validation:
99
+
- The dry-run/apply report includes expected legacy totals and current/projected billing totals.
100
+
-`verify:engagementPayments` invokes `psql` directly, so export `DATABASE_URL` in the shell before running it.
101
+
- If the source schemas are visible in one Postgres session, run:
- The verification SQL lists mismatches between expected legacy engagement-payment consumes and `ConsumedAmount` rows with `externalType = ENGAGEMENT`. TopGear-exempt accounts are reported separately as `topgear_exempt_*` statuses.
104
+
- Rollback:
105
+
- Use the JSON report from the apply run. A successful apply only commits after that report is written. Delete rows listed with `action: "insert"` and `createdId`; restore rows listed with `action: "update_single"` from `previous`; restore rows listed with `action: "move_existing_rows"` from their `existingRows` billing account ids.
106
+
- If apply mode exits with an error before writing the report, the transaction rolled back and there should be no partial billing-ledger changes from that run.
107
+
- If apply mode exits with an error after a report file exists, run the verifier or a dry run before rollback; the billing transaction should have committed all planned actions or none.
108
+
77
109
## Downstream Usage
78
110
79
111
- This service is consumed (directly or indirectly) by multiple Topcoder apps. The pointers below help with debugging.
0 commit comments