From 23f50d717fc1b4fbaa9ff7372682db5f354ca921 Mon Sep 17 00:00:00 2001 From: William Tran Date: Fri, 3 Nov 2023 23:55:30 -0400 Subject: [PATCH 1/2] feat: add neon db --- README.md | 6 +++ backend/typescript/prisma/schema.prisma | 49 +++++++++++++------------ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 53640253..3159cdee 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ docker-compose up --build The backend runs at http://localhost:5000 and the frontend runs at http://localhost:3000. By default, we use GraphQL (with TypeScript backend), REST (with Python backend), MongoDB, with user auth. ### Note: Manual Database Setup + If for some reason docker container is not syncing with your prisma models in backend/typescript/prisma/schema Update .env file in /backend/typescript to be @@ -91,6 +92,11 @@ nvm install 18.16.0 nvm use 18.16.0 ``` +## Creating Prisma Migration + +Go to `backend/typescript` and run + +npx prisma migrate dev ## Useful Commands diff --git a/backend/typescript/prisma/schema.prisma b/backend/typescript/prisma/schema.prisma index abfb9d6b..106d0c65 100644 --- a/backend/typescript/prisma/schema.prisma +++ b/backend/typescript/prisma/schema.prisma @@ -3,19 +3,20 @@ generator client { } datasource db { - provider = "postgresql" - url = env("DATABASE_URL") + provider = "postgresql" + url = env("DATABASE_URL") + directUrl = env("DIRECT_URL") } model post { - id Int @id @default(autoincrement()) - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - title String @db.VarChar(255) - content String? - published Boolean @default(false) - author_id Int - author user @relation(fields: [author_id], references: [id]) + id Int @id @default(autoincrement()) + created_at DateTime @default(now()) + updated_at DateTime @updatedAt + title String @db.VarChar(255) + content String? + published Boolean @default(false) + author_id Int + author user @relation(fields: [author_id], references: [id]) } model profile { @@ -106,10 +107,10 @@ model role { } model resident { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) first_name String last_name String - email String @unique + email String @unique phone_number String? display_name String profile_picture_link String? @@ -123,18 +124,20 @@ model resident { } model notification { - id Int @id @default(autoincrement()) - message String - author_id Int - author staff @relation(fields: [author_id], references: [id]) - created_at DateTime @default(now()) - residents notification_user[] + id Int @id @default(autoincrement()) + message String + author_id Int + author staff @relation(fields: [author_id], references: [id]) + created_at DateTime @default(now()) + residents notification_user[] } model notification_user { - notification notification @relation(fields: [notification_id], references: [id]) - notification_id Int - recipient resident @relation(fields: [recipient_id], references: [id]) - recipient_id Int - seen Boolean @default(false) + notification notification @relation(fields: [notification_id], references: [id]) + notification_id Int + recipient resident @relation(fields: [recipient_id], references: [id]) + recipient_id Int + seen Boolean @default(false) + + @@id([notification_id, recipient_id]) } From 29c05a45e2df424bd4961afd2364244e63653269 Mon Sep 17 00:00:00 2001 From: William Tran Date: Wed, 8 Nov 2023 21:25:49 -0500 Subject: [PATCH 2/2] fix: add optional neon setup --- backend/typescript/prisma/schema.prisma | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/typescript/prisma/schema.prisma b/backend/typescript/prisma/schema.prisma index 106d0c65..ca135c89 100644 --- a/backend/typescript/prisma/schema.prisma +++ b/backend/typescript/prisma/schema.prisma @@ -3,9 +3,10 @@ generator client { } datasource db { - provider = "postgresql" - url = env("DATABASE_URL") - directUrl = env("DIRECT_URL") + provider = "postgresql" + url = env("DATABASE_URL") + // uncomment this for neon db + // directUrl = env("DIRECT_URL") } model post {