Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit df16cf6

Browse files
bpamiriclaude
andcommitted
fix: Add unique index on tags(blog_id, name) to prevent duplicate tags
Duplicate tags accumulated when the edit flow's deleteBlogTags() silently failed (due to val() precision loss on BIGINT IDs) while saveTags() still inserted new rows. Cleaned up 97 existing duplicates and added a database constraint to prevent recurrence. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 68f4958 commit df16cf6

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
component extends="wheels.migrator.Migration" hint="adds unique index on tags(blog_id, name) to prevent duplicate tags per blog post" {
2+
3+
function up() {
4+
transaction {
5+
try {
6+
execute("CREATE UNIQUE INDEX idx_tags_blog_id_name ON tags (blog_id, name)");
7+
} catch (any ex) {
8+
local.exception = ex;
9+
}
10+
11+
if (StructKeyExists(local, "exception")) {
12+
transaction action="rollback";
13+
Throw(errorCode = "1", detail = local.exception.detail, message = local.exception.message, type = "any");
14+
} else {
15+
transaction action="commit";
16+
}
17+
}
18+
}
19+
20+
function down() {
21+
transaction {
22+
try {
23+
execute("DROP INDEX IF EXISTS idx_tags_blog_id_name");
24+
} catch (any ex) {
25+
local.exception = ex;
26+
}
27+
28+
if (StructKeyExists(local, "exception")) {
29+
transaction action="rollback";
30+
Throw(errorCode = "1", detail = local.exception.detail, message = local.exception.message, type = "any");
31+
} else {
32+
transaction action="commit";
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)