diff --git a/.env.local.example b/.env.local.example index d65ed2e..12f3c56 100644 --- a/.env.local.example +++ b/.env.local.example @@ -10,4 +10,6 @@ NEXT_PUBLIC_LIVEKIT_URL=wss://discord-clonelink..... NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/ -NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/ \ No newline at end of file +NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/ +SUPABASE_ACCESS_TOKEN=supabaseaccesstoken +SUPABASE_DB_PASSWORD=supabasedbpassword \ No newline at end of file diff --git a/package.json b/package.json index 9fd78fb..ebe5632 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "db:seed": "tsc seed.ts && node seed.js" }, "dependencies": { "@clerk/nextjs": "^4.25.4", @@ -59,9 +60,11 @@ "@types/react-dom": "^18", "@types/uuid": "^9.0.5", "autoprefixer": "^10", + "dotenv": "^16.4.5", "eslint": "^8", "eslint-config-next": "13.5.4", "postcss": "^8", + "supabase": "^1.169.8", "tailwindcss": "^3", "typescript": "^5" } diff --git a/seed.ts b/seed.ts new file mode 100644 index 0000000..f43e646 --- /dev/null +++ b/seed.ts @@ -0,0 +1,60 @@ +import { createClient } from "@supabase/supabase-js"; +require('dotenv').config({ path: `.env.local` }) + + +const supabase = createClient( + process.env.NEXT_PUBLIC_SUPABASE_URL || "", + process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || "" +); + + + +async function seedDataBase() { + try { + const profile = await supabase + .from('Profile') + .insert([{ + userId: `user_1`, + name: `Dummy User`, + imgUrl: "https://utfs.io/f/684fd07f-6421-4d5c-8ab4-4bc16c7e3cea-tpuwo3.jpg", + email: `dummy_user_@example.com`, + }]) + .select("id"); + + const server = await supabase + .from('Server') + .insert([ + { + name: 'Sample Server', + imgUrl: 'https://utfs.io/f/0686af8c-8c20-423d-a273-79e07239dac7-7v9i42.avif', + inviteCode: 'invite_1', + profileId: profile.data![0].id + } + + ]).select("id"); + + const channel = await supabase + .from('Channel') + .insert([ + { + name: 'Sample Channel', + type: "TEXT", + serverId: server.data![0].id, + profileId: profile.data![0].id + } + ]); + + const memeber = await supabase.from('Member') + .insert([{ + role: "ADMIN", + profileId: profile.data![0].id, + serverId: server.data![0].id + }]); + + + console.log("Database Seeded successfully"); + } catch (err) { + console.error('Unexpected error:', err); + } +} +seedDataBase() \ No newline at end of file diff --git a/supabase/migrations/20240528135826_create_structure.sql b/supabase/migrations/20240528135826_create_structure.sql new file mode 100644 index 0000000..b52af28 --- /dev/null +++ b/supabase/migrations/20240528135826_create_structure.sql @@ -0,0 +1,89 @@ +CREATE TYPE "channeltype" AS ENUM ('TEXT', 'AUDIO', 'VIDEO'); +CREATE TYPE "memberrole" AS ENUM ('MODERATOR', 'GUEST', 'ADMIN'); + +CREATE TABLE + public."Profile" ( + "id" TEXT PRIMARY KEY DEFAULT gen_random_uuid(), + "userId" TEXT, + "name" TEXT, + "imgUrl" TEXT, + "email" TEXT, + "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT now() +); + + +CREATE TABLE + public."Server" ( + "id" TEXT PRIMARY KEY DEFAULT gen_random_uuid(), + "name" TEXT, + "imgUrl" TEXT, + "inviteCode" TEXT, + "profileId" TEXT, + "createdAt" TIMESTAMP WITHOUT TIME ZONE default current_timestamp, + "updatedAt" TIMESTAMP WITHOUT TIME ZONE default now(), + FOREIGN KEY ("profileId") REFERENCES public."Profile" (id) +); + +CREATE TABLE + "Channel" ( + "id" TEXT PRIMARY KEY DEFAULT gen_random_uuid(), + "name" text, + "type" "channeltype", + "serverId" text, + "profileId" text, + "createdAt" TIMESTAMP WITHOUT TIME ZONE default current_timestamp, + "updatedAt" TIMESTAMP WITHOUT TIME ZONE default now(), + FOREIGN KEY ("profileId") REFERENCES public."Profile" (id), + FOREIGN KEY ("serverId") REFERENCES public."Server" (id) +); + +CREATE TABLE + "Member" ( + "id" TEXT PRIMARY KEY DEFAULT gen_random_uuid(), + "role" "memberrole", + "serverId" text, + "profileId" text, + "createdAt" TIMESTAMP WITHOUT TIME ZONE default current_timestamp, + "updatedAt" TIMESTAMP WITHOUT TIME ZONE default now(), + FOREIGN KEY ("profileId") REFERENCES public."Profile" (id), + FOREIGN KEY ("serverId") REFERENCES public."Server" (id) +); + +CREATE TABLE + "Message" ( + "id" TEXT PRIMARY KEY DEFAULT gen_random_uuid(), + "CONTENT" text, + "fileUrl" TEXT, + "memberId" TEXT , + "channelId" TEXT, + "deleted" BOOLEAN, + "createdAt" TIMESTAMP WITHOUT TIME ZONE default current_timestamp, + "updatedAt" TIMESTAMP WITHOUT TIME ZONE default now(), + FOREIGN KEY ("channelId") REFERENCES public."Channel" (id), + FOREIGN KEY ("memberId") REFERENCES public."Member" (id) +); + +CREATE TABLE + "Conversation" ( + "id" TEXT PRIMARY KEY DEFAULT gen_random_uuid(), + "memberOneId" TEXT , + "memberTwoId" TEXT, + "createdAt" TIMESTAMP WITHOUT TIME ZONE default current_timestamp, + FOREIGN KEY ("memberTwoId") REFERENCES public."Member" (id), + FOREIGN KEY ("memberOneId") REFERENCES public."Member" (id) +); + +CREATE TABLE + "DirectMessage" ( + "id" TEXT PRIMARY KEY DEFAULT gen_random_uuid(), + "CONTENT" TEXT, + "fileUrl" TEXT, + "memberId" TEXT, + "conversationId" TEXT, + "deleted" BOOLEAN, + "createdAt" TIMESTAMP WITHOUT TIME ZONE default current_timestamp, + "updatedAt" TIMESTAMP WITHOUT TIME ZONE default now(), + FOREIGN KEY ("memberId") REFERENCES "Member" (id), + FOREIGN KEY ("conversationId") REFERENCES "Conversation" (id) +); \ No newline at end of file