Currency, storefronts, purchasing (#12)

And a few other minor things, but primarily, the balance table exists and also consumable/inventory table.
This commit is contained in:
devin
2026-07-15 14:10:49 -04:00
committed by GitHub
parent 8314e54439
commit c33919bc67
29 changed files with 2204 additions and 524 deletions
@@ -0,0 +1,15 @@
-- Received gift boxes, owned by the `econ` worker. One row per box: a box is created
-- when a player buys a storefront item (`/api/storefronts/v2/buyItem`) and deleted when
-- the client opens it (`/api/avatar/v2/gifts/consume`, on the `api` worker). Opening is
-- cosmetic — the item is granted into the `inventory` table at purchase time, so a box
-- carries only its rendered content (`data`) for the gift list. Kept in sync with
-- RECEIVED_GIFT_SCHEMA_DDL in @repo/domain's gifts-db.ts.
CREATE TABLE IF NOT EXISTS received_gift (
id INTEGER PRIMARY KEY AUTOINCREMENT,
account_id INTEGER NOT NULL,
data TEXT NOT NULL,
created_at TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_received_gift_account ON received_gift (account_id);
+14
View File
@@ -0,0 +1,14 @@
-- Owned avatar items, owned by the `econ` worker. One row per (account, item): the
-- items a player has bought from a storefront. Granted at purchase time by
-- `/api/storefronts/v2/buyItem` and read back by `/api/avatar/v4/items`, where they are
-- concatenated with the default catalog. The item is keyed by its `AvatarItemDesc` (the
-- gift-drop's item guid string) so re-buying the same item is a no-op rather than a
-- duplicate row; `data` is the rendered avatar-item DTO. Kept in sync with
-- INVENTORY_SCHEMA_DDL in src/inventory-db.ts.
CREATE TABLE IF NOT EXISTS inventory (
account_id INTEGER NOT NULL,
avatar_item_desc TEXT NOT NULL,
data TEXT NOT NULL,
PRIMARY KEY (account_id, avatar_item_desc)
);
+18
View File
@@ -0,0 +1,18 @@
-- Owned consumables, owned by the `econ` worker. Unlike avatar items (own-once, one
-- row per (account, item)), consumables stack: each purchase inserts a fresh instance
-- row carrying its own id, count and created_at. Granted at purchase time by
-- `/api/storefronts/v2/buyItem` (when the gift-drop carries a `ConsumableItemDesc`) and
-- read back by `/api/consumables/v2/getUnlocked`, which groups a player's rows by
-- `consumable_item_desc` into the client's unlocked-consumable DTO (its `Ids`/`CreatedAts`
-- are these per-instance columns; `Count` their sum). Kept in sync with
-- CONSUMABLE_SCHEMA_DDL in src/consumables-db.ts.
CREATE TABLE IF NOT EXISTS consumable (
id INTEGER PRIMARY KEY AUTOINCREMENT,
account_id INTEGER NOT NULL,
consumable_item_desc TEXT NOT NULL,
count INTEGER NOT NULL,
created_at TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_consumable_account ON consumable (account_id);