tenseleyflow/shithub / 31abd7f

Browse files

migrations/0078: invoice status 'refunded' enum + billing_invoices.refunded_at

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
31abd7f4325e4b5ce105c80a08a1782d5e97cd82
Parents
735dcd9
Tree
8b26b7b

1 changed file

StatusFile+-
A internal/migrationsfs/migrations/0078_billing_invoices_refunded.sql 36 0
internal/migrationsfs/migrations/0078_billing_invoices_refunded.sqladded
@@ -0,0 +1,36 @@
1
+-- SPDX-License-Identifier: AGPL-3.0-or-later
2
+--
3
+-- PAYMENTS PRO08 D2 — surface refunds in shithub.
4
+--
5
+-- Stripe handles refunds out-of-band: a `charge.refunded` event fires,
6
+-- but the underlying invoice's `status` stays `paid`. shithub wants
7
+-- a UI surface ("Refunded $X on date Y") on the billing settings
8
+-- page, so we track refunds locally:
9
+--
10
+-- - `refunded_at` on billing_invoices records when the operator (or
11
+--   the cardholder) issued the refund.
12
+-- - The status enum gains a `refunded` value the UI can switch on.
13
+--
14
+-- Refund handling does NOT automatically cancel the subscription.
15
+-- An operator issuing a refund may want to keep Pro active (e.g.,
16
+-- a goodwill refund). Subscription cancellation is a separate Stripe
17
+-- action — Stripe's customer.subscription.deleted handler handles
18
+-- that path. This migration is UI surface only.
19
+
20
+-- +goose Up
21
+-- Postgres requires ALTER TYPE ... ADD VALUE outside a transaction.
22
+-- The migration is no-tx by goose default for this statement.
23
+
24
+-- +goose NO TRANSACTION
25
+ALTER TYPE billing_invoice_status ADD VALUE IF NOT EXISTS 'refunded';
26
+
27
+-- +goose StatementBegin
28
+ALTER TABLE billing_invoices
29
+    ADD COLUMN IF NOT EXISTS refunded_at timestamptz;
30
+-- +goose StatementEnd
31
+
32
+-- +goose Down
33
+ALTER TABLE billing_invoices DROP COLUMN IF EXISTS refunded_at;
34
+-- Note: Postgres does not support DROP VALUE on an enum, so the
35
+-- 'refunded' enum entry is permanent. Down migrations that depend
36
+-- on it require a full type recreate; for now we leave the value.