railyard/apps/rago/crates/rago-db/migrations/0048_fixed_charge_code.sql
caelum0x 386ff23608 feat(rago): REST plan fixed charges and plan charge reads
Fixed charges are billed now, so the REST API can manage them like Lago's
Plans::FixedChargesController:
- GET/POST /plans/:code/fixed_charges and GET/PUT/DELETE
  /plans/:code/fixed_charges/:code (add_on_code or add_on_id, code defaulting
  to the add-on's, standard/graduated/volume, units >= 0, unique code per
  plan). Migration 0048 adds fixed_charges.code; GraphQL-created ones get
  their id as code. GET /plans/:code shows fixed_charges.
- GET /plans/:code/charges and GET /plans/:code/charges/:id (id or code); the
  plan charge routes were write-only.

Tests: rago-api plan_fixed_charges (live Postgres, incl. the invoice preview
billing 8 seats and nothing after the delete). Full workspace with pg-tests:
575 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 15:11:14 +03:00

7 lines
419 B
SQL

-- Fixed charges get Lago's `code` (unique per plan among live rows), so the
-- REST API can address them as /plans/:code/fixed_charges/:fixed_charge_code.
ALTER TABLE fixed_charges ADD COLUMN IF NOT EXISTS code varchar;
UPDATE fixed_charges SET code = id::text WHERE code IS NULL;
CREATE UNIQUE INDEX IF NOT EXISTS index_fixed_charges_on_plan_id_and_code
ON fixed_charges (plan_id, code) WHERE deleted_at IS NULL;