app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

0026_order_validation_receipt_projection.sql (1117B)


      1 CREATE TABLE order_validation_receipts (
      2     event_id TEXT PRIMARY KEY NOT NULL,
      3     order_id TEXT REFERENCES orders(id) ON DELETE CASCADE,
      4     raw_order_id TEXT NOT NULL,
      5     root_event_id TEXT NOT NULL,
      6     listing_event_id TEXT NOT NULL,
      7     target_event_id TEXT NOT NULL,
      8     receipt_type TEXT NOT NULL CHECK (
      9         receipt_type IN ('listing_validation', 'trade_transition', 'inventory_state', 'state_checkpoint')
     10     ),
     11     result TEXT NOT NULL CHECK (
     12         result IN ('valid', 'needs_review')
     13     ),
     14     proof_system TEXT NOT NULL CHECK (
     15         proof_system IN ('none', 'sp1_core', 'sp1_compressed', 'sp1_groth16', 'sp1_plonk')
     16     ),
     17     event_set_root TEXT NOT NULL,
     18     reducer_output_root TEXT NOT NULL,
     19     public_values_hash TEXT NOT NULL,
     20     event_created_at INTEGER NOT NULL CHECK (event_created_at >= 0)
     21 );
     22 
     23 CREATE INDEX idx_order_validation_receipts_order_time
     24     ON order_validation_receipts(order_id, event_created_at DESC, event_id DESC)
     25     WHERE order_id IS NOT NULL;
     26 
     27 CREATE INDEX idx_order_validation_receipts_root_order
     28     ON order_validation_receipts(root_event_id, raw_order_id);