Packages: from one analysis to unlimited, admin can give them
A fixed catalog (packages.rs, reasoning in docs/csomagok.md): Egy elemzés
2 990 Ft, Páros 6 990 Ft, Család 11 990 Ft (featured), Korlátlan 17 990 Ft
for a year, and two top-ups. Every grant is a package_orders row; units are
credit_ledger rows with reason 'package' and never expire. The unlimited
package is a time-limited 'unlimited' entitlement: analyses use no unit and
persons have no limit, with a daily fair-use cap (UNLIMITED_DAILY_LIMIT, 5);
buying it again extends it by a year.
- GET /v1/packages, mock payment by package id, /v1/me unlimited_until
- POST /v1/admin/users/{id}/packages: give a package as a gift
- /csomagok page; the paid step of an analysis offers three packages with
the bigger one featured; person packs use the catalog; admin user list
has a package column
- PERSON_PACK_SIZE is replaced by the catalog's +5 személy top-up
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
-- Packages: every purchase or admin grant of a package is an order; the units
|
||||
-- it gives are credit_ledger rows pointing at it (reason 'package'), and the
|
||||
-- unlimited package is a time-limited 'unlimited' entitlement.
|
||||
CREATE TABLE package_orders (
|
||||
id uuid PRIMARY KEY,
|
||||
user_id uuid NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
package text NOT NULL,
|
||||
source text NOT NULL CHECK (source IN ('admin', 'mock', 'stripe')),
|
||||
price_huf integer NOT NULL DEFAULT 0 CHECK (price_huf >= 0),
|
||||
note text,
|
||||
created_by uuid REFERENCES users ON DELETE SET NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX package_orders_user_idx ON package_orders (user_id, created_at DESC);
|
||||
|
||||
ALTER TABLE credit_ledger DROP CONSTRAINT credit_ledger_reason_check;
|
||||
ALTER TABLE credit_ledger ADD CONSTRAINT credit_ledger_reason_check
|
||||
CHECK (reason IN ('monthly_grant', 'analysis', 'chat', 'refund', 'admin_adjust', 'purchase', 'person', 'package'));
|
||||
ALTER TABLE credit_ledger ADD COLUMN order_id uuid REFERENCES package_orders ON DELETE SET NULL;
|
||||
|
||||
-- 'unlimited': analyses and persons without limit until expires_at.
|
||||
ALTER TABLE entitlements DROP CONSTRAINT entitlements_entitlement_check;
|
||||
ALTER TABLE entitlements ADD CONSTRAINT entitlements_entitlement_check
|
||||
CHECK (entitlement IN ('unlimited_persons', 'unlimited'));
|
||||
ALTER TABLE entitlements ADD COLUMN expires_at timestamptz;
|
||||
Reference in New Issue
Block a user