Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a supabase migration and updated readme for migration step #17

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 129 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Slack Clone

## Tech Stacks Used

- Vite React(for frontend)
- Node.js (for backend)
- Supabase (as a backend service)
Expand All @@ -9,24 +10,31 @@
### Features Overview

#### Authentication

- Users can login using OAuth with Google and GitHub, or using their email and password.
- Password reset functionality via email.

#### Homepage Features

1. **Todo List**

- Create, view, and delete personal todo lists.

2. **Google Calendar Integration**

- Authenticate with Google to manage events in the primary Google Calendar linked to the user's account.

3. **Direct Messaging**

- Initiate and manage conversations, share text and images (up to 50MB).

4. **Channel Management**

- Create channels, add/remove admins, assign/delete tasks to channel members and assign task to any member of the channel also, direct message members,channel deletion.
- Role-based access (Admin, Member).

5. **Search Functionality**

- Search for channels and users(with whom conversation is started) within the Slack Clone.

6. **Responsive Design**
Expand All @@ -37,12 +45,15 @@
### Environment Variables

- Create a .env file in the root directory of your project and define the following variables:
``` bash

```bash
VITE_SUPABASE_URL=<your_supabase_project_url>
VITE_SUPABASE_KEY=<your_supabase_api_key>
VITE_Backend_Port=<backend_port_number>
```

- Create a .env file in the Back_end directory with following variables:

```bash
Port=<Your backend port>
EMAIL_USER=<your mail for nodemailer>
Expand All @@ -54,35 +65,65 @@ API_KEY=<API key from google cloud>
SESSION_SECRET=<session secret generated by you>
```

# Run Migration to Create Tables

There is a migration file in this project that you can run to create tables.
Below are the commands you need to run:

##### 1. Login to Supabase

```bash
npx supabase login
```

This will prompt you to log in through the browser.

##### 2. Link your project

```bash
npx supabase link
```

This command will ask you to link your project, so make sure a project is already there in supabase

##### 3. Run the migration

```bash
npx supabase db push
```

This will execute the migration in your newly created project.

### Database Tables

1. **user_data**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default value | Extra options |
|-------------------|-------------|---------------|---------------|
| `id` | `uuid` | NULL | - `primary` |
| ----------------- | ----------- | ------------- | ------------- |
| `id` | `uuid` | NULL | - `primary` |
| `updated_at` | `timestamp` | NULL | `Is Nullable` |
| `username` | `text` | NULL | `Is Nullable` |
| `avatar_url` | `text` | NULL | `Is Nullable` |
| `email` | `text` | NULL | `Is Nullable` |
| `phone` | `text` | NULL | `Is Nullable` |
| `hashed_password` | `text` | NULL | `Is Nullable` |

- **Purpose**: Stores user information including username, avatar URL, email, phone number, and hashed password.

- `Foreign keys`

| schema | auth |
|-------------------|-----------|
| ----------------- | --------- |
| table | `users` |
| public.user_data | `id` |
| auth.users | `id` |
| Action if updated | No action |
| Action if removed | `Cascade` |

**THROUGH SQL EDITOR**

- The above tables are the manual explanations for creating the `user_data` tables use the below code in the `SQL EDITOR` for Handling the triggers
``` bash

```bash
-- Create the user_data table
create table user_data (
id uuid references auth.users on delete cascade not null primary key,
Expand All @@ -103,8 +144,8 @@ SESSION_SECRET=<session secret generated by you>
insert into public.user_data (id, username, avatar_url, email, phone)
values (
new.id,
new.raw_user_meta_data->>'username',
new.raw_user_meta_data->>'avatar_url',
new.raw_user_meta_data->>'username',
new.raw_user_meta_data->>'avatar_url',
new.email,
new.raw_user_meta_data->>'phone'
);
Expand All @@ -117,101 +158,100 @@ create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();

```


2. **direct_messages**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
|--------------|-------------|---------------------|----------------------------------|
| `id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `dm_chats` | `json` | NULL | `Is Nullable` `define as Array` |

```

2. **direct_messages**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
| ------------ | ----------- | ------------------- | ------------------------------- |
| `id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `dm_chats` | `json` | NULL | `Is Nullable` `define as Array` |

No `foreign keys` needed

- **Purpose**: Stores contact information related to direct messaging.

3. **chats_dm**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
|--------------|-------------|---------------|----------------------------------|
| `id` | `text` | NULL | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `messages` | `jsonb` | NULL | `Is Nullable` `define as Array` |
3. **chats_dm**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
| ------------ | ----------- | ------------- | ------------------------------- |
| `id` | `text` | NULL | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `messages` | `jsonb` | NULL | `Is Nullable` `define as Array` |

No `foreign keys` needed

No `foreign keys` needed

- **Purpose**: Stores direct messages between users.

4. **channels_messages**: Disable the `RLS` and Enable the `Realtime`
| Name | Type | Default Value | Extra options |
|-------------------|-------------|---------------------|----------------------------------|
| `channel_id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `messages` | `json` | NULL | `Is Nullable` `define as Array` |
| `channel_name` | `text` | NULL | - |
| `channel_members` | `json` | NULL | `Is Nullable` `define as Array` |
4. **channels_messages**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
| ----------------- | ----------- | ------------------- | ------------------------------- |
| `channel_id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `messages` | `json` | NULL | `Is Nullable` `define as Array` |
| `channel_name` | `text` | NULL | - |
| `channel_members` | `json` | NULL | `Is Nullable` `define as Array` |

No `foreign keys` needed

- **Purpose**: Stores messages and metadata for channels.

5. **channels_list**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
|--------------|-------------|---------------|----------------------------------|
| `id` | `uuid` | `auth.uid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `messages` | `json` | NULL | `Is Nullable` `define as Array` |
5. **channels_list**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
| ------------ | ----------- | ------------- | ------------------------------- |
| `id` | `uuid` | `auth.uid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `messages` | `json` | NULL | `Is Nullable` `define as Array` |

No `foreign keys` needed

No `foreign keys` needed

- **Purpose**: Lists channels that a user is a member of.

6. **Todo_list**: Disable the `RLS` and Enable the `Realtime`
| Name | Type | Default Value | Extra options |
|--------------|-------------|---------------------|----------------------------------|
| `id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `todo_list` | `json` | NULL | `Is Nullable` `define as Array` |

No `foreign keys` needed
- **Purpose**: Stores user-specific todo lists.

7. **Mails_sent**: Disable the `RLS` and Enable the `Realtime`
| Name | Type | Default Value | Extra options |
|--------------|-------------|---------------------|---------------|
| `task_id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `last_sent` | `text` | NULL | `Is Nullable` |
| `t_f` | `bool` | NULL | `Is Nullable` |

No `foreign keys` needed
- **Purpose**: Tracks emails sent as reminders for tasks.

8. **Channels_todolist**: Disable the `RLS` and Enable the `Realtime`
| Name | Type | Default Value | Extra options |
|--------------|-------------|---------------------|----------------------------------|
| `id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `todo_list` | `json` | NULL | `Is Nullable` `Define as Array` |
No `foreign keys` needed

- **Purpose**: Stores tasks assigned to everyone in a channel.
6. **Todo_list**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
| ------------ | ----------- | ------------------- | ------------------------------- |
| `id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `todo_list` | `json` | NULL | `Is Nullable` `define as Array` |

No `foreign keys` needed

- **Purpose**: Stores user-specific todo lists.

7. **Mails_sent**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
| ------------ | ----------- | ------------------- | ------------- |
| `task_id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `last_sent` | `text` | NULL | `Is Nullable` |
| `t_f` | `bool` | NULL | `Is Nullable` |

No `foreign keys` needed

- **Purpose**: Tracks emails sent as reminders for tasks.

8. **Channels_todolist**: Disable the `RLS` and Enable the `Realtime`

| Name | Type | Default Value | Extra options |
| ------------ | ----------- | ------------------- | ------------------------------- |
| `id` | `uuid` | `gen_random_uuid()` | `primary` |
| `created_at` | `timestamp` | `now()` | - |
| `todo_list` | `json` | NULL | `Is Nullable` `Define as Array` |

No `foreign keys` needed

- **Purpose**: Stores tasks assigned to everyone in a channel.

### Storage bucket

1. Go to the Storage section and click on `new bucket`.
2. Name the bucket as `photos`, enable the `Public bucket`, and save it.
3. Under the configuration section, Click on `policies`.
4. Other Policies under storage.objects, Create a `New policy` as `For full customisation`.
5. Give the Policy name and `All` for allowed operation, keep the Target roles as default.
6. Provide `true` or `1` for `USING expression` and `With CHECK expression`.

4 changes: 4 additions & 0 deletions supabase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Supabase
.branches
.temp
.env
Loading