Commit 6b61473
fix(deleter): clean up all billing and kyc records during org delete (#1835)
Organization delete could fail halfway and leave the org without owners
and with a billing account pointing to a deleted Stripe customer.
Checkout and kyc rows were never removed, so their foreign keys made
the hard delete of billing_customers and organizations fail after the
Stripe customer was already gone. Retrying hit the same error forever.
- delete checkout rows before the billing customer row
- delete the org_kyc row before the org row
- delete credit transactions instead of orphaning them
- always remove local subscription and invoice rows, also for offline
billing accounts
- tear down billing first and org policies near the end, so a failure
at any step leaves the org owned and the delete retryable
- treat subscriptions already gone or canceled on the provider as
canceled instead of failing the teardown
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent c4b8ca5 commit 6b61473
15 files changed
Lines changed: 698 additions & 195 deletions
File tree
- billing
- checkout
- credit
- mocks
- subscription
- cmd
- core
- deleter
- mocks
- kyc
- mocks
- internal/store/postgres
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
768 | 769 | | |
769 | 770 | | |
770 | 771 | | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
771 | 778 | | |
772 | 779 | | |
773 | 780 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
178 | 185 | | |
179 | 186 | | |
180 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
312 | 321 | | |
313 | 322 | | |
314 | 323 | | |
| |||
1076 | 1085 | | |
1077 | 1086 | | |
1078 | 1087 | | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
1079 | 1093 | | |
1080 | 1094 | | |
1081 | 1095 | | |
1082 | 1096 | | |
1083 | 1097 | | |
1084 | 1098 | | |
1085 | 1099 | | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | 1100 | | |
1090 | | - | |
1091 | | - | |
| 1101 | + | |
| 1102 | + | |
1092 | 1103 | | |
1093 | 1104 | | |
1094 | 1105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
| 621 | + | |
| 622 | + | |
622 | 623 | | |
623 | 624 | | |
624 | 625 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments