-- Part 7: transactional outbox plus receiver inbox
-- Compose after: 06-shapes/source.sql on the producer and content/series/durable-work-postgres/source/schema.sql on the receiver.

BEGIN;
UPDATE orders SET status = 'paid' WHERE id = 9182;
INSERT INTO outbox (partition_key, event_type, payload, idempotency_key)
VALUES (
  'order:9182',
  'OrderPaid',
  '{"order_id":9182,"paid_at":"2026-07-01T12:00:00Z"}'::jsonb,
  'evt-order-9182-paid-v1'
);
COMMIT;

INSERT INTO inbox (partition_key, partition_bucket, payload, idempotency_key)
VALUES ($1, $2, $3, $4)
ON CONFLICT (idempotency_key) WHERE idempotency_key IS NOT NULL DO NOTHING;
