21 lines · 943 B
-- Custom domain add-on: a separate Stripe subscription whose quantity is the account's custom domain count.
CREATE TABLE billing_addons (
  account_id TEXT NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
  addon TEXT NOT NULL,
  subscription_id TEXT,
  item_id TEXT,
  status TEXT,
  quantity INTEGER NOT NULL DEFAULT 0,
  -- created time (ms) of the newest subscription event applied, so out-of-order deliveries never regress state.
  event_at INTEGER NOT NULL DEFAULT 0,
  -- When the add-on stopped being active; custom domains are released once the grace period after it passes.
  lapsed_at INTEGER,
  updated_at INTEGER NOT NULL,
  PRIMARY KEY (account_id, addon)
);

CREATE INDEX billing_addons_lapsed ON billing_addons(addon, lapsed_at);

-- Admin grant: custom domains without the paid add-on (comped accounts, or instances without billing).
ALTER TABLE account_billing ADD COLUMN custom_domains_grant INTEGER NOT NULL DEFAULT 0;