Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix/migrate to prisma #31

Merged
merged 14 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ MYSQL_DATABASE=
SERVER_PORT=
DB_DATABASE=
TOKEN_SECRET=
EMAIL=
EMAIL_PASSWORD=
2 changes: 2 additions & 0 deletions db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ CREATE TABLE IF NOT EXISTS users (
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
refresh_token VARCHAR(1000),
email_verified BOOLEAN DEFAULT FALSE,
verification_token CHAR(6),

UNIQUE(email)
);
Expand Down
111 changes: 111 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"@prisma/client": "^5.20.0",
"bcrypt": "^5.1.1",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
Expand All @@ -28,6 +29,7 @@
"jsonwebtoken": "^9.0.2",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.11.2",
"nodemailer": "^6.9.15",
"xss-filters": "^1.2.7",
"zod": "^3.23.8"
},
Expand All @@ -41,10 +43,12 @@
"@types/jsonwebtoken": "^9.0.6",
"@types/multer": "^1.4.12",
"@types/node": "^22.5.4",
"@types/nodemailer": "^6.4.16",
"@types/xss-filters": "^0.0.30",
"husky": "^9.1.5",
"jest": "^29.7.0",
"lint-staged": "^15.2.10",
"prisma": "^5.20.0",
"ts-jest": "^29.2.5",
"ts-node-dev": "^2.0.0",
"typescript": "^5.6.2"
Expand Down
45 changes: 45 additions & 0 deletions prisma/migrations/20241016022512_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- CreateEnum
CREATE TYPE "crdb_internal_region" AS ENUM ('gcp-asia-southeast1');

-- CreateTable
CREATE TABLE "products" (
"id" BIGSERIAL NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT NOT NULL,
"price" DOUBLE PRECISION NOT NULL,
"images" JSONB,

CONSTRAINT "products_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ratings" (
"id_user" BIGINT NOT NULL,
"id_product" BIGINT NOT NULL,
"star" INTEGER NOT NULL,
"message" TEXT NOT NULL,

CONSTRAINT "ratings_pkey" PRIMARY KEY ("id_user","id_product")
);

-- CreateTable
CREATE TABLE "users" (
"id" BIGSERIAL NOT NULL,
"fullname" TEXT NOT NULL,
"email" TEXT NOT NULL,
"password" TEXT NOT NULL,
"refresh_token" TEXT,
"email_verified" BOOLEAN DEFAULT false,
"verification_token" CHAR(6),

CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");

-- AddForeignKey
ALTER TABLE "ratings" ADD CONSTRAINT "ratings_id_product_fkey" FOREIGN KEY ("id_product") REFERENCES "products"("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "ratings" ADD CONSTRAINT "ratings_id_user_fkey" FOREIGN KEY ("id_user") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -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"
44 changes: 44 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}

model products {
id BigInt @id @default(autoincrement())
name String
description String
price Float
images Json?
ratings ratings[]
}

model ratings {
id_user BigInt
id_product BigInt
star Int
message String
products products @relation(fields: [id_product], references: [id], onDelete: NoAction, onUpdate: NoAction)
users users @relation(fields: [id_user], references: [id], onDelete: NoAction, onUpdate: NoAction)

@@id([id_user, id_product])
}

model users {
id BigInt @id @default(autoincrement())
fullname String
email String @unique
password String
refresh_token String?
email_verified Boolean? @default(false)
verification_token String? @db.Char(6)
ratings ratings[]
}

enum crdb_internal_region {
gcp_asia_southeast1 @map("gcp-asia-southeast1")
}
Loading