Add tags and categories CRUD

This commit is contained in:
2025-06-28 01:39:45 +02:00
parent 9f0807b0fc
commit 21bcee6cad
40 changed files with 2346 additions and 349 deletions

View File

@ -0,0 +1,68 @@
/*
Warnings:
- You are about to drop the column `imageId` on the `ExtractColor` table. All the data in the column will be lost.
- A unique constraint covering the columns `[name]` on the table `ExtractColor` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[name]` on the table `ImageColor` will be added. If there are existing duplicate values, this will fail.
- Made the column `name` on table `ColorPalette` required. This step will fail if there are existing NULL values in that column.
- Made the column `type` on table `ColorPalette` required. This step will fail if there are existing NULL values in that column.
- Added the required column `name` to the `ExtractColor` table without a default value. This is not possible if the table is not empty.
- Added the required column `name` to the `ImageColor` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "ExtractColor" DROP CONSTRAINT "ExtractColor_imageId_fkey";
-- DropForeignKey
ALTER TABLE "ImageColor" DROP CONSTRAINT "ImageColor_imageId_fkey";
-- AlterTable
ALTER TABLE "ColorPalette" ALTER COLUMN "name" SET NOT NULL,
ALTER COLUMN "type" SET NOT NULL;
-- AlterTable
ALTER TABLE "ExtractColor" DROP COLUMN "imageId",
ADD COLUMN "name" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "ImageColor" ADD COLUMN "name" TEXT NOT NULL;
-- CreateTable
CREATE TABLE "_ImageToImageColor" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_ImageToImageColor_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateTable
CREATE TABLE "_ImageToExtractColor" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_ImageToExtractColor_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE INDEX "_ImageToImageColor_B_index" ON "_ImageToImageColor"("B");
-- CreateIndex
CREATE INDEX "_ImageToExtractColor_B_index" ON "_ImageToExtractColor"("B");
-- CreateIndex
CREATE UNIQUE INDEX "ExtractColor_name_key" ON "ExtractColor"("name");
-- CreateIndex
CREATE UNIQUE INDEX "ImageColor_name_key" ON "ImageColor"("name");
-- AddForeignKey
ALTER TABLE "_ImageToImageColor" ADD CONSTRAINT "_ImageToImageColor_A_fkey" FOREIGN KEY ("A") REFERENCES "Image"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_ImageToImageColor" ADD CONSTRAINT "_ImageToImageColor_B_fkey" FOREIGN KEY ("B") REFERENCES "ImageColor"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_ImageToExtractColor" ADD CONSTRAINT "_ImageToExtractColor_A_fkey" FOREIGN KEY ("A") REFERENCES "ExtractColor"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_ImageToExtractColor" ADD CONSTRAINT "_ImageToExtractColor_B_fkey" FOREIGN KEY ("B") REFERENCES "Image"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `imageId` on the `ImageColor` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "ImageColor" DROP COLUMN "imageId";

View File

@ -0,0 +1,61 @@
-- CreateTable
CREATE TABLE "Category" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
CONSTRAINT "Category_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Tag" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
CONSTRAINT "Tag_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "_ImageTags" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_ImageTags_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateTable
CREATE TABLE "_ImageCategories" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_ImageCategories_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE UNIQUE INDEX "Category_name_key" ON "Category"("name");
-- CreateIndex
CREATE UNIQUE INDEX "Tag_name_key" ON "Tag"("name");
-- CreateIndex
CREATE INDEX "_ImageTags_B_index" ON "_ImageTags"("B");
-- CreateIndex
CREATE INDEX "_ImageCategories_B_index" ON "_ImageCategories"("B");
-- AddForeignKey
ALTER TABLE "_ImageTags" ADD CONSTRAINT "_ImageTags_A_fkey" FOREIGN KEY ("A") REFERENCES "Image"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_ImageTags" ADD CONSTRAINT "_ImageTags_B_fkey" FOREIGN KEY ("B") REFERENCES "Tag"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_ImageCategories" ADD CONSTRAINT "_ImageCategories_A_fkey" FOREIGN KEY ("A") REFERENCES "Category"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_ImageCategories" ADD CONSTRAINT "_ImageCategories_B_fkey" FOREIGN KEY ("B") REFERENCES "Image"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -103,19 +103,19 @@ model Image {
// sourceId String?
// source Source? @relation(fields: [sourceId], references: [id])
colors ImageColor[]
extractColors ExtractColor[]
metadata ImageMetadata[]
pixels PixelSummary[]
stats ImageStats[]
theme ThemeSeed[]
variants ImageVariant[]
//
metadata ImageMetadata[]
pixels PixelSummary[]
stats ImageStats[]
theme ThemeSeed[]
variants ImageVariant[]
// albumCover Album[] @relation("AlbumCoverImage")
// categories Category[] @relation("ImageCategories")
// galleryCover Gallery[] @relation("GalleryCoverImage")
palettes ColorPalette[] @relation("ImagePalettes")
// tags Tag[] @relation("ImageTags")
categories Category[] @relation("ImageCategories")
colors ImageColor[] @relation("ImageToImageColor")
extractColors ExtractColor[] @relation("ImageToExtractColor")
palettes ColorPalette[] @relation("ImagePalettes")
tags Tag[] @relation("ImageTags")
}
model ImageMetadata {
@ -183,8 +183,8 @@ model ColorPalette {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String?
type String?
name String
type String
items ColorPaletteItem[]
images Image[] @relation("ImagePalettes")
@ -207,17 +207,17 @@ model ExtractColor {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
hex String
imageId String
blue Int
green Int
red Int
name String @unique
hex String
blue Int
green Int
red Int
area Float?
hue Float?
saturation Float?
image Image @relation(fields: [imageId], references: [id])
images Image[] @relation("ImageToExtractColor")
}
model ImageColor {
@ -225,15 +225,15 @@ model ImageColor {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
imageId String
type String
name String @unique
type String
hex String?
blue Int?
green Int?
red Int?
image Image @relation(fields: [imageId], references: [id])
images Image[] @relation("ImageToImageColor")
}
model ThemeSeed {
@ -259,3 +259,27 @@ model PixelSummary {
image Image @relation(fields: [imageId], references: [id])
}
model Category {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @unique
description String?
images Image[] @relation("ImageCategories")
}
model Tag {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @unique
description String?
images Image[] @relation("ImageTags")
}