Repository navigation
fix(projects): enforce unique task ID prefixes - #780
Conversation
Separate third-party imports from local packages and use the test context for the migration audit query. Validated with golangci-lint 2.15.0 (Go 1.26.11): 0 issues; all four TestProjectPrefix PostgreSQL tests passed with -race against the isolated task cluster.
|
Hi @sinbumu , |
There was a problem hiding this comment.
✅ No new issues found.
Approach: sound — the database index is the single arbiter for prefix uniqueness, the migration dedupes, audits and builds that index in one transaction, and the service treats the constraint violation as the retry signal, so concurrent creates cannot bypass it.
Reviewed changes — read the full diff (35 files, both commits) and ran the new Postgres tests plus the affected Go packages locally.
- Migration
000093: dedupes active non-empty prefixes (oldest kept bycreated_at, id, first free numeric suffix within 10 chars), records old/new inproject_prefix_changes_000093, and adds the partial unique index onupper(task_id_prefix) WHERE task_id_prefix <> '' AND deleted_at IS NULL, all inside the runner's per-file transaction. - Repository and service:
Create/Updatemap the named index violation toErrPrefixTakenahead of the generic name fallback; auto-generated prefixes retry through the constraint while explicit prefixes fail fast. - Lookups:
FindByTaskIDPrefix,FindTaskByKeyand gitFindTaskByRefcarry the non-empty/soft-delete predicates and drop the oldest-project fallback. - API and web: 409
PROJECT_PREFIX_TAKENis mapped and documented; both project forms surface it inline in all nine locales, and untouched suggestions are server-allocated. - Tests: Postgres migration/dedupe/replay/concurrency coverage, service retry tests, an integration 409 test and a web component test.
Verification: the four TestProjectPrefix* tests pass against a local PostgreSQL 18 cluster, and go test passes for internal/service/project, internal/transport/http/handler, internal/transport/http/presenter, internal/repository/postgres and test/integration.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

Summary
Closes #779. Short task keys now identify a single active project: non-empty prefixes are unique case-insensitively, while soft-deleted projects and empty prefixes are excluded.
created_at, then UUID), assigns available numeric suffixes within 10 characters, records old/new values inproject_prefix_changes_000093, and creates the partial unique index. Project writes are locked until deduplication, audit records and index creation commit together. Crash-window replay preserves the audit history.ErrPrefixTaken/ HTTP 409PROJECT_PREFIX_TAKEN, distinct from the existing name error. Automatic creation retries conflicting candidates through the database constraint, including concurrent requests; failed attempts roll back their setup.Data and link impact
Task/project UUIDs and task numbers are preserved; UUID URLs remain stable. Renamed projects get new display keys, CSV labels and short links. Historical short links and textual git references are not rewritten or aliased: an old duplicate key addresses the project that retained the prefix, or returns not found if it lacks that task number. Future prefix changes or reuse after soft deletion can also change an old short link's target. Authorization on the resolved task remains in place.
The migration blocks project writes during deduplication/index construction. There is no automatic down migration: dropping the index does not restore old prefixes. Keep backups and the audit history; blindly restoring old values after subsequent edits would be unsafe. An application-only rollback retains the new values, but old binaries lack conflict handling. Details are in the development and API documentation.
Validation
Passed locally on macOS:
go test -race -timeout 300s ./...with DB/E2E opt-ins unset (Docker E2E and optional PostgreSQL tests skip in this mode).go vet ./...andgo build ./....bun run lintandbun run buildpassed. Lint reports four existing unused-suppression warnings in untouched files; build reports large chunks. Node 25 neededNODE_OPTIONS=--no-experimental-webstoragefor the existing jsdom setup.The wider optional PostgreSQL suite is not green: eight existing top-level tests fail, reproduced unchanged at base
4a5e5da: document row-lock timing, git upsert previous-state reporting, IAM key mapping, plugin-manifest migration, project-role-resource migration, roles API, roles-assign migration, and service-account API. These are outside this change.Not run locally: PostgreSQL 16, Docker full-stack E2E, Playwright browsers, and golangci-lint. The new PostgreSQL tests use the repository's existing
PACA_TEST_PG_DSNopt-in. No existing/production database was contacted, and no deployment was performed.Type of Change
Other: project key integrity and conflict handling.
Checklist
AI-assisted implementation and automated review/testing with OpenAI Codex. Human review is still pending; this PR is intentionally a draft.