From 580b842f7835a3d1fa171afdc7e0b52cc3f9dfc6 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 14 Feb 2024 01:14:42 +0000 Subject: fix: Fix the uniquness constraint on tag name --- .../20240214011350_fix_tag_name_index/migration.sql | 11 +++++++++++ packages/db/prisma/schema.prisma | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 packages/db/prisma/migrations/20240214011350_fix_tag_name_index/migration.sql diff --git a/packages/db/prisma/migrations/20240214011350_fix_tag_name_index/migration.sql b/packages/db/prisma/migrations/20240214011350_fix_tag_name_index/migration.sql new file mode 100644 index 00000000..cbcd8821 --- /dev/null +++ b/packages/db/prisma/migrations/20240214011350_fix_tag_name_index/migration.sql @@ -0,0 +1,11 @@ +/* + Warnings: + + - A unique constraint covering the columns `[userId,name]` on the table `BookmarkTags` will be added. If there are existing duplicate values, this will fail. + +*/ +-- DropIndex +DROP INDEX "BookmarkTags_name_key"; + +-- CreateIndex +CREATE UNIQUE INDEX "BookmarkTags_userId_name_key" ON "BookmarkTags"("userId", "name"); diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index e77297c6..8a681a0b 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -102,8 +102,7 @@ model BookmarkedLink { model BookmarkTags { id String @id @default(cuid()) - // TODO: Tags are unique per user not globally - name String @unique + name String createdAt DateTime @default(now()) userId String @@ -111,6 +110,8 @@ model BookmarkTags { // Relations user User @relation(fields: [userId], references: [id], onDelete: Cascade) bookmarks TagsOnBookmarks[] + + @@unique([userId, name]) } model TagsOnBookmarks { -- cgit v1.2.3-70-g09d2