Skip to content

Commit 5ca3c64

Browse files
chatchclaude
andcommitted
fix customer_status trigger passing OLD.status blocks flag toggles
The customers trigger was passing OLD.status='live' to customer_status(), causing the once-live-stay-live guard to fire on deliberate flag changes (revoking has_payment_method, confirmed_details_at, allow_onboard_transition). Pass NULL so the trigger always does a full recompute. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 75cee33 commit 5ca3c64

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

sqitch/deploy/0021_corporate_body_customer_status.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,19 @@ END;
119119
$function$
120120
;
121121

122+
-- The customers trigger was passing OLD.status which caused the 'once live, stay live'
123+
-- guard to fire on deliberate flag toggles (e.g. revoking has_payment_method). Pass NULL
124+
-- so the trigger always does a full status recompute.
125+
CREATE OR REPLACE FUNCTION myenergy.customer_status_update_on_trigger() RETURNS trigger
126+
LANGUAGE plpgsql SECURITY DEFINER
127+
AS $$
128+
DECLARE
129+
new_status myenergy.customer_status_enum;
130+
BEGIN
131+
SELECT myenergy.customer_status(NEW, NULL, NULL) INTO new_status;
132+
NEW.status = new_status;
133+
RETURN NEW;
134+
END;
135+
$$;
136+
122137
COMMIT;

sqitch/revert/0021_corporate_body_customer_status.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,16 @@ END;
110110
$function$
111111
;
112112

113+
CREATE OR REPLACE FUNCTION myenergy.customer_status_update_on_trigger() RETURNS trigger
114+
LANGUAGE plpgsql SECURITY DEFINER
115+
AS $$
116+
DECLARE
117+
new_status myenergy.customer_status_enum;
118+
BEGIN
119+
SELECT myenergy.customer_status(NEW, OLD.status, NULL) INTO new_status;
120+
NEW.status = new_status;
121+
RETURN NEW;
122+
END;
123+
$$;
124+
113125
COMMIT;

0 commit comments

Comments
 (0)