x
This commit is contained in:
1 parent
0ceee3dbff
commit
2d39edbd57
18 files changed
+804
-153
No files matched your search
+25
@@ -0,0 +1,25 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "CategoryMedia" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"categoryId" INTEGER NOT NULL,
|
||||
"role" TEXT NOT NULL,
|
||||
"url" TEXT NOT NULL,
|
||||
"width" INTEGER,
|
||||
"height" INTEGER,
|
||||
"focalX" DOUBLE PRECISION NOT NULL DEFAULT 0.5,
|
||||
"focalY" DOUBLE PRECISION NOT NULL DEFAULT 0.5,
|
||||
"sortOrder" INTEGER NOT NULL DEFAULT 0,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "CategoryMedia_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "CategoryMedia_categoryId_sortOrder_idx" ON "CategoryMedia"("categoryId", "sortOrder");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "CategoryMedia_categoryId_role_key" ON "CategoryMedia"("categoryId", "role");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "CategoryMedia" ADD CONSTRAINT "CategoryMedia_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
-- Preserve every existing Category.imageUrl as the initial semantic thumbnail.
|
||||
-- The legacy column remains available while API and frontend consumers migrate.
|
||||
INSERT INTO "CategoryMedia" (
|
||||
"categoryId",
|
||||
"role",
|
||||
"url",
|
||||
"focalX",
|
||||
"focalY",
|
||||
"sortOrder",
|
||||
"createdAt",
|
||||
"updatedAt"
|
||||
)
|
||||
SELECT
|
||||
"id",
|
||||
'thumbnail',
|
||||
"imageUrl",
|
||||
0.5,
|
||||
0.5,
|
||||
0,
|
||||
CURRENT_TIMESTAMP,
|
||||
CURRENT_TIMESTAMP
|
||||
FROM "Category"
|
||||
WHERE "imageUrl" IS NOT NULL
|
||||
AND BTRIM("imageUrl") <> ''
|
||||
ON CONFLICT ("categoryId", "role") DO NOTHING;
|
||||
@@ -35,6 +35,7 @@ model Category {
|
||||
name String @unique
|
||||
imageUrl String?
|
||||
layoutType String @default("split_showcase")
|
||||
media CategoryMedia[]
|
||||
products Product[]
|
||||
attributes AttributeDefinition[]
|
||||
translations CategoryTranslation[]
|
||||
@@ -45,6 +46,24 @@ model Category {
|
||||
@@index([deletedAt])
|
||||
}
|
||||
|
||||
model CategoryMedia {
|
||||
id Int @id @default(autoincrement())
|
||||
categoryId Int
|
||||
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
|
||||
role String
|
||||
url String
|
||||
width Int?
|
||||
height Int?
|
||||
focalX Float @default(0.5)
|
||||
focalY Float @default(0.5)
|
||||
sortOrder Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([categoryId, role])
|
||||
@@index([categoryId, sortOrder])
|
||||
}
|
||||
|
||||
model CategoryTranslation {
|
||||
id Int @id @default(autoincrement())
|
||||
categoryId Int
|
||||
|
||||
Reference in new issue
Block a user