diff --git a/backend/typescript/prisma/migrations/20240526175138_create_payments_table/migration.sql b/backend/typescript/prisma/migrations/20240526175138_create_payments_table/migration.sql new file mode 100644 index 0000000..8c9acd3 --- /dev/null +++ b/backend/typescript/prisma/migrations/20240526175138_create_payments_table/migration.sql @@ -0,0 +1,19 @@ +-- CreateEnum +CREATE TYPE "PaymentStatus" AS ENUM ('PAID', 'PROCESSING', 'UNPAID', 'DENIED'); + +-- CreateTable +CREATE TABLE "Payment" ( + "id" SERIAL NOT NULL, + "stripePaymentId" TEXT NOT NULL, + "creationDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updateDate" TIMESTAMP(3) NOT NULL, + "donation_id" INTEGER NOT NULL, + "amount" INTEGER NOT NULL, + "currency" TEXT NOT NULL, + "status" "PaymentStatus" NOT NULL, + + CONSTRAINT "Payment_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Payment_stripePaymentId_key" ON "Payment"("stripePaymentId"); diff --git a/backend/typescript/prisma/migrations/20240611002441_/migration.sql b/backend/typescript/prisma/migrations/20240611002441_/migration.sql new file mode 100644 index 0000000..53070a7 --- /dev/null +++ b/backend/typescript/prisma/migrations/20240611002441_/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - You are about to drop the column `donation_id` on the `Payment` table. All the data in the column will be lost. + - A unique constraint covering the columns `[payment_id]` on the table `Donation` will be added. If there are existing duplicate values, this will fail. + +*/ +-- AlterTable +ALTER TABLE "Donation" ADD COLUMN "payment_id" INTEGER; + +-- AlterTable +ALTER TABLE "Payment" DROP COLUMN "donation_id", +ALTER COLUMN "amount" SET DATA TYPE DOUBLE PRECISION; + +-- CreateIndex +CREATE UNIQUE INDEX "Donation_payment_id_key" ON "Donation"("payment_id"); diff --git a/backend/typescript/prisma/schema.prisma b/backend/typescript/prisma/schema.prisma index a9944ce..b5bcd6b 100644 --- a/backend/typescript/prisma/schema.prisma +++ b/backend/typescript/prisma/schema.prisma @@ -23,7 +23,7 @@ model User { donations Donation[] } -enum RoleType{ +enum RoleType { Admin User } @@ -39,6 +39,8 @@ model Donation { cause_id Int is_recurring Recurrence confirmation_email_sent Boolean + transactions Payment? @relation(fields: [payment_id], references: [id]) + payment_id Int? @unique } enum Recurrence { @@ -75,3 +77,21 @@ model Item { npo NPO? @relation("NPOItem") npo_id Int? @unique } + +model Payment { + id Int @id @default(autoincrement()) + stripePaymentId String @unique + creationDate DateTime @default(now()) + updateDate DateTime @updatedAt + donation Donation? + amount Float + currency String + status PaymentStatus +} + +enum PaymentStatus { + PAID + PROCESSING + UNPAID + DENIED +} \ No newline at end of file