Skip to content

Issue #754: tighten projects.effort CHECK constraint via v28 migration#757

Merged
hubertciebiada merged 1 commit into
mainfrom
fix/754-tighten-projects-effort-check
May 27, 2026
Merged

Issue #754: tighten projects.effort CHECK constraint via v28 migration#757
hubertciebiada merged 1 commit into
mainfrom
fix/754-tighten-projects-effort-check

Conversation

@hubertciebiada
Copy link
Copy Markdown
Owner

Summary

Defense-in-depth follow-up to the v22 migration. Adds a v28 SQLite migration that recreates the projects table with a tightened effort CHECK constraint (IN ('low','medium','high','xhigh')), removing the legacy 'max' value at the DB layer.

  • No client change required. Audit confirmed every UI surface (ProjectsPage, AddProjectDialog, TeamRow, TeamDetail, shared/types.ts), service-level validators (ProjectService.createProject/updateProject), the MCP add-project tool, and event-collector already reject 'max'. The user-reported repro is almost certainly stale browser bundle from v0.0.24.
  • Why the DB needs hardening anyway. The v19 addEffortColumn() migration installed CHECK(effort IN ('low','medium','high','xhigh','max')). v22 rewrote DATA from maxxhigh but SQLite cannot ALTER a CHECK in place — so legacy DBs still accept 'max' via direct API/MCP call or future regression. v28 closes that loophole.
  • Approach. Standard SQLite "create new table, copy, drop, rename" pattern inside a transaction, with PRAGMA foreign_keys=OFF toggled OUTSIDE the transaction in a try/finally. v_team_dashboard dropped inside the transaction; schema.sql recreates it at end of initSchema(). PRAGMA foreign_key_check runs before commit. Migration is idempotent (fresh DB + schema_version >= 28 short-circuits).

Closes #754

Test plan

  • npx tsc --noEmit clean
  • npm run build succeeds
  • 7 new v28 migration tests in tests/server/db.test.ts pass:
    • rewrites projects so INSERT effort='max' throws CHECK constraint failed
    • preserves all project rows during recreate
    • preserves FK references from teams/project_issue_sources
    • bumps schema_version to >= 28
    • idempotent on restart (log emitted exactly once)
    • no-op on fresh DB
    • v_team_dashboard view exists after migration
  • New POST validator test in tests/server/routes/projects-routes.test.ts confirms effort='max' returns 400 with 'xhigh' in the message (closes the gap where only PUT was tested)
  • No client files modified

🤖 Generated with Claude Code

Adds a v28 SQLite migration that recreates the projects table with a
tightened effort CHECK constraint (IN ('low','medium','high','xhigh')),
removing the legacy 'max' value at the DB layer. Defense-in-depth
follow-up to the v22 migration which rewrote DATA but left the CHECK
alone — legacy databases still accepted effort='max' writes despite no
client surface emitting that value anymore.

The migration uses the standard SQLite create-new / copy / drop / rename
pattern inside a transaction with FKs temporarily disabled (PRAGMA set
outside the transaction per better-sqlite3 semantics, restored via
try/finally). Drops v_team_dashboard before the rename and lets
schema.sql recreate it at the end of initSchema(). PRAGMA
foreign_key_check runs inside the transaction and aborts if any
violation is reported.

Adds 7 v28 tests covering: INSERT max throws CHECK failure, rows
preserved, FKs preserved across teams + project_issue_sources, schema
bumped to >= 28, idempotence (second initSchema is a no-op + log
emitted exactly once on first run), fresh-DB no-op, v_team_dashboard
remains queryable. Also adds a POST /api/projects validator test
asserting effort='max' returns 400 with 'xhigh' in the error message.

No client changes.
@hubertciebiada hubertciebiada enabled auto-merge (squash) May 27, 2026 09:43
@hubertciebiada hubertciebiada merged commit 1c1506b into main May 27, 2026
1 check passed
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.

ui: 'max' effort reportedly still selectable on Projects page (needs repro)

1 participant