Skip to content

fix(server): index artifact.test_id so deleting a large project fits the statement timeout - #131

Open
ciprian-hudl wants to merge 2 commits into
kinora-dev:mainfrom
ciprian-hudl:upstream-artifact-test-index
Open

ciprian-hudl wants to merge 2 commits into
kinora-dev:mainfrom
ciprian-hudl:upstream-artifact-test-index

Conversation

@ciprian-hudl

@ciprian-hudl ciprian-hudl commented Oct 19, 2026 •

Copy link
Copy Markdown

Problem

artifact.test_id references test.id with ON DELETE CASCADE, but has no index. Deleting a project cascades project → run → test → artifact, and for every deleted test row Postgres scans the whole artifact table for matching test_ids.

On a self-hosted instance, a project with a few hundred runs of ~200 tests (tens of thousands of test rows) ran past the server's 30 s statement_timeout on every delete attempt (Failed query: delete from "project" where "project"."id" = $1), while small projects deleted in under a second. The same cascade runs when retention purges old runs.

Fix

Add artifact_testId_idx on artifact(test_id): a migration following 20260814180000_add_artifact_project_index, plus the matching index in the Drizzle schema.

Tests

  • New project-router test: a project delete cascades through a test-scoped attachment (artifact.test_id set), and artifact_testId_idx exists after migrations. It fails without the migration.
  • pnpm lint, pnpm typecheck, pnpm test pass; server integration tests pass against Postgres 18 and the S3 mock (282/283 locally.

🤖 Generated with Claude Code

…the statement timeout

artifact.test_id references test.id with ON DELETE CASCADE but had no index,
so deleting a project (project -> run -> test -> artifact) scanned the whole
artifact table once per deleted test row. Projects with tens of thousands of
test rows ran past the 30s statement_timeout on every delete attempt; the
same cascade runs for retention purges of old runs.

Adds artifact_testId_idx (migration + Drizzle schema), and a test that a
project delete cascades through a test-scoped attachment and that the index
exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant