lesson-export.sql 1.2 KB

1234567891011121314151617
  1. BEGIN;
  2. CREATE TABLE IF NOT EXISTS xs_history_export_job (
  3. id text PRIMARY KEY DEFAULT md5(random()::text||clock_timestamp()::text),
  4. company text NOT NULL,actor text NOT NULL,scope text NOT NULL,request_key text NOT NULL,filters jsonb NOT NULL,
  5. status text NOT NULL DEFAULT 'queued' CHECK(status IN('queued','running','ready','failed','cancelled')),
  6. total integer NOT NULL DEFAULT 0,processed integer NOT NULL DEFAULT 0,snapshot_ready boolean NOT NULL DEFAULT false,
  7. lease text,lease_until timestamptz,attempts integer NOT NULL DEFAULT 0,error text NOT NULL DEFAULT '',file_base64 text,
  8. created_at timestamptz NOT NULL DEFAULT now(),expires_at timestamptz NOT NULL DEFAULT now()+interval '24 hours',
  9. UNIQUE(company,actor,request_key)
  10. );
  11. CREATE UNIQUE INDEX IF NOT EXISTS xs_history_export_one_per_owner ON xs_history_export_job(company,actor) WHERE status IN('queued','running');
  12. CREATE INDEX IF NOT EXISTS xs_history_export_queue ON xs_history_export_job(status,created_at);
  13. CREATE TABLE IF NOT EXISTS xs_history_export_row (
  14. job_id text NOT NULL REFERENCES xs_history_export_job(id) ON DELETE CASCADE,position integer NOT NULL,value jsonb NOT NULL,
  15. PRIMARY KEY(job_id,position)
  16. );
  17. COMMIT;