db: update user preference table

This commit is contained in:
Mahen 2026-02-13 11:03:17 +07:00
parent fd94d4a599
commit 3e87f8566f
3 changed files with 143 additions and 67 deletions

View File

@ -0,0 +1,38 @@
/*
Warnings:
- You are about to drop the column `role` on the `User` table. All the data in the column will be lost.
*/
-- CreateEnum
CREATE TYPE "OS" AS ENUM ('WINDOWS', 'MACOS', 'LINUX', 'CHROME_OS', 'OTHER');
-- CreateEnum
CREATE TYPE "Brand" AS ENUM ('APPLE', 'ASUS', 'ACER', 'LENOVO', 'HP', 'DELL', 'MSI', 'AXIOO', 'ADVAN', 'ZYREX', 'OTHER');
-- AlterTable
ALTER TABLE "User" DROP COLUMN "role",
ADD COLUMN "bio" TEXT,
ADD COLUMN "birthDate" TIMESTAMP(3),
ADD COLUMN "location" TEXT;
-- CreateTable
CREATE TABLE "UserPreference" (
"id" SERIAL NOT NULL,
"profession" TEXT,
"preferredOS" "OS",
"preferedBrand" "Brand",
"budgetMin" INTEGER,
"budgetMax" INTEGER,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"userId" INTEGER NOT NULL,
CONSTRAINT "UserPreference_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "UserPreference_userId_key" ON "UserPreference"("userId");
-- AddForeignKey
ALTER TABLE "UserPreference" ADD CONSTRAINT "UserPreference_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -6,7 +6,6 @@ datasource db {
provider = "postgresql" provider = "postgresql"
} }
// --- ENUMS ---
enum UserGender { enum UserGender {
male male
female female
@ -24,6 +23,28 @@ enum Sentiment {
NEUTRAL NEUTRAL
} }
enum OS {
WINDOWS
MACOS
LINUX
CHROME_OS
OTHER
}
enum Brand {
APPLE
ASUS
ACER
LENOVO
HP
DELL
MSI
AXIOO
ADVAN
ZYREX
OTHER
}
model Account { model Account {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
userId Int userId Int
@ -64,87 +85,105 @@ model User {
email String? @unique email String? @unique
emailVerified DateTime? emailVerified DateTime?
image String? image String?
gender UserGender?
password String? password String?
role Role @default(USER) bio String? @db.Text
location String?
createdAt DateTime @default(now()) birthDate DateTime?
updatedAt DateTime @updatedAt gender UserGender?
accounts Account[]
sessions Session[]
analyses Analysis[]
}
model Product {
id Int @id @default(autoincrement())
name String
brand String?
url String @unique
image String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
reviews Review[] accounts Account[]
analyses Analysis[] sessions Session[]
analyses Analysis[]
preference UserPreference?
}
model UserPreference {
id Int @id @default(autoincrement())
profession String?
preferredOS OS?
preferedBrand Brand?
budgetMin Int?
budgetMax Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId Int @unique
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model Product {
id Int @id @default(autoincrement())
name String
brand String?
url String @unique
image String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
reviews Review[]
analyses Analysis[]
} }
model Review { model Review {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
content String content String
sentiment Sentiment sentiment Sentiment
confidenceScore Float confidenceScore Float
keywords String[] keywords String[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
productId Int createdAt DateTime @default(now())
product Product @relation(fields: [productId], references: [id], onDelete: Cascade) updatedAt DateTime @updatedAt
modelId Int?
model Model? @relation(fields: [modelId], references: [id])
}
model Analysis {
id Int @id @default(autoincrement())
targetProfession String
generalSentiment Float
compatibilityScore Float
verdict String
topKeywords String[]
createdAt DateTime @default(now())
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
productId Int productId Int
product Product @relation(fields: [productId], references: [id], onDelete: Cascade) product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
modelId Int modelId Int?
model Model @relation(fields: [modelId], references: [id]) model Model? @relation(fields: [modelId], references: [id])
}
model Analysis {
id Int @id @default(autoincrement())
targetProfession String
generalSentiment Float
compatibilityScore Float
verdict String
topKeywords String[]
createdAt DateTime @default(now())
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
productId Int
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
modelId Int
model Model @relation(fields: [modelId], references: [id])
} }
model Model { model Model {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
modelName String modelName String
description String? description String?
version String? version String?
accuracy Float
macroF1 Float
f1Negative Float
f1Neutral Float
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
analyses Analysis[] accuracy Float
reviews Review[] macroF1 Float
} f1Negative Float
f1Neutral Float
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
analyses Analysis[]
reviews Review[]
}

View File

@ -12,7 +12,6 @@ export const getAnotherUserData = async () => {
where: { email: session.user.email }, where: { email: session.user.email },
select: { select: {
gender: true, gender: true,
productReference: true,
}, },
}); });