aboutsummaryrefslogtreecommitdiffstats
path: root/prisma
diff options
context:
space:
mode:
authorSebastien Castiel <sebastien@castiel.me>2023-12-05 17:39:05 -0500
committerSebastien Castiel <sebastien@castiel.me>2023-12-05 17:39:05 -0500
commited55c696cd083bfaa5429082a9c5edd4ebde0cd8 (patch)
tree9f387881f85716bcb4a05d6fce13bfe59fbc9c17 /prisma
parent1fd6e48807d455f66d9cd79db64cbf9e9f947c6c (diff)
First version
Diffstat (limited to 'prisma')
-rw-r--r--prisma/migrations/20231205211834_create_models/migration.sql46
-rw-r--r--prisma/migrations/20231205214145_add_group_to_expenses/migration.sql11
-rw-r--r--prisma/migrations/20231205214538_change_amount_type/migration.sql8
-rw-r--r--prisma/migrations/migration_lock.toml3
-rw-r--r--prisma/schema.prisma48
5 files changed, 116 insertions, 0 deletions
diff --git a/prisma/migrations/20231205211834_create_models/migration.sql b/prisma/migrations/20231205211834_create_models/migration.sql
new file mode 100644
index 0000000..babd781
--- /dev/null
+++ b/prisma/migrations/20231205211834_create_models/migration.sql
@@ -0,0 +1,46 @@
+-- CreateTable
+CREATE TABLE "Group" (
+ "id" TEXT NOT NULL,
+ "name" TEXT NOT NULL,
+
+ CONSTRAINT "Group_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "Participant" (
+ "id" TEXT NOT NULL,
+ "name" TEXT NOT NULL,
+ "groupId" TEXT NOT NULL,
+
+ CONSTRAINT "Participant_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "Expense" (
+ "id" TEXT NOT NULL,
+ "title" TEXT NOT NULL,
+ "amount" DECIMAL(65,30) NOT NULL,
+ "paidById" TEXT NOT NULL,
+
+ CONSTRAINT "Expense_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "ExpensePaidFor" (
+ "expenseId" TEXT NOT NULL,
+ "participantId" TEXT NOT NULL,
+
+ CONSTRAINT "ExpensePaidFor_pkey" PRIMARY KEY ("expenseId","participantId")
+);
+
+-- AddForeignKey
+ALTER TABLE "Participant" ADD CONSTRAINT "Participant_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "Group"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Expense" ADD CONSTRAINT "Expense_paidById_fkey" FOREIGN KEY ("paidById") REFERENCES "Participant"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ExpensePaidFor" ADD CONSTRAINT "ExpensePaidFor_expenseId_fkey" FOREIGN KEY ("expenseId") REFERENCES "Expense"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ExpensePaidFor" ADD CONSTRAINT "ExpensePaidFor_participantId_fkey" FOREIGN KEY ("participantId") REFERENCES "Participant"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
diff --git a/prisma/migrations/20231205214145_add_group_to_expenses/migration.sql b/prisma/migrations/20231205214145_add_group_to_expenses/migration.sql
new file mode 100644
index 0000000..aa012dd
--- /dev/null
+++ b/prisma/migrations/20231205214145_add_group_to_expenses/migration.sql
@@ -0,0 +1,11 @@
+/*
+ Warnings:
+
+ - Added the required column `groupId` to the `Expense` table without a default value. This is not possible if the table is not empty.
+
+*/
+-- AlterTable
+ALTER TABLE "Expense" ADD COLUMN "groupId" TEXT NOT NULL;
+
+-- AddForeignKey
+ALTER TABLE "Expense" ADD CONSTRAINT "Expense_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "Group"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
diff --git a/prisma/migrations/20231205214538_change_amount_type/migration.sql b/prisma/migrations/20231205214538_change_amount_type/migration.sql
new file mode 100644
index 0000000..d2978b8
--- /dev/null
+++ b/prisma/migrations/20231205214538_change_amount_type/migration.sql
@@ -0,0 +1,8 @@
+/*
+ Warnings:
+
+ - You are about to alter the column `amount` on the `Expense` 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 "Expense" ALTER COLUMN "amount" SET DATA TYPE INTEGER;
diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml
new file mode 100644
index 0000000..fbffa92
--- /dev/null
+++ b/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/prisma/schema.prisma b/prisma/schema.prisma
new file mode 100644
index 0000000..73c3ad1
--- /dev/null
+++ b/prisma/schema.prisma
@@ -0,0 +1,48 @@
+// This is your Prisma schema file,
+// learn more about it in the docs: https://pris.ly/d/prisma-schema
+
+generator client {
+ provider = "prisma-client-js"
+}
+
+datasource db {
+ provider = "postgresql"
+ url = env("POSTGRES_PRISMA_URL") // uses connection pooling
+ directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
+}
+
+model Group {
+ id String @id
+ name String
+ participants Participant[]
+ expenses Expense[]
+}
+
+model Participant {
+ id String @id
+ name String
+ group Group @relation(fields: [groupId], references: [id])
+ groupId String
+ expensesPaidBy Expense[]
+ expensesPaidFor ExpensePaidFor[]
+}
+
+model Expense {
+ id String @id
+ group Group @relation(fields: [groupId], references: [id])
+ title String
+ amount Int
+ paidBy Participant @relation(fields: [paidById], references: [id])
+ paidById String
+ paidFor ExpensePaidFor[]
+ groupId String
+}
+
+model ExpensePaidFor {
+ expense Expense @relation(fields: [expenseId], references: [id])
+ participant Participant @relation(fields: [participantId], references: [id])
+ expenseId String
+ participantId String
+
+ @@id([expenseId, participantId])
+}