From c46146d92663c10fef418ec5e74a754b72347418 Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Sat, 13 Dec 2025 13:23:54 +0530 Subject: [PATCH 1/4] feat: Add initial database schema and update setup instructions to use `schema.sql` while including `SUPABASE_JWT_SECRET` in `.env-example`. --- Backend/schema.sql | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Backend/schema.sql diff --git a/Backend/schema.sql b/Backend/schema.sql new file mode 100644 index 0000000..98a0a70 --- /dev/null +++ b/Backend/schema.sql @@ -0,0 +1,98 @@ +-- Enable UUID extension +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +-- Create Enum Types +CREATE TYPE application_status AS ENUM ('pending', 'accepted', 'rejected'); +CREATE TYPE invite_status AS ENUM ('pending', 'accepted', 'declined'); +CREATE TYPE payment_status AS ENUM ('pending', 'completed', 'failed'); +CREATE TYPE deal_status AS ENUM ('open', 'closed', 'in_progress'); + +-- Create Users Table +CREATE TABLE IF NOT EXISTS public.users ( + id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + username TEXT UNIQUE NOT NULL, + email TEXT UNIQUE NOT NULL, + role TEXT NOT NULL, -- 'creator' or 'brand' + profile_image TEXT, + bio TEXT, + created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), + is_online BOOLEAN DEFAULT FALSE, + last_seen TIMESTAMP WITH TIME ZONE DEFAULT NOW() +); + +-- Create Audience Insights Table +CREATE TABLE IF NOT EXISTS public.audience_insights ( + id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + audience_age_group JSONB, + audience_location JSONB, + engagement_rate FLOAT, + average_views INTEGER, + time_of_attention INTEGER, -- in seconds + price_expectation DECIMAL(10, 2), + created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() +); + +-- Create Sponsorships Table +CREATE TABLE IF NOT EXISTS public.sponsorships ( + id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + brand_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + title TEXT NOT NULL, + description TEXT NOT NULL, + required_audience JSONB, -- {"age": ["18-24"], "location": ["USA", "UK"]} + budget DECIMAL(10, 2), + engagement_minimum FLOAT, + status deal_status DEFAULT 'open', + created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() +); + +-- Create User Posts Table +CREATE TABLE IF NOT EXISTS public.user_posts ( + id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + title TEXT NOT NULL, + content TEXT NOT NULL, + post_url TEXT, + category TEXT, + engagement_metrics JSONB, -- {"likes": 500, "comments": 100, "shares": 50} + created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() +); + +-- Create Sponsorship Applications Table +CREATE TABLE IF NOT EXISTS public.sponsorship_applications ( + id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + creator_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + sponsorship_id UUID NOT NULL REFERENCES public.sponsorships(id) ON DELETE CASCADE, + post_id UUID REFERENCES public.user_posts(id) ON DELETE SET NULL, + proposal TEXT NOT NULL, + status application_status DEFAULT 'pending', + applied_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() +); + +-- Create Collaborations Table +CREATE TABLE IF NOT EXISTS public.collaborations ( + id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + creator_1_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + creator_2_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + collaboration_details TEXT NOT NULL, + status invite_status DEFAULT 'pending', + created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() +); + +-- Create Sponsorship Payments Table +CREATE TABLE IF NOT EXISTS public.sponsorship_payments ( + id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + creator_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + brand_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + sponsorship_id UUID NOT NULL REFERENCES public.sponsorships(id) ON DELETE CASCADE, + amount DECIMAL(10, 2) NOT NULL, + status payment_status DEFAULT 'pending', + transaction_date TIMESTAMP WITH TIME ZONE DEFAULT NOW() +); + +-- Grant Permissions +GRANT USAGE ON SCHEMA public TO anon, authenticated, service_role; +GRANT ALL ON ALL TABLES IN SCHEMA public TO service_role; +GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO service_role; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO authenticated; +GRANT SELECT ON ALL TABLES IN SCHEMA public TO anon; From 7b2cad681d407d1ad1e8c13a1453f55a60d614b2 Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Sat, 13 Dec 2025 13:24:14 +0530 Subject: [PATCH 2/4] docs: add `SUPABASE_JWT_SECRET` to `.env-example` and include `schema.sql` setup instructions in `README.md`. --- Backend/.env-example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Backend/.env-example b/Backend/.env-example index 18e42cd..6eefdf4 100644 --- a/Backend/.env-example +++ b/Backend/.env-example @@ -7,4 +7,5 @@ GROQ_API_KEY= SUPABASE_URL= SUPABASE_KEY= GEMINI_API_KEY= -YOUTUBE_API_KEY= \ No newline at end of file +YOUTUBE_API_KEY= +SUPABASE_JWT_SECRET= From 1954310ddff86f9137e267413bca5e16e7840cf8 Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Sat, 13 Dec 2025 13:24:31 +0530 Subject: [PATCH 3/4] docs: update SQL script execution instructions to use `schema.sql` instead of `sql.txt`. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 07d283d..2029c9e 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,9 @@ To populate the database with initial data, follow these steps: - In the left sidebar, click on **SQL Editor**. 3. **Run the SQL Script** + - Open the `schema.sql` file in your project. + - Copy the SQL queries from the file. + - Paste the queries into the SQL Editor and click **Run**. - Open the `sql.txt` file in your project. - Copy the SQL queries from the file. - Paste the queries into the SQL Editor and click **Run**. From 2a85114a5ff7aeae6a96413973da3b89ee47a925 Mon Sep 17 00:00:00 2001 From: Aditya Gupta <157408539+aditya-gupta24005@users.noreply.github.com> Date: Sat, 13 Dec 2025 13:50:00 +0530 Subject: [PATCH 4/4] Prevent duplicate enum types in schema.sql Added checks to prevent duplicate enum type creation. --- Backend/schema.sql | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Backend/schema.sql b/Backend/schema.sql index 98a0a70..12adcd2 100644 --- a/Backend/schema.sql +++ b/Backend/schema.sql @@ -2,10 +2,29 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- Create Enum Types -CREATE TYPE application_status AS ENUM ('pending', 'accepted', 'rejected'); -CREATE TYPE invite_status AS ENUM ('pending', 'accepted', 'declined'); -CREATE TYPE payment_status AS ENUM ('pending', 'completed', 'failed'); -CREATE TYPE deal_status AS ENUM ('open', 'closed', 'in_progress'); +DO $$ BEGIN + CREATE TYPE application_status AS ENUM ('pending', 'accepted', 'rejected'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; + +DO $$ BEGIN + CREATE TYPE invite_status AS ENUM ('pending', 'accepted', 'declined'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; + +DO $$ BEGIN + CREATE TYPE payment_status AS ENUM ('pending', 'completed', 'failed'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; + +DO $$ BEGIN + CREATE TYPE deal_status AS ENUM ('open', 'closed', 'in_progress'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; -- Create Users Table CREATE TABLE IF NOT EXISTS public.users (