chore: add all the code from original repo

This commit is contained in:
Riccardo
2024-05-23 16:55:29 +02:00
parent d8f9a215eb
commit 85d66215a7
66 changed files with 16668 additions and 122 deletions

View File

@@ -0,0 +1,101 @@
-- CreateEnum
CREATE TYPE "Currency" AS ENUM ('EUR', 'DKK', 'SGD', 'USD');
-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
"email" TEXT NOT NULL,
"name" TEXT,
"password" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Profile" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"userId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Profile_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Item" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"price" DOUBLE PRECISION NOT NULL,
"currency" "Currency" NOT NULL,
"deleted" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"profileId" TEXT NOT NULL,
"tagId" TEXT,
CONSTRAINT "Item_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "ItemComment" (
"id" TEXT NOT NULL,
"body" TEXT NOT NULL,
"score" INTEGER NOT NULL,
"regret" BOOLEAN NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"itemId" TEXT NOT NULL,
CONSTRAINT "ItemComment_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Tag" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Tag_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "User_id_key" ON "User"("id");
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
-- CreateIndex
CREATE UNIQUE INDEX "Profile_id_key" ON "Profile"("id");
-- CreateIndex
CREATE UNIQUE INDEX "Profile_userId_key" ON "Profile"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "Item_id_key" ON "Item"("id");
-- CreateIndex
CREATE UNIQUE INDEX "ItemComment_id_key" ON "ItemComment"("id");
-- CreateIndex
CREATE UNIQUE INDEX "Tag_id_key" ON "Tag"("id");
-- CreateIndex
CREATE UNIQUE INDEX "Tag_name_key" ON "Tag"("name");
-- AddForeignKey
ALTER TABLE "Profile" ADD CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Item" ADD CONSTRAINT "Item_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Item" ADD CONSTRAINT "Item_tagId_fkey" FOREIGN KEY ("tagId") REFERENCES "Tag"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ItemComment" ADD CONSTRAINT "ItemComment_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "Item"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -0,0 +1,15 @@
-- AlterTable
ALTER TABLE "Item" ADD COLUMN "priceEuro" DOUBLE PRECISION;
-- CreateTable
CREATE TABLE "CurrencyRate" (
"id" TEXT NOT NULL,
"currency" "Currency" NOT NULL,
"rate" DOUBLE PRECISION NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "CurrencyRate_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "CurrencyRate_id_key" ON "CurrencyRate"("id");

View File

@@ -0,0 +1,15 @@
/*
Warnings:
- You are about to drop the column `updatedAt` on the `Item` table. All the data in the column will be lost.
- You are about to drop the column `updatedAt` on the `ItemComment` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Item" DROP COLUMN "updatedAt";
-- AlterTable
ALTER TABLE "ItemComment" DROP COLUMN "updatedAt",
ALTER COLUMN "body" DROP NOT NULL,
ALTER COLUMN "score" DROP NOT NULL,
ALTER COLUMN "regret" SET DEFAULT false;

View File

@@ -0,0 +1,11 @@
/*
Warnings:
- Added the required column `profileId` to the `Tag` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Tag" ADD COLUMN "profileId" TEXT NOT NULL;
-- AddForeignKey
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -0,0 +1,2 @@
-- DropIndex
DROP INDEX "Profile_userId_key";

View File

@@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[name]` on the table `Profile` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "Profile_name_key" ON "Profile"("name");

View File

@@ -0,0 +1,23 @@
-- DropForeignKey
ALTER TABLE "Item" DROP CONSTRAINT "Item_profileId_fkey";
-- DropForeignKey
ALTER TABLE "ItemComment" DROP CONSTRAINT "ItemComment_itemId_fkey";
-- DropForeignKey
ALTER TABLE "Profile" DROP CONSTRAINT "Profile_userId_fkey";
-- DropForeignKey
ALTER TABLE "Tag" DROP CONSTRAINT "Tag_profileId_fkey";
-- AddForeignKey
ALTER TABLE "Profile" ADD CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Item" ADD CONSTRAINT "Item_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ItemComment" ADD CONSTRAINT "ItemComment_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "Item"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"

9
prisma/prisma.ts Normal file
View File

@@ -0,0 +1,9 @@
import { PrismaClient } from '@prisma/client';
const globalForPrisma = global as unknown as { prisma: PrismaClient };
export const prisma = globalForPrisma.prisma || new PrismaClient();
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
export default prisma;

80
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,80 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum Currency {
EUR
DKK
SGD
USD
}
model User {
id String @id @unique @default(uuid())
email String @unique
name String?
password String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Profiles Profile[]
}
model Profile {
id String @id @unique @default(uuid())
name String @unique
description String?
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Items Item[]
Tag Tag[]
}
model Item {
id String @id @unique @default(uuid())
name String
description String?
price Float
currency Currency
priceEuro Float?
deleted Boolean @default(false)
createdAt DateTime @default(now())
Profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
profileId String
ItemComment ItemComment[]
Tag Tag? @relation(fields: [tagId], references: [id])
tagId String?
}
model ItemComment {
id String @id @unique @default(uuid())
body String?
score Int?
regret Boolean @default(false)
createdAt DateTime @default(now())
Item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
itemId String
}
model Tag {
id String @id @unique @default(uuid())
name String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
profileId String
Items Item[]
}
model CurrencyRate {
id String @id @unique @default(uuid())
currency Currency
rate Float
createdAt DateTime @default(now())
}