Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-khattab committed Feb 23, 2024
2 parents 1c45890 + 6c5be4b commit 4de2e9e
Show file tree
Hide file tree
Showing 26 changed files with 1,708 additions and 242 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
SECRET_KEY="fe9e750d4588e66b16c391980502d8f0afb006bb513ada864334f2853cc3a8fce25ec0bbcd4d1c68966b287de1847d28545eb658dabb870b9e8e32f8fc11d627"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -122,9 +125,13 @@ dist
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# VSCode
.vscode/

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

2 changes: 2 additions & 0 deletions docs/prisma-erd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
216 changes: 216 additions & 0 deletions docs/schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# 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`

## Prisma Components

We depend on Prisma as an ORM to connect our application to the database using the following components:

### 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")
}
```

## Schema Description

### 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)
}
```

### 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

#### 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

#### 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

#### 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

#### 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
}
```
Loading

0 comments on commit 4de2e9e

Please sign in to comment.