From 9728eb9cf323a5186efb54f06e70140f7e67220c Mon Sep 17 00:00:00 2001 From: AmrMohamed27 Date: Mon, 12 Feb 2024 21:18:54 +0200 Subject: [PATCH 1/7] Added doc file and ERD diagram image --- docs/prisma-erd.svg | 2 + docs/schema.md | 226 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100644 docs/prisma-erd.svg create mode 100644 docs/schema.md diff --git a/docs/prisma-erd.svg b/docs/prisma-erd.svg new file mode 100644 index 0000000..eb59b41 --- /dev/null +++ b/docs/prisma-erd.svg @@ -0,0 +1,2 @@ + +UserIntidStringemailStringnameStringpasswordUserRoleroleTeamIntidStringnameTeamMembersMemberRoleroleProjectIntidStringnameStringuuidDatabaseStringidStringnameDateTimecreatedAtIntstoragestatusstatusteamuserteamproject \ No newline at end of file diff --git a/docs/schema.md b/docs/schema.md new file mode 100644 index 0000000..91c3ee8 --- /dev/null +++ b/docs/schema.md @@ -0,0 +1,226 @@ +# Prisma Schema Documentation + +## Overview + +This is a a comprehensive overview of the database schema used in the platform, including entities, relationships, enums, diagrams and additional notes for proper usage and maintenance. + +### Technologies Used + +**Database Management System:** PostgreSQL + +- PostgreSQL is scalable open-source relational database management system known for SQL compliance, + advanced concurrency control, extensibility, and strong security. + +**ORM:** Prisma + +- Prisma is a Node.js and Typescript ORM with an intuitive data model, automated migrations, type-safety, + and auto-completion. It defines the main configuration of the data models in a file called `schema.prisma` + +## Schema Description + +### Generator + +Specifies how Prisma generates client code for interacting with the database, such as Prisma Client. + +```prisma +generator client { + provider = "prisma-client-js" +} +``` + +### Data Source + +Defines the database connection details, including the provider (in our case PostgreSQL), and URL, which is stored in an environment variable. + +```prisma +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} +``` + +### Entities + +#### Structure + +The schema consists of the following entities: + +- **User:** Represents users of the system. + + ```prisma + model User { + id Int @id @default(autoincrement()) + email String @unique + name String + password String + role UserRole @default(USER) + teams TeamMembers[] + } + ``` + +- **Team:** Represents teams with members and projects. + + ```prisma + model Team { + id Int @id @default(autoincrement()) + name String + members TeamMembers[] + projects Project[] + } + ``` + +- **TeamMembers:** Represents the relationship between users and teams, including their roles. + + ```prisma + model TeamMembers { + teamId Int + userId Int + team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) + role MemberRole @default(MEMBER) + + @@id([teamId, userId]) + } + ``` + +- **Project:** Represents projects belonging to teams. + + ```prisma + model Project { + id Int @id @default(autoincrement()) + name String + teamId Int + team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) + databases Database[] + uuid String @default(uuid()) + } + ``` + +- **Database:** Represents databases associated with projects. + + ```prisma + model Database { + id String @id @default(uuid()) + name String + createdAt DateTime @default(now()) + storage Int + projectId Int + project Project @relation(fields: [projectId], references: [id], onDelete: Cascade) + status status @default(INACTIVE) + } + ``` + +#### Entity Details + +##### User + +- `id`: Auto-incremented unique identifier for the user. +- `email`: Unique email address of the user. +- `name`: Name of the user +- `password`: Hashed password of the user +- `role`: Role of the user, default: `USER` +- Relationships: + `teams` Many-to-many relationship with Team entity through TeamMembers property + +###### Suggestions + +- implementing a unique constraint on the email column +- Adding an image column for profile pictures of users +- Adding a column to store the user's preferred language and another for his preferred timezone + +##### Team + +- `id` Auto-incremented unique identifier for the team +- `name` Name of the team +- Relationships: + `members` One-to-many relationship with team members + `projects` One-to-many relationship with projects + +###### Suggestions + +- Adding a column to store a description of the team and its goals + +##### TeamMembers + +- `teamId` Foreign key referencing the id column of the Team table, pointing to the team that the member belongs to +- `userId` Foreign key referencing the id column of the User table, pointing to the user that is a member of the team +- `role` Role of the member in the team, default: `MEMBER` +- Relationships: + `team` Many-to-one relationship with teams + `user` Many-to-one relationship with users + +##### Project + +- `id` Auto-incremented unique identifier for the project +- `name` Name of the project +- `teamId` Foreign key referencing the id column of the Team table, pointing to the team that created the project +- `uuid` Unique UUID identifier for the project +- Relationships: + `team` Many-to-one relationship with the team that creates the projects + `databases` One-to-many relationship with databases associated with the project + +###### Suggestions + +- Adding a column to store a description of the project +- Combining the `id` and `uuid` columns in a single column `id` that uses a uuid to identify the project + +##### Database + +- `id` Unique UUID identifier for the database +- `name`Name of the database +- `createdAt` Timestamp indicating the creation time of the database +- `storage` Storage capacity of the database +- `projectId` Foreign key referencing the id column of the Project table, pointing to the project that the database belongs to +- Relationships: + `project` Many-to-one relationship with the project + +### Enums + +#### UserRole + +- `USER`: Regular user + - Regular user with standard access privileges on teams and projects. +- `ADMIN`: Admin user + - User with elevated access rights for system administration of the platform. + +```prisma +enum UserRole { + USER + ADMIN +} +``` + +#### MemberRole + +- `MEMBER`: Regular member + - Regular team member with access to the team's projects +- `LEADER`: Leader member + - The user that created the team and has the privileges to create and delete projects. + +```prisma +enum MemberRole { + LEADER + MEMBER +} +``` + +#### Status + +- `ACTIVE`: Active database + - Database that is online and fully responsive +- `INACTIVE`: Inactive database + - Database that hasn't been used for a while but still responsive +- `SLEEP`: Sleeping database + - Database that was `INACTIVE` for a certain amount of time and entered an offline mode, and it must be activated in order to be responsive for queries + +```prisma +enum status { + ACTIVE + INACTIVE + SLEEP +} +``` + +### ERD Diagram + +![1707762267097](./prisma-erd.svg) From 493aa943f253c6eb71204b006bc8c9bcca9db445 Mon Sep 17 00:00:00 2001 From: AmrMohamed27 Date: Mon, 12 Feb 2024 21:23:19 +0200 Subject: [PATCH 2/7] Fixed relationships not showing as a list --- docs/schema.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/schema.md b/docs/schema.md index 91c3ee8..3e7bb23 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -120,7 +120,7 @@ The schema consists of the following entities: - `password`: Hashed password of the user - `role`: Role of the user, default: `USER` - Relationships: - `teams` Many-to-many relationship with Team entity through TeamMembers property + - `teams` Many-to-many relationship with Team entity through TeamMembers property ###### Suggestions @@ -133,8 +133,8 @@ The schema consists of the following entities: - `id` Auto-incremented unique identifier for the team - `name` Name of the team - Relationships: - `members` One-to-many relationship with team members - `projects` One-to-many relationship with projects + - `members` One-to-many relationship with team members + - `projects` One-to-many relationship with projects ###### Suggestions @@ -146,8 +146,8 @@ The schema consists of the following entities: - `userId` Foreign key referencing the id column of the User table, pointing to the user that is a member of the team - `role` Role of the member in the team, default: `MEMBER` - Relationships: - `team` Many-to-one relationship with teams - `user` Many-to-one relationship with users + - `team` Many-to-one relationship with teams + - `user` Many-to-one relationship with users ##### Project @@ -156,8 +156,8 @@ The schema consists of the following entities: - `teamId` Foreign key referencing the id column of the Team table, pointing to the team that created the project - `uuid` Unique UUID identifier for the project - Relationships: - `team` Many-to-one relationship with the team that creates the projects - `databases` One-to-many relationship with databases associated with the project + - `team` Many-to-one relationship with the team that creates the projects + - `databases` One-to-many relationship with databases associated with the project ###### Suggestions @@ -172,7 +172,7 @@ The schema consists of the following entities: - `storage` Storage capacity of the database - `projectId` Foreign key referencing the id column of the Project table, pointing to the project that the database belongs to - Relationships: - `project` Many-to-one relationship with the project + - `project` Many-to-one relationship with the project ### Enums From 3e841f00849bf2b0be26d8871affc79db2c785aa Mon Sep 17 00:00:00 2001 From: AmrMohamed27 Date: Wed, 14 Feb 2024 16:37:37 +0200 Subject: [PATCH 3/7] Added .vscode folder to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c6bba59..84bf5a6 100644 --- a/.gitignore +++ b/.gitignore @@ -122,6 +122,9 @@ dist # Stores VSCode versions used for testing VSCode extensions .vscode-test +# VSCode +.vscode/ + # yarn v2 .yarn/cache .yarn/unplugged From a0585e0dbebdc967b1557cbe8cea0e5a56c6ab35 Mon Sep 17 00:00:00 2001 From: AmrMohamed27 Date: Wed, 14 Feb 2024 16:38:39 +0200 Subject: [PATCH 4/7] Removed suggestions and moved diagram to top --- docs/schema.md | 123 ++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 69 deletions(-) diff --git a/docs/schema.md b/docs/schema.md index 3e7bb23..e0a1ded 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -16,6 +16,10 @@ This is a a comprehensive overview of the database schema used in the platform, - Prisma is a Node.js and Typescript ORM with an intuitive data model, automated migrations, type-safety, and auto-completion. It defines the main configuration of the data models in a file called `schema.prisma` +### ERD Diagram + +![ERD diagram of the schema](./prisma-erd.svg "ERD Diagram of the schema") + ## Schema Description ### Generator @@ -47,68 +51,68 @@ The schema consists of the following entities: - **User:** Represents users of the system. - ```prisma - model User { - id Int @id @default(autoincrement()) - email String @unique - name String - password String - role UserRole @default(USER) - teams TeamMembers[] - } - ``` +```prisma +model User { + id Int @id @default(autoincrement()) + email String @unique + name String + password String + role UserRole @default(USER) + teams TeamMembers[] +} +``` - **Team:** Represents teams with members and projects. - ```prisma - model Team { - id Int @id @default(autoincrement()) - name String - members TeamMembers[] - projects Project[] - } - ``` +```prisma +model Team { + id Int @id @default(autoincrement()) + name String + members TeamMembers[] + projects Project[] +} +``` - **TeamMembers:** Represents the relationship between users and teams, including their roles. - ```prisma - model TeamMembers { - teamId Int - userId Int - team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) - user User @relation(fields: [userId], references: [id], onDelete: Cascade) - role MemberRole @default(MEMBER) - - @@id([teamId, userId]) - } - ``` +```prisma +model TeamMembers { + teamId Int + userId Int + team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) + role MemberRole @default(MEMBER) + + @@id([teamId, userId]) +} +``` - **Project:** Represents projects belonging to teams. - ```prisma - model Project { - id Int @id @default(autoincrement()) - name String - teamId Int - team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) - databases Database[] - uuid String @default(uuid()) - } - ``` +```prisma +model Project { + id Int @id @default(autoincrement()) + name String + teamId Int + team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) + databases Database[] + uuid String @default(uuid()) +} +``` - **Database:** Represents databases associated with projects. - ```prisma - model Database { - id String @id @default(uuid()) - name String - createdAt DateTime @default(now()) - storage Int - projectId Int - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade) - status status @default(INACTIVE) - } - ``` +```prisma +model Database { + id String @id @default(uuid()) + name String + createdAt DateTime @default(now()) + storage Int + projectId Int + project Project @relation(fields: [projectId], references: [id], onDelete: Cascade) + status status @default(INACTIVE) +} +``` #### Entity Details @@ -122,12 +126,6 @@ The schema consists of the following entities: - Relationships: - `teams` Many-to-many relationship with Team entity through TeamMembers property -###### Suggestions - -- implementing a unique constraint on the email column -- Adding an image column for profile pictures of users -- Adding a column to store the user's preferred language and another for his preferred timezone - ##### Team - `id` Auto-incremented unique identifier for the team @@ -136,10 +134,6 @@ The schema consists of the following entities: - `members` One-to-many relationship with team members - `projects` One-to-many relationship with projects -###### Suggestions - -- Adding a column to store a description of the team and its goals - ##### TeamMembers - `teamId` Foreign key referencing the id column of the Team table, pointing to the team that the member belongs to @@ -159,11 +153,6 @@ The schema consists of the following entities: - `team` Many-to-one relationship with the team that creates the projects - `databases` One-to-many relationship with databases associated with the project -###### Suggestions - -- Adding a column to store a description of the project -- Combining the `id` and `uuid` columns in a single column `id` that uses a uuid to identify the project - ##### Database - `id` Unique UUID identifier for the database @@ -220,7 +209,3 @@ enum status { SLEEP } ``` - -### ERD Diagram - -![1707762267097](./prisma-erd.svg) From 13d3d4dee65041604368c82e7155614f1e9c7b44 Mon Sep 17 00:00:00 2001 From: AmrMohamed27 Date: Thu, 15 Feb 2024 01:15:28 +0200 Subject: [PATCH 5/7] ignoring .gitignore file --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 84bf5a6..0d62657 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ yarn-error.log* lerna-debug.log* .pnpm-debug.log* +# Ignore file +.gitignore + # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json @@ -131,3 +134,4 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* + From 193c62cf021180f092d6d52b2936908e6ce5a103 Mon Sep 17 00:00:00 2001 From: AmrMohamed27 Date: Thu, 15 Feb 2024 01:27:23 +0200 Subject: [PATCH 6/7] Added Prisma Components section --- docs/schema.md | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/schema.md b/docs/schema.md index e0a1ded..a6735cf 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -1,4 +1,4 @@ -# Prisma Schema Documentation +# Schema Documentation ## Overview @@ -16,11 +16,9 @@ This is a a comprehensive overview of the database schema used in the platform, - Prisma is a Node.js and Typescript ORM with an intuitive data model, automated migrations, type-safety, and auto-completion. It defines the main configuration of the data models in a file called `schema.prisma` -### ERD Diagram +## Prisma Components -![ERD diagram of the schema](./prisma-erd.svg "ERD Diagram of the schema") - -## Schema Description +We depend on Prisma as an ORM to connect our application to the database using the following components: ### Generator @@ -43,6 +41,8 @@ datasource db { } ``` +## Schema Description + ### Entities #### Structure @@ -114,9 +114,13 @@ model Database { } ``` -#### Entity Details +### ERD Diagram + +![ERD diagram of the schema](./prisma-erd.svg "ERD Diagram of the schema") + +### Entity Details -##### User +#### User - `id`: Auto-incremented unique identifier for the user. - `email`: Unique email address of the user. @@ -126,7 +130,7 @@ model Database { - Relationships: - `teams` Many-to-many relationship with Team entity through TeamMembers property -##### Team +#### Team - `id` Auto-incremented unique identifier for the team - `name` Name of the team @@ -134,7 +138,7 @@ model Database { - `members` One-to-many relationship with team members - `projects` One-to-many relationship with projects -##### TeamMembers +#### TeamMembers - `teamId` Foreign key referencing the id column of the Team table, pointing to the team that the member belongs to - `userId` Foreign key referencing the id column of the User table, pointing to the user that is a member of the team @@ -143,7 +147,7 @@ model Database { - `team` Many-to-one relationship with teams - `user` Many-to-one relationship with users -##### Project +#### Project - `id` Auto-incremented unique identifier for the project - `name` Name of the project @@ -153,7 +157,7 @@ model Database { - `team` Many-to-one relationship with the team that creates the projects - `databases` One-to-many relationship with databases associated with the project -##### Database +#### Database - `id` Unique UUID identifier for the database - `name`Name of the database From 80630fc2ddddec2e0974816aca16eca7054cf377 Mon Sep 17 00:00:00 2001 From: AmrMohamed27 Date: Thu, 15 Feb 2024 01:28:53 +0200 Subject: [PATCH 7/7] Added a caption above the ERD diagram --- docs/schema.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/schema.md b/docs/schema.md index a6735cf..ee1265d 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -116,6 +116,7 @@ model Database { ### ERD Diagram +This ERD Diagram helps visualize the relationships between each entity in the schema and how they depend on each other ![ERD diagram of the schema](./prisma-erd.svg "ERD Diagram of the schema") ### Entity Details