-- SYNTHETIC LAB ONLY. The runner creates a new, disposable cluster.
\set ON_ERROR_STOP on
DO $$
BEGIN
  IF current_database() <> 'synthetic_proof' THEN
    RAISE EXCEPTION 'Only run in the isolated synthetic_proof database';
  END IF;
END $$;

-- Intentionally no DROP/IF EXISTS: abort if this schema already exists.
CREATE SCHEMA proof;
CREATE TABLE proof.orders (
  order_id bigint PRIMARY KEY,
  tenant_id integer NOT NULL,
  status text NOT NULL,
  created_at timestamp NOT NULL,
  total_cents integer NOT NULL,
  payload text NOT NULL
) WITH (autovacuum_enabled = false);

INSERT INTO proof.orders
SELECT g,
       1 + (g % 1000)::integer,
       CASE WHEN (g / 1000) % 5 = 0 THEN 'open' ELSE 'closed' END,
       timestamp '2026-01-01 00:00:00' + g * interval '1 second',
       ((g * 37) % 100000)::integer,
       repeat('synthetic-order-payload-', 6)
FROM generate_series(1::bigint, 1000000::bigint) AS g;

VACUUM (ANALYZE) proof.orders;
SELECT count(*) AS synthetic_order_count FROM proof.orders;
