Issue #754: tighten projects.effort CHECK constraint via v28 migration#757
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Defense-in-depth follow-up to the v22 migration. Adds a v28 SQLite migration that recreates the
projectstable with a tightenedeffortCHECK constraint (IN ('low','medium','high','xhigh')), removing the legacy'max'value at the DB layer.ProjectsPage,AddProjectDialog,TeamRow,TeamDetail,shared/types.ts), service-level validators (ProjectService.createProject/updateProject), the MCPadd-projecttool, andevent-collectoralready reject'max'. The user-reported repro is almost certainly stale browser bundle from v0.0.24.addEffortColumn()migration installedCHECK(effort IN ('low','medium','high','xhigh','max')). v22 rewrote DATA frommax→xhighbut 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.PRAGMA foreign_keys=OFFtoggled OUTSIDE the transaction in atry/finally.v_team_dashboarddropped inside the transaction; schema.sql recreates it at end ofinitSchema().PRAGMA foreign_key_checkruns before commit. Migration is idempotent (fresh DB +schema_version >= 28short-circuits).Closes #754
Test plan
npx tsc --noEmitcleannpm run buildsucceedstests/server/db.test.tspass:INSERT effort='max'throws CHECK constraint failedschema_versionto >= 28v_team_dashboardview exists after migrationtests/server/routes/projects-routes.test.tsconfirmseffort='max'returns 400 with'xhigh'in the message (closes the gap where only PUT was tested)🤖 Generated with Claude Code