Phase 4 part 1: the full Stripe sync, and margins per product
Customers, invoices with all their lines (both of Stripe's line shapes), credit notes, refunds (with their customer) and products: a backfill, then the Events API every hour, and a new backfill when events have expired. Metrics page with sync status. Gross margin per product: a default (60%) and overrides, with names from Stripe's products or the invoice lines. Schemas 18 and 19. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -495,6 +495,48 @@ CREATE TABLE seo_briefs (
|
||||
live_at TEXT
|
||||
);
|
||||
CREATE INDEX seo_briefs_by_site ON seo_briefs (site, id);
|
||||
`,
|
||||
// 18: the full Stripe data for the metrics: every customer, invoice,
|
||||
// credit note and refund as Stripe sent it, and the invoice lines the
|
||||
// MRR model reads.
|
||||
`
|
||||
CREATE TABLE stripe_objects (
|
||||
kind TEXT NOT NULL, -- customer, invoice, credit_note, refund
|
||||
id TEXT NOT NULL,
|
||||
customer TEXT NOT NULL DEFAULT '',
|
||||
created INTEGER NOT NULL DEFAULT 0,
|
||||
status TEXT NOT NULL DEFAULT '',
|
||||
currency TEXT NOT NULL DEFAULT '',
|
||||
amount INTEGER NOT NULL DEFAULT 0, -- invoice: total; credit note: total; refund: amount
|
||||
data TEXT NOT NULL,
|
||||
PRIMARY KEY (kind, id)
|
||||
);
|
||||
CREATE INDEX stripe_objects_by_customer ON stripe_objects (kind, customer);
|
||||
CREATE TABLE stripe_invoice_lines (
|
||||
invoice TEXT NOT NULL,
|
||||
id TEXT NOT NULL,
|
||||
customer TEXT NOT NULL DEFAULT '',
|
||||
status TEXT NOT NULL DEFAULT '', -- the invoice's
|
||||
currency TEXT NOT NULL DEFAULT '',
|
||||
amount INTEGER NOT NULL DEFAULT 0, -- after discounts, before tax
|
||||
period_start INTEGER NOT NULL DEFAULT 0,
|
||||
period_end INTEGER NOT NULL DEFAULT 0,
|
||||
subscription TEXT NOT NULL DEFAULT '',
|
||||
price TEXT NOT NULL DEFAULT '',
|
||||
product TEXT NOT NULL DEFAULT '',
|
||||
interval TEXT NOT NULL DEFAULT '',
|
||||
interval_count INTEGER NOT NULL DEFAULT 0,
|
||||
quantity INTEGER NOT NULL DEFAULT 0,
|
||||
proration INTEGER NOT NULL DEFAULT 0,
|
||||
recurring INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (invoice, id)
|
||||
);
|
||||
CREATE INDEX stripe_invoice_lines_by_customer ON stripe_invoice_lines (customer, period_start);
|
||||
`,
|
||||
// 19: invoice lines' descriptions, which name the product when the key
|
||||
// can't read Products.
|
||||
`
|
||||
ALTER TABLE stripe_invoice_lines ADD COLUMN description TEXT NOT NULL DEFAULT '';
|
||||
`,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user