feat(cron): enforce unique active cron job names per agent+user#712
Open
nguyennguyenit wants to merge 2 commits intomainfrom
Open
feat(cron): enforce unique active cron job names per agent+user#712nguyennguyenit wants to merge 2 commits intomainfrom
nguyennguyenit wants to merge 2 commits intomainfrom
Conversation
Add partial unique index on cron_jobs to prevent duplicate active jobs with the same name for a given tenant+agent+user scope. - Migration 000037: dedup existing rows, add idx_cron_jobs_unique_active_name - PG/SQLite stores: handle unique constraint on insert (return existing job) and on update (return ErrCronJobDuplicateName) - CronTool: pre-check for duplicate name before insert to give clear feedback - Bump RequiredSchemaVersion to 37
Contributor
💡 Suggestion: Add suffix instead of DELETE in migrationAnh @NguyenNLT ơi, theo góp ý từ anh @viettx, em nghĩ mình nên thêm suffix vào tên job thay vì DELETE duplicate jobs trong migration.
|
Rename newer duplicates with '-dup-{id[:8]}' suffix before applying
unique index. Prevents data loss and keeps the migration reversible.
Addresses review feedback from PR #712.
Contributor
Author
|
Đã cập nhật theo đề xuất. Migration 000037 giờ rename các job duplicate thay vì DELETE: UPDATE cron_jobs
SET name = name || '-dup-' || substr(id::text, 1, 8)
WHERE id IN (SELECT id FROM dupes WHERE rn > 1);
|
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
000037: partial unique indexidx_cron_jobs_unique_active_nameoncron_jobs(scoped totenant_id + agent_id + user_id + namewhereenabled = true). Deduplicates existing rows before adding constraint.cron_crud.go,cron_update.go): detect23505unique constraint violation on insert (return existing job) and on update (returnErrCronJobDuplicateName).CronTool: pre-check for duplicate name before attempting insert, returning clear feedback to the agent.RequiredSchemaVersion→ 37.Test Plan
go build ./...passesgo build -tags sqliteonly ./...passesgo vet ./...passesErrCronJobDuplicateName