-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added migrations and seed script (#83)
- Loading branch information
1 parent
76e345b
commit bdbc6eb
Showing
4 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: `[email protected]`, | ||
}]) | ||
.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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
); |