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).
21 lines
894 B
SQL
21 lines
894 B
SQL
-- Durable, Postgres-backed job queue (replaces in-memory scheduling).
|
|
CREATE TABLE IF NOT EXISTS jobs (
|
|
id uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY,
|
|
queue varchar DEFAULT 'default' NOT NULL,
|
|
job_type varchar NOT NULL,
|
|
payload jsonb DEFAULT '{}' NOT NULL,
|
|
status varchar DEFAULT 'pending' NOT NULL, -- pending | leased | succeeded | failed | dead
|
|
attempts integer DEFAULT 0 NOT NULL,
|
|
max_attempts integer DEFAULT 5 NOT NULL,
|
|
run_at timestamp(6) DEFAULT now() NOT NULL,
|
|
leased_at timestamp(6),
|
|
leased_by varchar,
|
|
last_error text,
|
|
created_at timestamp(6) DEFAULT now() NOT NULL,
|
|
updated_at timestamp(6) DEFAULT now() NOT NULL
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_jobs_due ON jobs (status, run_at);
|
|
|
|
-- Webhook re-delivery scheduling: when the next retry is due.
|
|
ALTER TABLE webhooks ADD COLUMN IF NOT EXISTS next_retry_at timestamp(6);
|