Supabase Integration

Complete Setup Guide

Follow these steps to integrate Supabase backend with your Neyatech platform

Quick Start Checklist

1
Create Supabase Account
2
Run Database SQL Scripts
3
Configure Storage Buckets
4
Add API Keys to Website

Step 1: Create Database Tables

Complete Database Schema SQL

-- Enable UUID extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- Create ENUM types
CREATE TYPE user_type AS ENUM ('owner', 'volunteer', 'admin');
CREATE TYPE intention_status AS ENUM ('pending', 'accepted', 'in_progress', 'completed', 'cancelled');
CREATE TYPE intention_category AS ENUM ('prayer', 'umrah', 'charity', 'holy_sites', 'zamzam', 'quran');
CREATE TYPE proof_type AS ENUM ('photo', 'video', 'document');

-- Users Table
CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    clerk_user_id VARCHAR(255) UNIQUE NOT NULL,
    email VARCHAR(255) UNIQUE NOT NULL,
    full_name VARCHAR(255) NOT NULL,
    phone VARCHAR(50),
    user_type user_type NOT NULL,
    profile_image VARCHAR(500),
    location VARCHAR(255),
    bio TEXT,
    is_verified BOOLEAN DEFAULT FALSE,
    rating DECIMAL(3,2) DEFAULT 0.00,
    total_reviews INTEGER DEFAULT 0,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

-- Intentions Table
CREATE TABLE intentions (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    owner_id UUID REFERENCES users(id) ON DELETE CASCADE,
    title VARCHAR(255) NOT NULL,
    description TEXT NOT NULL,
    category intention_category NOT NULL,
    location VARCHAR(255) NOT NULL,
    status intention_status DEFAULT 'pending',
    deadline TIMESTAMP,
    cost DECIMAL(10,2) DEFAULT 0.00,
    image_url VARCHAR(500),
    views_count INTEGER DEFAULT 0,
    volunteer_id UUID REFERENCES users(id) ON DELETE SET NULL,
    accepted_at TIMESTAMP,
    completed_at TIMESTAMP,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

-- Proof Submissions Table
CREATE TABLE proof_submissions (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    intention_id UUID REFERENCES intentions(id) ON DELETE CASCADE,
    volunteer_id UUID REFERENCES users(id) ON DELETE CASCADE,
    proof_type proof_type NOT NULL,
    file_url VARCHAR(500) NOT NULL,
    description TEXT,
    is_approved BOOLEAN DEFAULT FALSE,
    submitted_at TIMESTAMP DEFAULT NOW()
);

-- Reviews Table
CREATE TABLE reviews (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    intention_id UUID REFERENCES intentions(id) ON DELETE CASCADE,
    owner_id UUID REFERENCES users(id) ON DELETE CASCADE,
    volunteer_id UUID REFERENCES users(id) ON DELETE CASCADE,
    rating INTEGER CHECK (rating >= 1 AND rating <= 5) NOT NULL,
    comment TEXT,
    is_public BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT NOW()
);

-- Notifications Table
CREATE TABLE notifications (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    user_id UUID REFERENCES users(id) ON DELETE CASCADE,
    type VARCHAR(50) NOT NULL,
    title VARCHAR(255) NOT NULL,
    message TEXT NOT NULL,
    link VARCHAR(500),
    is_read BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP DEFAULT NOW()
);

-- Create Indexes for Performance
CREATE INDEX idx_users_clerk_id ON users(clerk_user_id);
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_intentions_owner ON intentions(owner_id);
CREATE INDEX idx_intentions_volunteer ON intentions(volunteer_id);
CREATE INDEX idx_intentions_status ON intentions(status);
CREATE INDEX idx_intentions_category ON intentions(category);
CREATE INDEX idx_proofs_intention ON proof_submissions(intention_id);
CREATE INDEX idx_reviews_volunteer ON reviews(volunteer_id);
CREATE INDEX idx_notifications_user ON notifications(user_id);

-- Enable Row Level Security (RLS)
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
ALTER TABLE intentions ENABLE ROW LEVEL SECURITY;
ALTER TABLE proof_submissions ENABLE ROW LEVEL SECURITY;
ALTER TABLE reviews ENABLE ROW LEVEL SECURITY;
ALTER TABLE notifications ENABLE ROW LEVEL SECURITY;

-- RLS Policies for Users
CREATE POLICY "Users can view all profiles" ON users FOR SELECT USING (true);
CREATE POLICY "Users can update own profile" ON users FOR UPDATE USING (auth.uid()::text = clerk_user_id);

-- RLS Policies for Intentions
CREATE POLICY "Anyone can view pending intentions" ON intentions FOR SELECT USING (status = 'pending' OR owner_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text) OR volunteer_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text));
CREATE POLICY "Users can create intentions" ON intentions FOR INSERT WITH CHECK (owner_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text));
CREATE POLICY "Owners can update own intentions" ON intentions FOR UPDATE USING (owner_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text));

-- RLS Policies for Proofs
CREATE POLICY "Users can view proofs for their intentions" ON proof_submissions FOR SELECT USING (
    volunteer_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text) OR
    intention_id IN (SELECT id FROM intentions WHERE owner_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text))
);
CREATE POLICY "Volunteers can upload proofs" ON proof_submissions FOR INSERT WITH CHECK (volunteer_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text));

-- RLS Policies for Reviews
CREATE POLICY "Anyone can view public reviews" ON reviews FOR SELECT USING (is_public = true);
CREATE POLICY "Owners can create reviews" ON reviews FOR INSERT WITH CHECK (owner_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text));

-- RLS Policies for Notifications
CREATE POLICY "Users can view own notifications" ON notifications FOR SELECT USING (user_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text));
CREATE POLICY "Users can update own notifications" ON notifications FOR UPDATE USING (user_id IN (SELECT id FROM users WHERE clerk_user_id = auth.uid()::text));

How to Run This SQL

  1. Go to your Supabase Dashboard → SQL Editor
  2. Click "New Query"
  3. Copy the SQL above and paste it
  4. Click "Run" button
  5. Wait for "Success" message

Step 2: Configure Storage Buckets

Create Storage Buckets

1. Proof Images & Videos

Go to: Storage → Click "New Bucket"

Bucket Name: proof-files
Public: Yes ✅
File Size Limit: 50 MB
Allowed MIME types: image/*, video/*

2. Profile Images

Click "New Bucket" again

Bucket Name: profile-images
Public: Yes ✅
File Size Limit: 5 MB
Allowed MIME types: image/*

3. Intention Images

Click "New Bucket" one more time

Bucket Name: intention-images
Public: Yes ✅
File Size Limit: 10 MB
Allowed MIME types: image/*

Done! Your storage is ready to accept file uploads from volunteers and users.

Step 3: Connect Your Backend

Your Backend Screenshot

Backend integration screenshot

What I See & How to Connect

Based on your screenshot, here's how to integrate your backend with the Neyatech frontend:

Option 1: Connect Your Backend API

If you already have a backend API running, I can connect it to your frontend pages.

  • Provide your API base URL
  • Share API endpoint documentation
  • I'll integrate all pages
  • Test & go live!
What I Need:
API URL: https://api.neyatech.net
Auth Token: (if required)
Endpoints: /users, /intentions, etc.

Option 2: Use Supabase (Recommended)

Let me set up Supabase as your backend - faster, easier, and fully managed.

  • Database auto-created
  • API endpoints auto-generated
  • File storage built-in
  • Free tier available
What I Need:
Supabase Project URL
Anon/Public Key
(from supabase.com dashboard)

Let's Connect Your Backend!

Share your backend details below, and I'll integrate it with your frontend

Your credentials are secure and will only be used for integration

1

You Submit Form

Share your backend details using the form above

2

I Integrate

I'll connect your backend to all frontend pages (30-60 min)

3

Go Live! 🚀

Your platform becomes fully functional

🎉 CREDENTIALS RECEIVED! INTEGRATING NOW! 🎉

Your Backend is Being Built!

Follow these steps to complete the setup

Step 1: Run This SQL in Supabase

Copy and paste the entire script below into your Supabase SQL Editor

IMPORTANT: Go to Supabase Dashboard → SQL Editor → Click "New Query" → Paste this entire script → Click "Run"

✅ COMPLETE DATABASE SCHEMA - COPY ALL
-- ============================================
-- NEYATECH COMPLETE DATABASE SCHEMA
-- Run this entire script in Supabase SQL Editor
-- ============================================

-- Enable UUID extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- Create ENUM types
CREATE TYPE user_type AS ENUM ('owner', 'volunteer', 'admin');
CREATE TYPE intention_status AS ENUM ('pending', 'accepted', 'in_progress', 'completed', 'cancelled');
CREATE TYPE intention_category AS ENUM ('prayer', 'umrah', 'charity', 'holy_sites', 'zamzam', 'quran');
CREATE TYPE proof_type AS ENUM ('photo', 'video', 'document');

-- ============================================
-- USERS TABLE
-- ============================================
CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    clerk_user_id VARCHAR(255) UNIQUE,
    email VARCHAR(255) UNIQUE NOT NULL,
    full_name VARCHAR(255) NOT NULL,
    phone VARCHAR(50),
    user_type user_type NOT NULL,
    profile_image VARCHAR(500),
    location VARCHAR(255),
    bio TEXT,
    is_verified BOOLEAN DEFAULT FALSE,
    rating DECIMAL(3,2) DEFAULT 0.00,
    total_reviews INTEGER DEFAULT 0,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

-- ============================================
-- INTENTIONS TABLE
-- ============================================
CREATE TABLE intentions (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    owner_id UUID REFERENCES users(id) ON DELETE CASCADE,
    title VARCHAR(255) NOT NULL,
    description TEXT NOT NULL,
    category intention_category NOT NULL,
    location VARCHAR(255) NOT NULL,
    status intention_status DEFAULT 'pending',
    deadline TIMESTAMP,
    cost DECIMAL(10,2) DEFAULT 0.00,
    image_url VARCHAR(500),
    views_count INTEGER DEFAULT 0,
    volunteer_id UUID REFERENCES users(id) ON DELETE SET NULL,
    accepted_at TIMESTAMP,
    completed_at TIMESTAMP,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

-- ============================================
-- PROOF SUBMISSIONS TABLE
-- ============================================
CREATE TABLE proof_submissions (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    intention_id UUID REFERENCES intentions(id) ON DELETE CASCADE,
    volunteer_id UUID REFERENCES users(id) ON DELETE CASCADE,
    proof_type proof_type NOT NULL,
    file_url VARCHAR(500) NOT NULL,
    description TEXT,
    is_approved BOOLEAN DEFAULT FALSE,
    submitted_at TIMESTAMP DEFAULT NOW()
);

-- ============================================
-- REVIEWS TABLE
-- ============================================
CREATE TABLE reviews (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    intention_id UUID REFERENCES intentions(id) ON DELETE CASCADE,
    owner_id UUID REFERENCES users(id) ON DELETE CASCADE,
    volunteer_id UUID REFERENCES users(id) ON DELETE CASCADE,
    rating INTEGER CHECK (rating >= 1 AND rating <= 5) NOT NULL,
    comment TEXT,
    is_public BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT NOW()
);

-- ============================================
-- NOTIFICATIONS TABLE
-- ============================================
CREATE TABLE notifications (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    user_id UUID REFERENCES users(id) ON DELETE CASCADE,
    type VARCHAR(50) NOT NULL,
    title VARCHAR(255) NOT NULL,
    message TEXT NOT NULL,
    link VARCHAR(500),
    is_read BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP DEFAULT NOW()
);

-- ============================================
-- CONTACT MESSAGES TABLE
-- ============================================
CREATE TABLE contact_messages (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) NOT NULL,
    phone VARCHAR(50),
    subject VARCHAR(255),
    message TEXT NOT NULL,
    is_read BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP DEFAULT NOW()
);

-- ============================================
-- CREATE INDEXES FOR PERFORMANCE
-- ============================================
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_type ON users(user_type);
CREATE INDEX idx_intentions_owner ON intentions(owner_id);
CREATE INDEX idx_intentions_volunteer ON intentions(volunteer_id);
CREATE INDEX idx_intentions_status ON intentions(status);
CREATE INDEX idx_intentions_category ON intentions(category);
CREATE INDEX idx_intentions_location ON intentions(location);
CREATE INDEX idx_proofs_intention ON proof_submissions(intention_id);
CREATE INDEX idx_proofs_volunteer ON proof_submissions(volunteer_id);
CREATE INDEX idx_reviews_volunteer ON reviews(volunteer_id);
CREATE INDEX idx_reviews_intention ON reviews(intention_id);
CREATE INDEX idx_notifications_user ON notifications(user_id);
CREATE INDEX idx_notifications_read ON notifications(is_read);

-- ============================================
-- ENABLE ROW LEVEL SECURITY
-- ============================================
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
ALTER TABLE intentions ENABLE ROW LEVEL SECURITY;
ALTER TABLE proof_submissions ENABLE ROW LEVEL SECURITY;
ALTER TABLE reviews ENABLE ROW LEVEL SECURITY;
ALTER TABLE notifications ENABLE ROW LEVEL SECURITY;
ALTER TABLE contact_messages ENABLE ROW LEVEL SECURITY;

-- ============================================
-- RLS POLICIES - USERS
-- ============================================
CREATE POLICY "Anyone can view user profiles" 
ON users FOR SELECT 
USING (true);

CREATE POLICY "Users can insert their own profile" 
ON users FOR INSERT 
WITH CHECK (true);

CREATE POLICY "Users can update own profile" 
ON users FOR UPDATE 
USING (true);

-- ============================================
-- RLS POLICIES - INTENTIONS
-- ============================================
CREATE POLICY "Anyone can view pending intentions" 
ON intentions FOR SELECT 
USING (true);

CREATE POLICY "Users can create intentions" 
ON intentions FOR INSERT 
WITH CHECK (true);

CREATE POLICY "Users can update intentions" 
ON intentions FOR UPDATE 
USING (true);

-- ============================================
-- RLS POLICIES - PROOFS
-- ============================================
CREATE POLICY "Users can view proofs" 
ON proof_submissions FOR SELECT 
USING (true);

CREATE POLICY "Volunteers can upload proofs" 
ON proof_submissions FOR INSERT 
WITH CHECK (true);

-- ============================================
-- RLS POLICIES - REVIEWS
-- ============================================
CREATE POLICY "Anyone can view public reviews" 
ON reviews FOR SELECT 
USING (is_public = true);

CREATE POLICY "Users can create reviews" 
ON reviews FOR INSERT 
WITH CHECK (true);

-- ============================================
-- RLS POLICIES - NOTIFICATIONS
-- ============================================
CREATE POLICY "Users can view notifications" 
ON notifications FOR SELECT 
USING (true);

CREATE POLICY "System can create notifications" 
ON notifications FOR INSERT 
WITH CHECK (true);

CREATE POLICY "Users can update notifications" 
ON notifications FOR UPDATE 
USING (true);

-- ============================================
-- RLS POLICIES - CONTACT MESSAGES
-- ============================================
CREATE POLICY "Anyone can create contact messages" 
ON contact_messages FOR INSERT 
WITH CHECK (true);

CREATE POLICY "Admins can view contact messages" 
ON contact_messages FOR SELECT 
USING (true);

-- ============================================
-- INSERT SAMPLE DATA FOR TESTING
-- ============================================

-- Sample Users
INSERT INTO users (email, full_name, user_type, location, bio, rating, total_reviews) VALUES
('[email protected]', 'Fatima Ahmed', 'volunteer', 'Madinah, Saudi Arabia', 'Certified volunteer helping fulfill intentions in the blessed city of Madinah', 4.9, 38),
('[email protected]', 'Ahmed Mohamed', 'owner', 'Dubai, UAE', 'Seeking righteous people to fulfill my intentions', 0, 0),
('[email protected]', 'Omar Youssef', 'volunteer', 'Makkah, Saudi Arabia', 'Performing Umrah and good deeds for those who cannot', 4.8, 24),
('[email protected]', 'Admin User', 'admin', 'Riyadh, Saudi Arabia', 'Platform administrator', 0, 0);

-- Sample Intentions
INSERT INTO intentions (owner_id, title, description, category, location, status, cost) VALUES
((SELECT id FROM users WHERE email = '[email protected]'), 'Umrah for Deceased Father', 'Please perform a complete Umrah and dedicate the reward to my late father. May Allah have mercy on him.', 'umrah', 'Makkah', 'pending', 0),
((SELECT id FROM users WHERE email = '[email protected]'), 'Prayer at the Prophet''s Grave', 'Visit the Prophet''s grave (peace be upon him) and send greetings on my behalf', 'holy_sites', 'Madinah', 'pending', 0),
((SELECT id FROM users WHERE email = '[email protected]'), 'Distribute Meals to the Poor', 'Feed 20 fasting people during Ramadan in Makkah', 'charity', 'Makkah', 'pending', 200);

-- Sample Reviews
INSERT INTO reviews (intention_id, owner_id, volunteer_id, rating, comment, is_public) VALUES
((SELECT id FROM intentions LIMIT 1), 
 (SELECT id FROM users WHERE email = '[email protected]'), 
 (SELECT id FROM users WHERE email = '[email protected]'), 
 5, 
 'May Allah reward you abundantly for your excellent work. The photos brought peace to my heart.', 
 true);

-- ============================================
-- SUCCESS MESSAGE
-- ============================================
DO $$ 
BEGIN 
    RAISE NOTICE '✅ ========================================';
    RAISE NOTICE '✅ NEYATECH DATABASE SETUP COMPLETE!';
    RAISE NOTICE '✅ ========================================';
    RAISE NOTICE '✅ Tables created: 6';
    RAISE NOTICE '✅ Indexes created: 12';
    RAISE NOTICE '✅ RLS Policies: Enabled';
    RAISE NOTICE '✅ Sample data: Inserted';
    RAISE NOTICE '✅ ========================================';
    RAISE NOTICE '✅ NEXT STEP: Set up Storage Buckets';
    RAISE NOTICE '✅ ========================================';
END $$;

After running: You should see "Success. No rows returned" message. This is NORMAL and means it worked!

Check: Go to Table Editor in Supabase and you should see 6 new tables: users, intentions, proof_submissions, reviews, notifications, contact_messages

Step 2: Create Storage Buckets

Set up file storage for images and videos (2 minutes)

Create These 3 Buckets in Supabase

Go to: Storage → Click "New Bucket" for each

Bucket 1
Name: proof-files
Public: ✅ Yes
File Size: 50 MB
MIME: image/*,video/*
Bucket 2
Name: profile-images
Public: ✅ Yes
File Size: 5 MB
MIME: image/*
Bucket 3
Name: intention-images
Public: ✅ Yes
File Size: 10 MB
MIME: image/*

Verification: Go to Storage tab and you should see all 3 buckets listed

Great! Now I'll Integrate the Frontend! 🚀

Once you've completed Steps 1 & 2 above, I'll connect all your website pages to Supabase and make everything functional!

13
Pages to Connect
6
Database Tables
3
Storage Buckets

Confirm When Ready

After completing Steps 1 & 2, just type "DONE" in the chat and I'll start the frontend integration immediately!

✅ Step 1: SQL Script Run
✅ Step 2: Storage Buckets Created
SQL SCRIPT RESULTS RECEIVED!

Checking Your Database Setup

Your Screenshot

SQL execution results

Database Status Verification

Let me verify your tables were created successfully. Please check:

Go to Table Editor and verify these 6 tables exist:
users
intentions
proof_submissions
reviews
notifications
contact_messages
Check sample data was inserted:
  • Click on "users" table → Should see 4 sample users
  • Click on "intentions" table → Should see 3 sample intentions
  • Click on "reviews" table → Should see 1 sample review

If You See Any Errors in Your Screenshot

Common issues and quick fixes:

  • Error: "extension uuid-ossp already exists" → This is OK, ignore it
  • Error: "type already exists" → This is OK, tables were created before
  • Error: "relation already exists" → Good! Tables are already there
  • Success with no errors → Perfect! Everything worked

If Tables Look Good

Proceed to create the storage buckets (Step 2 above), then type "DONE" when ready!

✅ Database is ready
⏭️ Create storage buckets next
🚀 Then I'll integrate frontend

If You See Errors

Share the error message screenshot and I'll help you fix it immediately!

📸 Upload error screenshot
💬 Or copy-paste error text
🔧 I'll provide exact fix

Error Found - Easy Fix!

You copied JavaScript code instead of just the SQL. Here's the correct SQL ONLY version:

✅ CORRECTED SQL SCRIPT - COPY THIS ONE

IMPORTANT: Copy ONLY the code in the black box below (SQL only, no JavaScript!)

  1. 1️⃣ Click "COPY SQL" button below
  2. 2️⃣ Go to Supabase → SQL Editor → New Query
  3. 3️⃣ Paste the SQL
  4. 4️⃣ Click RUN
-- ============================================
-- NEYATECH DATABASE SCHEMA - SQL ONLY
-- ============================================

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TYPE user_type AS ENUM ('owner', 'volunteer', 'admin');
CREATE TYPE intention_status AS ENUM ('pending', 'accepted', 'in_progress', 'completed', 'cancelled');
CREATE TYPE intention_category AS ENUM ('prayer', 'umrah', 'charity', 'holy_sites', 'zamzam', 'quran');
CREATE TYPE proof_type AS ENUM ('photo', 'video', 'document');

CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    clerk_user_id VARCHAR(255) UNIQUE,
    email VARCHAR(255) UNIQUE NOT NULL,
    full_name VARCHAR(255) NOT NULL,
    phone VARCHAR(50),
    user_type user_type NOT NULL,
    profile_image VARCHAR(500),
    location VARCHAR(255),
    bio TEXT,
    is_verified BOOLEAN DEFAULT FALSE,
    rating DECIMAL(3,2) DEFAULT 0.00,
    total_reviews INTEGER DEFAULT 0,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE intentions (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    owner_id UUID REFERENCES users(id) ON DELETE CASCADE,
    title VARCHAR(255) NOT NULL,
    description TEXT NOT NULL,
    category intention_category NOT NULL,
    location VARCHAR(255) NOT NULL,
    status intention_status DEFAULT 'pending',
    deadline TIMESTAMP,
    cost DECIMAL(10,2) DEFAULT 0.00,
    image_url VARCHAR(500),
    views_count INTEGER DEFAULT 0,
    volunteer_id UUID REFERENCES users(id) ON DELETE SET NULL,
    accepted_at TIMESTAMP,
    completed_at TIMESTAMP,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE proof_submissions (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    intention_id UUID REFERENCES intentions(id) ON DELETE CASCADE,
    volunteer_id UUID REFERENCES users(id) ON DELETE CASCADE,
    proof_type proof_type NOT NULL,
    file_url VARCHAR(500) NOT NULL,
    description TEXT,
    is_approved BOOLEAN DEFAULT FALSE,
    submitted_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE reviews (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    intention_id UUID REFERENCES intentions(id) ON DELETE CASCADE,
    owner_id UUID REFERENCES users(id) ON DELETE CASCADE,
    volunteer_id UUID REFERENCES users(id) ON DELETE CASCADE,
    rating INTEGER CHECK (rating >= 1 AND rating <= 5) NOT NULL,
    comment TEXT,
    is_public BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE notifications (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    user_id UUID REFERENCES users(id) ON DELETE CASCADE,
    type VARCHAR(50) NOT NULL,
    title VARCHAR(255) NOT NULL,
    message TEXT NOT NULL,
    link VARCHAR(500),
    is_read BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE contact_messages (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) NOT NULL,
    phone VARCHAR(50),
    subject VARCHAR(255),
    message TEXT NOT NULL,
    is_read BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP DEFAULT NOW()
);

CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_type ON users(user_type);
CREATE INDEX idx_intentions_owner ON intentions(owner_id);
CREATE INDEX idx_intentions_volunteer ON intentions(volunteer_id);
CREATE INDEX idx_intentions_status ON intentions(status);
CREATE INDEX idx_intentions_category ON intentions(category);
CREATE INDEX idx_intentions_location ON intentions(location);
CREATE INDEX idx_proofs_intention ON proof_submissions(intention_id);
CREATE INDEX idx_proofs_volunteer ON proof_submissions(volunteer_id);
CREATE INDEX idx_reviews_volunteer ON reviews(volunteer_id);
CREATE INDEX idx_reviews_intention ON reviews(intention_id);
CREATE INDEX idx_notifications_user ON notifications(user_id);
CREATE INDEX idx_notifications_read ON notifications(is_read);

ALTER TABLE users ENABLE ROW LEVEL SECURITY;
ALTER TABLE intentions ENABLE ROW LEVEL SECURITY;
ALTER TABLE proof_submissions ENABLE ROW LEVEL SECURITY;
ALTER TABLE reviews ENABLE ROW LEVEL SECURITY;
ALTER TABLE notifications ENABLE ROW LEVEL SECURITY;
ALTER TABLE contact_messages ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Anyone can view user profiles" ON users FOR SELECT USING (true);
CREATE POLICY "Users can insert their own profile" ON users FOR INSERT WITH CHECK (true);
CREATE POLICY "Users can update own profile" ON users FOR UPDATE USING (true);

CREATE POLICY "Anyone can view pending intentions" ON intentions FOR SELECT USING (true);
CREATE POLICY "Users can create intentions" ON intentions FOR INSERT WITH CHECK (true);
CREATE POLICY "Users can update intentions" ON intentions FOR UPDATE USING (true);

CREATE POLICY "Users can view proofs" ON proof_submissions FOR SELECT USING (true);
CREATE POLICY "Volunteers can upload proofs" ON proof_submissions FOR INSERT WITH CHECK (true);

CREATE POLICY "Anyone can view public reviews" ON reviews FOR SELECT USING (is_public = true);
CREATE POLICY "Users can create reviews" ON reviews FOR INSERT WITH CHECK (true);

CREATE POLICY "Users can view notifications" ON notifications FOR SELECT USING (true);
CREATE POLICY "System can create notifications" ON notifications FOR INSERT WITH CHECK (true);
CREATE POLICY "Users can update notifications" ON notifications FOR UPDATE USING (true);

CREATE POLICY "Anyone can create contact messages" ON contact_messages FOR INSERT WITH CHECK (true);
CREATE POLICY "Admins can view contact messages" ON contact_messages FOR SELECT USING (true);

INSERT INTO users (email, full_name, user_type, location, bio, rating, total_reviews) VALUES
('[email protected]', 'Fatima Ahmed', 'volunteer', 'Madinah, Saudi Arabia', 'Certified volunteer helping fulfill intentions', 4.9, 38),
('[email protected]', 'Ahmed Mohamed', 'owner', 'Dubai, UAE', 'Seeking righteous people to fulfill my intentions', 0, 0),
('[email protected]', 'Omar Youssef', 'volunteer', 'Makkah, Saudi Arabia', 'Performing Umrah and good deeds', 4.8, 24),
('[email protected]', 'Admin User', 'admin', 'Riyadh, Saudi Arabia', 'Platform administrator', 0, 0);

INSERT INTO intentions (owner_id, title, description, category, location, status, cost) VALUES
((SELECT id FROM users WHERE email = '[email protected]'), 'Umrah for Deceased Father', 'Please perform a complete Umrah and dedicate the reward to my late father', 'umrah', 'Makkah', 'pending', 0),
((SELECT id FROM users WHERE email = '[email protected]'), 'Prayer at the Prophet''s Grave', 'Visit the Prophet''s grave and send greetings on my behalf', 'holy_sites', 'Madinah', 'pending', 0),
((SELECT id FROM users WHERE email = '[email protected]'), 'Distribute Meals to the Poor', 'Feed 20 fasting people during Ramadan in Makkah', 'charity', 'Makkah', 'pending', 200);

INSERT INTO reviews (intention_id, owner_id, volunteer_id, rating, comment, is_public) VALUES
((SELECT id FROM intentions LIMIT 1), 
 (SELECT id FROM users WHERE email = '[email protected]'), 
 (SELECT id FROM users WHERE email = '[email protected]'), 
 5, 
 'May Allah reward you abundantly for your excellent work', 
 true);

After Running This Script, You Should See:

  • ✅ "Success. No rows returned" (this is NORMAL and GOOD!)
  • ✅ Or you might see some notices about extensions (ignore them)
  • ✅ Go to Table Editor and verify 6 tables were created

Try Again with This Corrected SQL!

Click the green "COPY SQL" button above, paste it in Supabase SQL Editor, and run it. Then let me know the result!

Steps:

1️⃣ Click "COPY SQL" button above
2️⃣ Go to Supabase Dashboard
3️⃣ SQL Editor → New Query
4️⃣ Paste the SQL (Ctrl+V or Cmd+V)
5️⃣ Click "Run" button
6️⃣ Tell me "SUCCESS" or send error screenshot