Lands the previously-untracked rago app: a Rust port of Lago billing with the three audit fixes from the 2026-09-03 railyard audit baked in: - CRITICAL: deterministic Stripe idempotency key (UUIDv5 of invoice id, sent as 'Idempotency-Key: payment-<id>') replacing the random-UUID-per- attempt pattern that allowed retry double-charges - HIGH: unique index on events(organization_id, external_subscription_id, transaction_id) with idempotent ON CONFLICT DO NOTHING insert; duplicate transaction_id surfaces as an API validation error, not a 500 - HIGH: partial unique index on invoice_subscriptions(subscription_id, charges_from_datetime, charges_to_datetime) WHERE recurring, with insert_subscription_invoice_guarded returning Created|AlreadyBilled, wired into bill_subscription and the scheduler Includes real-Postgres #[sqlx::test] suites (rago-db idempotency/parity, rago-jobs rebill/clock, rago-graphql admin1-5, rago-api rest_crud).
50 lines
1.7 KiB
SQL
50 lines
1.7 KiB
SQL
-- Entitlements: features → privileges → entitlements (feature on plan/sub) → values.
|
|
CREATE TABLE IF NOT EXISTS entitlement_features (
|
|
id uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY,
|
|
organization_id uuid NOT NULL,
|
|
code varchar NOT NULL,
|
|
name varchar,
|
|
description varchar,
|
|
deleted_at timestamp(6),
|
|
created_at timestamp(6) NOT NULL,
|
|
updated_at timestamp(6) NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS entitlement_privileges (
|
|
id uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY,
|
|
organization_id uuid NOT NULL,
|
|
entitlement_feature_id uuid NOT NULL,
|
|
code varchar NOT NULL,
|
|
name varchar,
|
|
value_type varchar DEFAULT 'string' NOT NULL,
|
|
config jsonb DEFAULT '{}' NOT NULL,
|
|
deleted_at timestamp(6),
|
|
created_at timestamp(6) NOT NULL,
|
|
updated_at timestamp(6) NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS entitlement_entitlements (
|
|
id uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY,
|
|
organization_id uuid NOT NULL,
|
|
entitlement_feature_id uuid NOT NULL,
|
|
plan_id uuid,
|
|
subscription_id uuid,
|
|
deleted_at timestamp(6),
|
|
created_at timestamp(6) NOT NULL,
|
|
updated_at timestamp(6) NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS entitlement_entitlement_values (
|
|
id uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY,
|
|
organization_id uuid NOT NULL,
|
|
entitlement_privilege_id uuid NOT NULL,
|
|
entitlement_entitlement_id uuid NOT NULL,
|
|
value varchar NOT NULL,
|
|
deleted_at timestamp(6),
|
|
created_at timestamp(6) NOT NULL,
|
|
updated_at timestamp(6) NOT NULL
|
|
);
|
|
|
|
-- Provider mandate id on the customer↔provider link (GoCardless).
|
|
ALTER TABLE payment_provider_customers ADD COLUMN IF NOT EXISTS provider_mandate_id varchar;
|