g1t/services/billing/migrations/0027_stripe_cache.sql
| 1 | -- What billing keeps of Stripe so reads never wait on it (stripe_sync.rs). |
| 2 | |
| 3 | -- The workspace's saved card as Stripe last said, refreshed by card and |
| 4 | -- customer events and a weekly pass. card_synced_at NULL: never read, or |
| 5 | -- forgotten after g1t itself changed the card; the next read asks Stripe. |
| 6 | ALTER TABLE accounts ADD COLUMN card_brand TEXT; |
| 7 | ALTER TABLE accounts ADD COLUMN card_last4 TEXT; |
| 8 | ALTER TABLE accounts ADD COLUMN card_exp_month INTEGER; |
| 9 | ALTER TABLE accounts ADD COLUMN card_exp_year INTEGER; |
| 10 | ALTER TABLE accounts ADD COLUMN card_synced_at TEXT; |
| 11 | |
| 12 | -- Card and customer events name the customer, not the workspace. |
| 13 | CREATE INDEX IF NOT EXISTS accounts_by_customer ON accounts (customer_id); |
| 14 | |
| 15 | -- How far missed events have been replayed from Stripe's event list, per |
| 16 | -- key mode: every event created before `through` (Unix seconds) has been |
| 17 | -- seen, by its webhook or by the replay. |
| 18 | CREATE TABLE stripe_sync ( |
| 19 | mode TEXT PRIMARY KEY, |
| 20 | through INTEGER NOT NULL, |
| 21 | checked_at TEXT NOT NULL |
| 22 | ); |