testing all features

This commit is contained in:
Kevsl
2024-06-06 16:31:31 +02:00
commit 9f5c23c7c9
74 changed files with 18541 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
"firstName" TEXT NOT NULL,
"lastName" TEXT NOT NULL,
"pseudo" TEXT NOT NULL,
"hash" TEXT NOT NULL,
"email" TEXT NOT NULL,
"roleId" TEXT NOT NULL,
"isActive" BOOLEAN NOT NULL,
"city" TEXT NOT NULL,
"dollarAvailables" DOUBLE PRECISION NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Crypto" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"value" DOUBLE PRECISION NOT NULL,
"image" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Crypto_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "UserHasCrypto" (
"id_user" TEXT NOT NULL,
"id_crypto" TEXT NOT NULL,
"amount" DOUBLE PRECISION NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "UserHasCrypto_pkey" PRIMARY KEY ("id_user","id_crypto")
);
-- CreateTable
CREATE TABLE "Trade" (
"id" TEXT NOT NULL,
"id_giver" TEXT NOT NULL,
"id_receiver" TEXT NOT NULL,
"id_crypto" TEXT NOT NULL,
"value_while_trade" DOUBLE PRECISION NOT NULL,
"amount_traded" DOUBLE PRECISION NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Trade_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Role" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
CONSTRAINT "Role_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "PromoCode" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
CONSTRAINT "PromoCode_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "Role"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "UserHasCrypto" ADD CONSTRAINT "UserHasCrypto_id_user_fkey" FOREIGN KEY ("id_user") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "UserHasCrypto" ADD CONSTRAINT "UserHasCrypto_id_crypto_fkey" FOREIGN KEY ("id_crypto") REFERENCES "Crypto"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Trade" ADD CONSTRAINT "Trade_id_giver_fkey" FOREIGN KEY ("id_giver") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Trade" ADD CONSTRAINT "Trade_id_receiver_fkey" FOREIGN KEY ("id_receiver") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Trade" ADD CONSTRAINT "Trade_id_crypto_fkey" FOREIGN KEY ("id_crypto") REFERENCES "Crypto"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `value` to the `PromoCode` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "PromoCode" ADD COLUMN "value" INTEGER NOT NULL;

View File

@@ -0,0 +1,26 @@
/*
Warnings:
- You are about to alter the column `value` on the `Crypto` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
- You are about to alter the column `value_while_trade` on the `Trade` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
- You are about to alter the column `amount_traded` on the `Trade` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
- You are about to alter the column `dollarAvailables` on the `User` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
- You are about to alter the column `amount` on the `UserHasCrypto` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
- A unique constraint covering the columns `[email]` on the table `User` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "Crypto" ALTER COLUMN "value" SET DATA TYPE DECIMAL(65,30);
-- AlterTable
ALTER TABLE "Trade" ALTER COLUMN "value_while_trade" SET DATA TYPE DECIMAL(65,30),
ALTER COLUMN "amount_traded" SET DATA TYPE DECIMAL(65,30);
-- AlterTable
ALTER TABLE "User" ALTER COLUMN "dollarAvailables" SET DATA TYPE DECIMAL(65,30);
-- AlterTable
ALTER TABLE "UserHasCrypto" ALTER COLUMN "amount" SET DATA TYPE DECIMAL(65,30);
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

View File

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

View File

@@ -0,0 +1,16 @@
/*
Warnings:
- You are about to alter the column `value` on the `Crypto` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Integer`.
- You are about to alter the column `amount_traded` on the `Trade` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Integer`.
- You are about to alter the column `amount` on the `UserHasCrypto` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Integer`.
*/
-- AlterTable
ALTER TABLE "Crypto" ALTER COLUMN "value" SET DATA TYPE INTEGER;
-- AlterTable
ALTER TABLE "Trade" ALTER COLUMN "amount_traded" SET DATA TYPE INTEGER;
-- AlterTable
ALTER TABLE "UserHasCrypto" ALTER COLUMN "amount" SET DATA TYPE INTEGER;

View File

@@ -0,0 +1,11 @@
/*
Warnings:
- The primary key for the `UserHasCrypto` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The required column `id` was added to the `UserHasCrypto` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.
*/
-- AlterTable
ALTER TABLE "UserHasCrypto" DROP CONSTRAINT "UserHasCrypto_pkey",
ADD COLUMN "id" TEXT NOT NULL,
ADD CONSTRAINT "UserHasCrypto_pkey" PRIMARY KEY ("id");

View File

@@ -0,0 +1,8 @@
/*
Warnings:
- You are about to alter the column `dollarAvailables` on the `User` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `DoublePrecision`.
*/
-- AlterTable
ALTER TABLE "User" ALTER COLUMN "dollarAvailables" SET DATA TYPE DOUBLE PRECISION;

View File

@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Crypto" ALTER COLUMN "value" SET DATA TYPE DOUBLE PRECISION;
-- AlterTable
ALTER TABLE "Trade" ALTER COLUMN "amount_traded" SET DATA TYPE DOUBLE PRECISION;

View File

@@ -0,0 +1,47 @@
/*
Warnings:
- Added the required column `id_offer` to the `Trade` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Crypto" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "PromoCode" ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "Role" ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "Trade" ADD COLUMN "id_offer" TEXT NOT NULL,
ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "User" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "UserHasCrypto" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP;
-- CreateTable
CREATE TABLE "Offer" (
"id" TEXT NOT NULL,
"id_crypto" TEXT NOT NULL,
"id_user" TEXT NOT NULL,
"amount" DOUBLE PRECISION NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Offer_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "Offer" ADD CONSTRAINT "Offer_id_crypto_fkey" FOREIGN KEY ("id_crypto") REFERENCES "Crypto"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Offer" ADD CONSTRAINT "Offer_id_user_fkey" FOREIGN KEY ("id_user") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Trade" ADD CONSTRAINT "Trade_id_offer_fkey" FOREIGN KEY ("id_offer") REFERENCES "Offer"("id") ON DELETE RESTRICT 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"

110
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,110 @@
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Crypto {
id String @id @default(uuid())
name String
value Float
image String
created_at DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
UserHasCrypto UserHasCrypto[]
Trade Trade[]
Offer Offer[]
}
model Offer {
id String @id @default(uuid())
id_crypto String
id_user String
amount Float
created_at DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
Crypto Crypto @relation(fields: [id_crypto], references: [id])
User User @relation(fields: [id_user], references: [id])
Trade Trade[]
}
model PromoCode {
id String @id @default(uuid())
name String
value Int
created_at DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
}
model Role {
id String @id @default(uuid())
name String
created_at DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
User User[]
}
model Trade {
id String @id @default(uuid())
id_giver String
id_receiver String
id_crypto String
amount_traded Float
id_offer String
created_at DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
Offer Offer @relation(fields: [id_offer], references: [id])
Giver User @relation("Giver", fields: [id_giver], references: [id])
Receiver User @relation("Receiver", fields: [id_receiver], references: [id])
Crypto Crypto @relation(fields: [id_crypto], references: [id])
}
model User {
id String @id @default(uuid())
firstName String
lastName String
pseudo String
hash String
email String @unique
roleId String
isActive Boolean
city String
dollarAvailables Float
created_at DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
Role Role @relation(fields: [roleId], references: [id])
UserHasCrypto UserHasCrypto[]
TradeGiven Trade[] @relation("Giver")
TradeReceived Trade[] @relation("Receiver")
Offer Offer[]
}
model UserHasCrypto {
id String @id @default(uuid())
id_user String
id_crypto String
amount Int
createdAt DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
User User @relation(fields: [id_user], references: [id])
Crypto Crypto @relation(fields: [id_crypto], references: [id])
}