Files
computer/supabase
zeekay c951278680 feat: Integrate Supabase backend for RFQ and Cluster requests
Add complete Supabase integration for data persistence and authentication:

Backend Setup:
- Created Supabase client configuration (src/lib/supabase.ts)
- Defined TypeScript interfaces for all database tables
- Implemented helper functions for RFQ and cluster request submission
- Added functions for customer data retrieval (quotes, orders, subscriptions)
- Added admin functions for managing all requests

Database Schema (supabase/schema.sql):
- 10 tables: users, rfqs, cluster_requests, quotes, orders, subscriptions,
  invoices, gpu_reservations, usage_records, admin_actions
- Row Level Security (RLS) policies for customer/admin access control
- Indexes for query performance
- Triggers for automatic timestamp updates
- Complete foreign key relationships

Security Features:
- RLS policies: Customers can only view their own data
- Admins can view and manage all data
- Anonymous users can submit RFQs and cluster requests
- Automatic timestamp management
- Secure credential storage

Form Integration:
- Request Quote page now submits to Supabase rfqs table
- Clusters page now submits to Supabase cluster_requests table
- Both forms include proper error handling and success messages
- Duration converted to months for database storage

Configuration:
- .env.example with Supabase URL and API key placeholders
- supabase/README.md with comprehensive setup instructions
- Project ID: fefkbezinxawrutwjdkq
- Region: us-east-1

Helper Functions:
- submitRFQ() - Submit request for quote
- submitClusterRequest() - Submit cluster inquiry
- getUserRFQs/Quotes/Orders/Subscriptions() - Customer data retrieval
- getAllRFQs/ClusterRequests() - Admin data retrieval
- updateRFQStatus/ClusterRequestStatus() - Admin workflow management

Next Steps:
1. Run schema.sql in Supabase SQL Editor
2. Configure environment variables in .env.local
3. Test RFQ and cluster request submissions
4. Build customer dashboard to view submitted requests
5. Build admin dashboard to manage requests and send quotes
2025-10-31 11:14:49 -07:00
..

Supabase Setup for Hanzo.Computer

This directory contains the database schema and setup instructions for the Hanzo.Computer leasing platform.

Database Information

Project ID: fefkbezinxawrutwjdkq
Region: us-east-1
Database URL: postgresql://postgres:[PASSWORD]@db.fefkbezinxawrutwjdkq.supabase.co:5432/postgres
Supabase URL: https://fefkbezinxawrutwjdkq.supabase.co

Setup Instructions

1. Initialize Database

  1. Go to Supabase SQL Editor: https://supabase.com/dashboard/project/fefkbezinxawrutwjdkq/sql
  2. Run the schema.sql file to create all tables and policies
  3. Verify tables are created in Table Editor

2. Configure Environment Variables

Copy .env.example to .env.local:

cp .env.example .env.local

Get your Supabase API keys:

  1. Go to Project Settings → API
  2. Copy the Project URL (already in .env.example)
  3. Copy the anon public key to VITE_SUPABASE_ANON_KEY

3. Test Database Connection

npm run dev

Try submitting an RFQ or cluster request to verify the connection.

Database Schema

Core Tables

  • users: User profiles (extends Supabase auth)
  • rfqs: Request for Quote submissions
  • cluster_requests: GPU cluster inquiries
  • quotes: Admin-generated quotes
  • orders: Accepted quotes or direct purchases
  • subscriptions: Recurring GPU leasing subscriptions
  • invoices: Generated invoices (Stripe or manual)
  • gpu_reservations: Provisioned GPU instances
  • usage_records: GPU usage tracking
  • admin_actions: Audit log for admin operations

Row Level Security (RLS)

All tables have RLS policies:

  • Customers can create RFQs/cluster requests and view their own data
  • Admins can view and manage all data
  • Anonymous users can submit RFQs (unauthenticated)

Admin Setup

To create an admin user:

  1. Sign up via the app (creates a customer user)
  2. In Supabase SQL Editor, run:
UPDATE public.users 
SET role = 'admin' 
WHERE email = '[email protected]';

API Functions

Helper functions in src/lib/supabase.ts:

Customer Functions:

  • submitRFQ() - Submit request for quote
  • submitClusterRequest() - Submit cluster inquiry
  • getUserRFQs() - Get user's RFQs
  • getUserQuotes() - Get user's quotes
  • getUserOrders() - Get user's orders
  • getUserSubscriptions() - Get user's subscriptions

Admin Functions:

  • getAllRFQs() - Get all RFQs (with optional status filter)
  • getAllClusterRequests() - Get all cluster requests
  • updateRFQStatus() - Update RFQ status
  • updateClusterRequestStatus() - Update cluster request status

Integration with Forms

Both RFQ and Clusters pages use Supabase for data persistence:

Request Quote (/request-quote):

  • Submits to rfqs table via submitRFQ()

Clusters (/clusters):

  • Submits to cluster_requests table via submitClusterRequest()

Next Steps

  1. ✅ Database schema created
  2. ✅ RLS policies configured
  3. ⏳ Create admin dashboard to view RFQs/cluster requests
  4. ⏳ Build quote generation workflow
  5. ⏳ Integrate Stripe for payments
  6. ⏳ Build customer dashboard

Troubleshooting

Connection errors:

  • Verify Supabase URL and anon key in .env.local
  • Check project is not paused in Supabase dashboard

RLS errors:

  • Verify policies are enabled: SELECT * FROM pg_policies WHERE tablename = 'rfqs';
  • Test with authenticated vs. unauthenticated requests

Missing tables:

  • Re-run schema.sql in SQL Editor
  • Check for SQL errors in execution logs