From 3cbc98c050420dfa2d826a363f26e8f48ebed950 Mon Sep 17 00:00:00 2001 From: Sayak Bhattacharya Date: Fri, 5 Dec 2025 14:48:50 +0530 Subject: [PATCH] feat(psql): Backfill payouts table where organization_id is null (#10210) Co-authored-by: Sayak Bhattacharya --- .../down.sql | 3 +++ .../up.sql | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 migrations/2025-11-11-143207_backfill_org_id_in_payouts_table/down.sql create mode 100644 migrations/2025-11-11-143207_backfill_org_id_in_payouts_table/up.sql diff --git a/migrations/2025-11-11-143207_backfill_org_id_in_payouts_table/down.sql b/migrations/2025-11-11-143207_backfill_org_id_in_payouts_table/down.sql new file mode 100644 index 0000000000..56265c7845 --- /dev/null +++ b/migrations/2025-11-11-143207_backfill_org_id_in_payouts_table/down.sql @@ -0,0 +1,3 @@ +-- This file should undo anything in `up.sql` + +SELECT 1; \ No newline at end of file diff --git a/migrations/2025-11-11-143207_backfill_org_id_in_payouts_table/up.sql b/migrations/2025-11-11-143207_backfill_org_id_in_payouts_table/up.sql new file mode 100644 index 0000000000..7870ae274c --- /dev/null +++ b/migrations/2025-11-11-143207_backfill_org_id_in_payouts_table/up.sql @@ -0,0 +1,11 @@ +-- Your SQL goes here + +-- This migration backfills the organization_id column in the payouts table. +-- It sets organization_id based on the corresponding merchant_account entry for cases where the organization_id was NULL. +-- This is required for older payout records created before organization_id was introduced as a column in the payouts table. + +UPDATE payouts p +SET organization_id = ma.organization_id +FROM merchant_account ma +WHERE p.merchant_id = ma.merchant_id + AND p.organization_id IS NULL;