066_add_scheduled_test_tables.sql 1.5 KB

123456789101112131415161718192021222324252627282930
  1. -- 066_add_scheduled_test_tables.sql
  2. -- Scheduled account test plans and results
  3. CREATE TABLE IF NOT EXISTS scheduled_test_plans (
  4. id BIGSERIAL PRIMARY KEY,
  5. account_id BIGINT NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
  6. model_id VARCHAR(100) NOT NULL DEFAULT '',
  7. cron_expression VARCHAR(100) NOT NULL DEFAULT '*/30 * * * *',
  8. enabled BOOLEAN NOT NULL DEFAULT true,
  9. max_results INT NOT NULL DEFAULT 50,
  10. last_run_at TIMESTAMPTZ,
  11. next_run_at TIMESTAMPTZ,
  12. created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  13. updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
  14. );
  15. CREATE INDEX IF NOT EXISTS idx_stp_account_id ON scheduled_test_plans(account_id);
  16. CREATE INDEX IF NOT EXISTS idx_stp_enabled_next_run ON scheduled_test_plans(enabled, next_run_at) WHERE enabled = true;
  17. CREATE TABLE IF NOT EXISTS scheduled_test_results (
  18. id BIGSERIAL PRIMARY KEY,
  19. plan_id BIGINT NOT NULL REFERENCES scheduled_test_plans(id) ON DELETE CASCADE,
  20. status VARCHAR(20) NOT NULL DEFAULT 'success',
  21. response_text TEXT NOT NULL DEFAULT '',
  22. error_message TEXT NOT NULL DEFAULT '',
  23. latency_ms BIGINT NOT NULL DEFAULT 0,
  24. started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  25. finished_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  26. created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
  27. );
  28. CREATE INDEX IF NOT EXISTS idx_str_plan_created ON scheduled_test_results(plan_id, created_at DESC);