From e798338107f3333ecc7887a06d7f9dee7f2dd02a Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Fri, 27 Mar 2026 22:56:18 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20db:=20update=20schema?= =?UTF-8?q?=20for=20new=20collection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration.sql | 14 ++++++++++++++ prisma/schema.prisma | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/20260327155457_add_collection_unique_by_owner_and_id/migration.sql diff --git a/prisma/migrations/20260327155457_add_collection_unique_by_owner_and_id/migration.sql b/prisma/migrations/20260327155457_add_collection_unique_by_owner_and_id/migration.sql new file mode 100644 index 0000000..5a06b55 --- /dev/null +++ b/prisma/migrations/20260327155457_add_collection_unique_by_owner_and_id/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - You are about to alter the column `name` on the `collections` table. The data in that column could be lost. The data in that column will be cast from `VarChar(255)` to `VarChar(115)`. + - A unique constraint covering the columns `[slug,ownerId]` on the table `collections` will be added. If there are existing duplicate values, this will fail. + - Added the required column `slug` to the `collections` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "collections" ADD COLUMN "slug" VARCHAR(115) NOT NULL, +ALTER COLUMN "name" SET DATA TYPE VARCHAR(115); + +-- CreateIndex +CREATE UNIQUE INDEX "collections_slug_ownerId_key" ON "collections"("slug", "ownerId"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f91c2c2..1c5f444 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -418,7 +418,8 @@ model UserLog { model Collection { id String @id @db.Uuid - name String @db.VarChar(255) + name String @db.VarChar(115) + slug String @db.VarChar(115) medias Media[] @relation("MediaCollections") owner User @relation("UserCollections", fields: [ownerId], references: [id]) ownerId String @db.Uuid @@ -429,6 +430,8 @@ model Collection { deletedAt DateTime? createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt + + @@unique([slug, ownerId]) @@map("collections") }