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"
}
// --- ENUMS ---
enum UserGender {
male
female
@ -24,6 +23,28 @@ enum Sentiment {
NEUTRAL
}
enum OS {
WINDOWS
MACOS
LINUX
CHROME_OS
OTHER
}
enum Brand {
APPLE
ASUS
ACER
LENOVO
HP
DELL
MSI
AXIOO
ADVAN
ZYREX
OTHER
}
model Account {
id Int @id @default(autoincrement())
userId Int
@ -64,87 +85,105 @@ model User {
email String? @unique
emailVerified DateTime?
image String?
gender UserGender?
password String?
role Role @default(USER)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
bio String? @db.Text
location String?
birthDate DateTime?
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())
updatedAt DateTime @updatedAt
reviews Review[]
analyses Analysis[]
accounts Account[]
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 {
id Int @id @default(autoincrement())
content String
sentiment Sentiment
confidenceScore Float
keywords String[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
content String
sentiment Sentiment
confidenceScore Float
keywords String[]
productId Int
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
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)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
productId Int
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
modelId Int
model Model @relation(fields: [modelId], references: [id])
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
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
modelId Int
model Model @relation(fields: [modelId], references: [id])
}
model Model {
id Int @id @default(autoincrement())
modelName String
id Int @id @default(autoincrement())
modelName String
description String?
version String?
accuracy Float
macroF1 Float
f1Negative Float
f1Neutral Float
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
version String?
analyses Analysis[]
reviews Review[]
}
accuracy Float
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 },
select: {
gender: true,
productReference: true,
},
});