From 3dd588f7ca28007fefc0906d69714837c716e5ec Mon Sep 17 00:00:00 2001 From: Shushawn Saha <84819112+ShushawnS@users.noreply.github.com> Date: Tue, 5 Mar 2024 20:54:59 -0500 Subject: [PATCH] Completed Inital Prisma Migration (#10) * completed prisma migration * add some commands --------- Co-authored-by: Jessica --- README.md | 6 +- backend/typescript/package.json | 4 +- .../20240225001117_feb25/migration.sql | 83 +++++++++++++++++++ .../prisma/migrations/migration_lock.toml | 3 + backend/typescript/yarn.lock | 48 +++++++++++ 5 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 backend/typescript/prisma/migrations/20240225001117_feb25/migration.sql create mode 100644 backend/typescript/prisma/migrations/migration_lock.toml diff --git a/README.md b/README.md index 10397bf..039b6a2 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# don-efficace \ No newline at end of file +# don-efficace + +# Useful commands to run prisma +"npx prisma db push" to push +"npx prisma studio" to run prisma diff --git a/backend/typescript/package.json b/backend/typescript/package.json index fc508c9..d6ff379 100644 --- a/backend/typescript/package.json +++ b/backend/typescript/package.json @@ -13,7 +13,7 @@ "author": "", "license": "ISC", "dependencies": { - "@prisma/client": "4.15.0", + "@prisma/client": "^5.10.2", "@types/graphql-upload": "^8.0.6", "@types/json2csv": "^5.0.3", "@types/multer": "^1.4.6", @@ -72,7 +72,7 @@ "mongodb-memory-server": "^6.9.6", "nodemon": "^2.0.7", "prettier": "^2.2.1", - "prisma": "^4.15.0", + "prisma": "^5.10.2", "ts-jest": "^27.0.3", "typescript": "^4.1.5" }, diff --git a/backend/typescript/prisma/migrations/20240225001117_feb25/migration.sql b/backend/typescript/prisma/migrations/20240225001117_feb25/migration.sql new file mode 100644 index 0000000..82c303a --- /dev/null +++ b/backend/typescript/prisma/migrations/20240225001117_feb25/migration.sql @@ -0,0 +1,83 @@ +-- CreateEnum +CREATE TYPE "CauseEnum" AS ENUM ('ENVIRONMENT', 'EDUCATION', 'HEALTH'); + +-- CreateTable +CREATE TABLE "User" ( + "id" SERIAL NOT NULL, + "first_name" TEXT NOT NULL, + "last_name" TEXT NOT NULL, + "full_addr" TEXT NOT NULL, + "email_addr" TEXT NOT NULL, + "opt_in" BOOLEAN NOT NULL, + "date_created" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "is_admin" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Donation" ( + "id" SERIAL NOT NULL, + "user_id" INTEGER NOT NULL, + "amount" DOUBLE PRECISION NOT NULL, + "donation_date" TIMESTAMP(3) NOT NULL, + "is_recurring" BOOLEAN NOT NULL, + "confirmation_email_sent" BOOLEAN NOT NULL, + + CONSTRAINT "Donation_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "CauseDonation" ( + "donation_id" INTEGER NOT NULL, + "cause_id" INTEGER NOT NULL, + + CONSTRAINT "CauseDonation_pkey" PRIMARY KEY ("donation_id","cause_id") +); + +-- CreateTable +CREATE TABLE "Cause" ( + "id" SERIAL NOT NULL, + "name" "CauseEnum" NOT NULL, + "description" TEXT NOT NULL, + + CONSTRAINT "Cause_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "NPO" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "contact_information" TEXT NOT NULL, + "cause_id" INTEGER NOT NULL, + "item_id" INTEGER, + + CONSTRAINT "NPO_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Item" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "impact_ratio" DOUBLE PRECISION NOT NULL, + + CONSTRAINT "Item_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_addr_key" ON "User"("email_addr"); + +-- AddForeignKey +ALTER TABLE "Donation" ADD CONSTRAINT "Donation_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "CauseDonation" ADD CONSTRAINT "CauseDonation_donation_id_fkey" FOREIGN KEY ("donation_id") REFERENCES "Donation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "CauseDonation" ADD CONSTRAINT "CauseDonation_cause_id_fkey" FOREIGN KEY ("cause_id") REFERENCES "Cause"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "NPO" ADD CONSTRAINT "NPO_cause_id_fkey" FOREIGN KEY ("cause_id") REFERENCES "Cause"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "NPO" ADD CONSTRAINT "NPO_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "Item"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/backend/typescript/prisma/migrations/migration_lock.toml b/backend/typescript/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..fbffa92 --- /dev/null +++ b/backend/typescript/prisma/migrations/migration_lock.toml @@ -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" \ No newline at end of file diff --git a/backend/typescript/yarn.lock b/backend/typescript/yarn.lock index f8d4985..3c784c8 100644 --- a/backend/typescript/yarn.lock +++ b/backend/typescript/yarn.lock @@ -800,6 +800,47 @@ "@nodelib/fs.scandir" "2.1.4" fastq "^1.6.0" +"@prisma/client@^5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.10.2.tgz#e087b40a4de8e3171eb9cbf0a873465cd2068e17" + integrity sha512-ef49hzB2yJZCvM5gFHMxSFL9KYrIP9udpT5rYo0CsHD4P9IKj473MbhU1gjKKftiwWBTIyrt9jukprzZXazyag== + +"@prisma/debug@5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.10.2.tgz#74be81d8969978f4d53c1b4e76d61f04bfbc3951" + integrity sha512-bkBOmH9dpEBbMKFJj8V+Zp8IZHIBjy3fSyhLhxj4FmKGb/UBSt9doyfA6k1UeUREsMJft7xgPYBbHSOYBr8XCA== + +"@prisma/engines-version@5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9": + version "5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9" + resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9.tgz#1502335d4d72d2014cb25b8ad8a740a3a13400ea" + integrity sha512-uCy/++3Jx/O3ufM+qv2H1L4tOemTNqcP/gyEVOlZqTpBvYJUe0tWtW0y3o2Ueq04mll4aM5X3f6ugQftOSLdFQ== + +"@prisma/engines@5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.10.2.tgz#a4851d90f76ad6d22e783d5fd2e2e8c0640f1e81" + integrity sha512-HkSJvix6PW8YqEEt3zHfCYYJY69CXsNdhU+wna+4Y7EZ+AwzeupMnUThmvaDA7uqswiHkgm5/SZ6/4CStjaGmw== + dependencies: + "@prisma/debug" "5.10.2" + "@prisma/engines-version" "5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9" + "@prisma/fetch-engine" "5.10.2" + "@prisma/get-platform" "5.10.2" + +"@prisma/fetch-engine@5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.10.2.tgz#a061f6727d395c7033b55f9c6e92f8741a70d5c5" + integrity sha512-dSmXcqSt6DpTmMaLQ9K8ZKzVAMH3qwGCmYEZr/uVnzVhxRJ1EbT/w2MMwIdBNq1zT69Rvh0h75WMIi0mrIw7Hg== + dependencies: + "@prisma/debug" "5.10.2" + "@prisma/engines-version" "5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9" + "@prisma/get-platform" "5.10.2" + +"@prisma/get-platform@5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.10.2.tgz#7af97b1d82e5574a474e3fbf6eaf04f4156bc535" + integrity sha512-nqXP6vHiY2PIsebBAuDeWiUYg8h8mfjBckHh6Jezuwej0QJNnjDiOq30uesmg+JXxGk99nqyG3B7wpcOODzXvg== + dependencies: + "@prisma/debug" "5.10.2" + "@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf" @@ -5600,6 +5641,13 @@ pretty-format@^27.0.6: ansi-styles "^5.0.0" react-is "^17.0.1" +prisma@^5.10.2: + version "5.10.2" + resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.10.2.tgz#aa63085c49dc74cdb5c3816e8dd1fb4d74a2aadd" + integrity sha512-hqb/JMz9/kymRE25pMWCxkdyhbnIWrq+h7S6WysJpdnCvhstbJSNP/S6mScEcqiB8Qv2F+0R3yG+osRaWqZacQ== + dependencies: + "@prisma/engines" "5.10.2" + process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"