Skip to content

Commit 763aa7a

Browse files
committed
Table Setup documentation Added
1 parent b24e6c4 commit 763aa7a

File tree

2 files changed

+252
-19
lines changed

2 files changed

+252
-19
lines changed

learn.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
2-
## Local development:
3-
4-
---
1+
# Project Setup
52

63
### Fork the repo:
74

@@ -20,11 +17,13 @@ To contribute to this Discord-Clone, you must first fork the [Discord-Clone](htt
2017
```sh
2118
cd discord-clone
2219
```
20+
2321
3. To install the dependencies, run:
2422

2523
```sh
2624
npm install
2725
```
26+
2827
4. To start the development server, run in terminal:
2928

3029
```sh
@@ -33,32 +32,23 @@ To contribute to this Discord-Clone, you must first fork the [Discord-Clone](htt
3332

3433
Note : The project's backend is based on nodejs, so make sure you have node version 20 or above installed in your machine, if not refer to this: https://nodejs.org/en/download.
3534

36-
### Setup environment variables
35+
# Setup environment variables
3736

38-
---
37+
## Supabase setup:
3938

40-
#### 1. Supabase setup:
39+
### 1. Project API setup
4140

4241
1. Go to [Supabase Dashboard](https://supabase.com/dashboard/projects) (create your account if you have not).
4342
2. Create a new project.
4443
![Screenshot 2024-05-12 122005](https://github.com/meAyushSharma/file-converter--md-html/assets/146171218/b2332b87-9014-444e-847e-0edddfd41508)
45-
3. Get your project url and anon api key.
44+
3. Get your project url and anon api key.
4645
Note : You should not reveal this api key as this works as a bridge between your database and project.
4746
4. In your forked repo create a `.env.local` file, copy the contents from `.env.local.example` and paste the credentials in it:
4847
```sh
4948
NEXT_PUBLIC_SUPABASE_URL=https(:)//some-string-here.supabase.co
5049
NEXT_PUBLIC_SUPABASE_ANON_KEY=anon-api-key-here
5150
```
51+
5. Setup your tables. Refer to [Table Setup Documentation](./table-setup.md)
5252

53-
54-
5. Connect to your supabase DB.
55-
```sh
56-
import { createClient } from '@supabase/supabase-js';
57-
58-
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
59-
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
60-
const supabase = createClient(supabaseUrl, supabaseKey);
61-
```
62-
63-
Supabase is an open source firebase alternative, that provides Postgres database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, Storage, and Vector embeddings.
53+
Supabase is an open source firebase alternative, that provides Postgres database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, Storage, and Vector embeddings.
6454
Refer to this [Documentation](https://supabase.com/docs), for more information.

table-setup.md

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
# PosgreSQl table setup
2+
3+
#### Points to remember:-
4+
5+
- There are `7` tables in **public** schema.
6+
- Make sure your RLS policy is Disabled for all tables.
7+
- You have to create both enums and tables.
8+
- Running the provided codes may create problem in case sensitiveness. Make sure you correct those cases.
9+
- To run the SQL code go to [Supabase Dashboard](https://supabase.com/dashboard/project) -> `YourProject` -> `SQL Editor`
10+
- Make sure you create the ENUM first then the Tables sequentially.
11+
- `If your SQL code does not work then please try to create by seeing the images.`
12+
13+
| Table Name | No. of Columns |
14+
| ------------- | -------------- |
15+
| Profile | 7 |
16+
| Server | 7 |
17+
| Channel | 7 |
18+
| Member | 6 |
19+
| Conversation | 4 |
20+
| Message | 8 |
21+
| DirectMessage | 8 |
22+
23+
## Enums -->
24+
25+
| Enum name | Values |
26+
| ----------- | --------------------------- |
27+
| ChannelType | [ TEXT, AUDIO, VIDEO ] |
28+
| MemberRole | [ ADMIN, MODERATOR, GUEST ] |
29+
30+
Code to create the enums ->
31+
32+
```sql
33+
CREATE TYPE channeltype AS ENUM ('TEXT', 'AUDIO', 'VIDEO');
34+
CREATE TYPE memberrole AS ENUM ('MODERATOR', 'GUEST', 'ADMIN');
35+
```
36+
37+
## 1. Table - 'Profile':
38+
39+
| Column Name | Data Type | Description |
40+
| ----------- | --------- | ------------------------- |
41+
| id | text | Primary key |
42+
| name | text | Username of the user |
43+
| userId | text | |
44+
| imgUrl | text | profile image of the user |
45+
| email | text | Email of the user |
46+
| createdAt | timestamp | Time of creation |
47+
| updatedAt | timestamp | Last updated time |
48+
49+
![Screenshot from 2024-05-26 17-47-26](https://github.com/Yeasir0032/GcectHackathon/assets/124646897/164d807f-c3f3-4d6b-90ce-5cd3f7884cb0)
50+
51+
### SQL Code to Create Table
52+
53+
```sql
54+
CREATE TABLE
55+
public.Profile (
56+
id TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
57+
userId TEXT,
58+
name TEXT,
59+
imgUrl TEXT,
60+
email TEXT,
61+
createdAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
62+
updatedAt TIMESTAMP WITH TIME ZONE DEFAULT now()
63+
);
64+
```
65+
66+
## 2. Table - 'Server':
67+
68+
| Column Name | Data Type | Description |
69+
| ----------- | --------- | ------------------------------------------------------ |
70+
| id | text | Primary key |
71+
| name | text | Name of the server |
72+
| imgUrl | text | Thumbnail |
73+
| profileId | text | Owner of the server- It is a forign key of Profile(id) |
74+
| inviteCode | text | Invite link for the server |
75+
| createdAt | timestamp | Time of creation |
76+
| updatedAt | timestamp | Last updated time |
77+
78+
![Screenshot from 2024-05-26 18-52-08](https://github.com/Yeasir0032/GcectHackathon/assets/124646897/d4834b0a-5b32-4c84-9b0b-316a64d108bb)
79+
80+
### SQL code to create table
81+
82+
```sql
83+
CREATE TABLE
84+
public.Server (
85+
id TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
86+
name TEXT,
87+
imgUrl TEXT,
88+
inviteCode TEXT,
89+
profileId TEXT,
90+
createdAt TIMESTAMP WITHOUT TIME ZONE default current_timestamp,
91+
updatedAt TIMESTAMP WITHOUT TIME ZONE default now(),
92+
FOREIGN KEY (profileId) REFERENCES public.Profile (id)
93+
);
94+
```
95+
96+
## 3. Table - 'Channel':
97+
98+
| Column Name | Data Type | Description |
99+
| ----------- | ----------- | ------------------------------------------- |
100+
| id | text | Primary key |
101+
| name | text | Name of the channel |
102+
| type | channelType | It is a enum of type channel type |
103+
| serverId | text | Server id- It is a forign key of Server(id) |
104+
| profileId | text | Profile id of admin - It is a forign key |
105+
| createdAt | timestamp | Time of creation |
106+
| updatedAt | timestamp | Last updated time |
107+
108+
![Screenshot from 2024-05-27 17-03-59](https://github.com/Yeasir0032/DataAnalystStreamlit/assets/124646897/87412081-3c48-4c68-8993-9b3be0cde22e)
109+
110+
### SQL code to create table
111+
112+
```sql
113+
CREATE TABLE
114+
Channel (
115+
id TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
116+
name text,
117+
type channeltype,
118+
serverId text,
119+
profileId text,
120+
createdAt TIMESTAMP WITHOUT TIME ZONE default current_timestamp,
121+
updatedAt TIMESTAMP WITHOUT TIME ZONE default now(),
122+
FOREIGN KEY (profileId) REFERENCES public.Profile (id),
123+
FOREIGN KEY (serverId) REFERENCES public.Server (id)
124+
);
125+
```
126+
127+
## 3. Table - 'Member':
128+
129+
| Column Name | Data Type | Description |
130+
| ----------- | ---------- | ------------------------------------------- |
131+
| id | text | Primary key |
132+
| role | memberrole | It is a enum of type member role |
133+
| serverId | text | Server id- It is a forign key of Server(id) |
134+
| profileId | text | Profile id of admin - It is a forign key |
135+
| createdAt | timestamp | Time of creation |
136+
| updatedAt | timestamp | Last updated time |
137+
138+
![Screenshot from 2024-05-27 18-06-36](https://github.com/Yeasir0032/GcectHackathon/assets/124646897/f1155ed1-fa0d-43ed-bbed-acb224db409a)
139+
140+
### SQL code to create table
141+
142+
```sql
143+
CREATE TABLE
144+
Member (
145+
id TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
146+
role memberrole,
147+
serverId text,
148+
profileId text,
149+
createdAt TIMESTAMP WITHOUT TIME ZONE default current_timestamp,
150+
updatedAt TIMESTAMP WITHOUT TIME ZONE default now(),
151+
FOREIGN KEY (profileId) REFERENCES public.Profile (id),
152+
FOREIGN KEY (serverId) REFERENCES public.Server (id)
153+
);
154+
```
155+
156+
## 3. Table - 'Message':
157+
158+
| Column Name | Data Type | Description |
159+
| ----------- | --------- | ----------------------------------------------- |
160+
| id | text | Primary key |
161+
| content | text | Content of the message |
162+
| fileUrl | text | Attachment url (nullable) |
163+
| memberId | text | Member id - It is a foreign key for Member(id) |
164+
| channelId | text | Channel id - It is a forign key for Channel(id) |
165+
| deleted | boolean | A boolean value to check if message is deleted |
166+
| createdAt | timestamp | Time of creation |
167+
| updatedAt | timestamp | Last updated time |
168+
169+
![Screenshot from 2024-05-28 15-06-30](https://github.com/Yeasir0032/Discord-Clone/assets/124646897/983daf48-0b61-41f1-bcc5-1c8eae0fd9ae)
170+
171+
### SQL code to create table
172+
173+
```sql
174+
CREATE TABLE
175+
Message (
176+
id TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
177+
CONTENT text,
178+
fileUrl TEXT,
179+
memberId TEXT ,
180+
channelId TEXT,
181+
deleted BOOLEAN,
182+
createdAt TIMESTAMP WITHOUT TIME ZONE default current_timestamp,
183+
updatedAt TIMESTAMP WITHOUT TIME ZONE default now(),
184+
FOREIGN KEY (channelId) REFERENCES public.Channel (id),
185+
FOREIGN KEY (memberId) REFERENCES public.Member (id)
186+
);
187+
```
188+
189+
## 4. Table - 'Conversation':
190+
191+
| Column Name | Data Type | Description |
192+
| ----------- | --------- | ----------------------------------------------- |
193+
| id | text | Primary key |
194+
| memberOneId | text | Sender Member Id - Foreign key for Member(id) |
195+
| memberTwoId | text | Receiver Member Id - Foreign key for Member(id) |
196+
| createdAt | timestamp | Time of creation |
197+
198+
![image](https://github.com/Yeasir0032/Discord-Clone/assets/124646897/8100e53b-e7ff-484e-897e-296d07cfc5fe)
199+
200+
### SQL code to create Table
201+
202+
```sql
203+
CREATE TABLE
204+
Conversation (
205+
id TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
206+
memberOneId TEXT ,
207+
memberTwoId TEXT,
208+
createdAt TIMESTAMP WITHOUT TIME ZONE default current_timestamp,
209+
FOREIGN KEY (memberTwoId) REFERENCES public.Member (id),
210+
FOREIGN KEY (memberOneId) REFERENCES public.Member (id)
211+
);
212+
```
213+
214+
## 5. Table - 'DirectMessage':
215+
216+
| Column Name | Data Type | Description |
217+
| -------------- | --------- | -------------------------------------------------- |
218+
| id | text | Primary key |
219+
| content | text | Content of the message |
220+
| fileUrl | text | Attachment url (nullable) |
221+
| memberId | text | Sender Id - foreign keys for Member(id) |
222+
| conversationId | text | Converastion Id - Foreign key for Conversation(id) |
223+
| deleted | boolean | A boolean value to check if message is deleted |
224+
| createdAt | timestamp | Time of creation |
225+
| updatedAt | timestamp | Last updated time |
226+
227+
![image](https://github.com/Yeasir0032/Discord-Clone/assets/124646897/98cdafe1-860d-463b-9afd-f9f03b1a00cb)
228+
229+
```sql
230+
CREATE TABLE
231+
DirectMessage (
232+
id TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
233+
CONTENT TEXT,
234+
fileUrl TEXT,
235+
memberId TEXT,
236+
conversationId TEXT,
237+
deleted BOOLEAN,
238+
createdAt TIMESTAMP WITHOUT TIME ZONE default current_timestamp,
239+
updatedAt TIMESTAMP WITHOUT TIME ZONE default now(),
240+
FOREIGN KEY (memberId) REFERENCES Member (id),
241+
FOREIGN KEY (conversationId) REFERENCES Conversation (id)
242+
);
243+
```

0 commit comments

Comments
 (0)