This guide explains how to migrate from the previous backend implementation to the new Supabase integration.
The application has been migrated from a custom backend to Supabase as the primary backend service. This change provides:
- Real-time database capabilities
- Built-in authentication
- Automatic API generation
- Row Level Security (RLS)
- Scalable infrastructure
- Removed: Custom API endpoints pointing to
dev.ryzer.app - Added: Supabase client integration
- Modified: Authentication flow to use Supabase Auth
- Updated: Data services to use Supabase database
- Added:
VITE_SUPABASE_URLandVITE_SUPABASE_ANON_KEYto.envfile - Removed: Previous API endpoint configurations
- Enhanced: Companies table with all form fields
- Enhanced: Assets table with category-specific fields
- Added: Related tables for board members, legal advisors, bank accounts
- Added: Related tables for asset locations and documents
-
companies - Main company information
CREATE TABLE companies ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), name VARCHAR(255) NOT NULL, registration_number VARCHAR(255), address TEXT, phone VARCHAR(20), email VARCHAR(255), website VARCHAR(255), industry VARCHAR(100), description TEXT, user_id UUID REFERENCES auth.users(id), -- Additional company fields pan_number VARCHAR(10), city VARCHAR(100), state VARCHAR(100), pincode VARCHAR(6), incorporation_type VARCHAR(50), instrument VARCHAR(50), llp_agreement_copy TEXT, moa TEXT, aoi TEXT, spv_memo TEXT, risk_disclosure TEXT );
-
assets - Asset information with category-specific fields
CREATE TABLE assets ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), name VARCHAR(255) NOT NULL, description TEXT, type VARCHAR(100), value DECIMAL(12, 2), location TEXT, status VARCHAR(50) DEFAULT 'active', company_id UUID REFERENCES companies(id), -- Asset-specific fields category VARCHAR(100), sub_category VARCHAR(100), stage VARCHAR(50), style VARCHAR(50), currency VARCHAR(10), instrument_type VARCHAR(50), class VARCHAR(50), about TEXT, -- Category-specific fields for all 8 asset categories -- Token information fields total_number_of_sfts INTEGER, price_per_sft DECIMAL(12, 2), expected_annual_return DECIMAL(5, 2), investment_horizon INTEGER );
-
Related Tables
company_board_members- Board member informationcompany_legal_advisors- Legal advisor informationcompany_bank_accounts- Bank account informationasset_locations- Nearby locations for assetsasset_documents- Media and documents for assets
// Old authentication using custom API
const response = await axios.post('https://api.fandora.app/api/auth/login', {
phone,
country_code
});// New authentication using Supabase
const { data, error } = await supabase.auth.signInWithOtp({
phone: `${country_code}${phone}`,
});- Replace all authentication calls with Supabase Auth methods
- Update session management to use Supabase session
- Modify protected routes to check Supabase auth state
- Update user profile handling to use Supabase user data
// Old API service
import api from '@/lib/httpClient';
export const createCompany = (body:any) => {
return api.post('company/create', {
...body
})
}// New Supabase service
import { supabase } from '@/lib/supabaseClient';
export const createCompany = async (companyData: any) => {
try {
const { data, error } = await supabase
.from('companies')
.insert([companyData])
.select();
if (error) throw new Error(error.message);
return { data, message: 'Company created successfully' };
} catch (error) {
throw error;
}
};- Replace API service calls with Supabase database operations
- Update data transformation logic to match new schema
- Handle related data (board members, documents, etc.) with separate table operations
- Update error handling to work with Supabase error format
All company form fields are now synchronized with the database schema:
- Company information fields map directly to
companiestable columns - Board member forms map to
company_board_memberstable - Legal advisor forms map to
company_legal_advisorstable - Bank account forms map to
company_bank_accountstable
All asset form fields are now synchronized with the database schema:
- Basic asset information maps to
assetstable columns - Category-specific fields map to corresponding columns in
assetstable - Location information maps to
asset_locationstable - Document information maps to
asset_documentstable
- Verify all form fields have corresponding database columns
- Update form submission handlers to use new service methods
- Ensure related data (arrays of objects) are properly handled
- Update form validation to match database constraints
Two test components are available to verify the integration:
-
Simple Test -
src/components/SupabaseTest.tsx- Basic authentication and CRUD operations
- Simple company and asset creation
-
Comprehensive Test -
src/components/SupabaseComprehensiveTest.tsx- Full authentication flow
- Complete company creation with related data
- Complete asset creation with category-specific fields
- Update and retrieval operations
- Run the development server:
npm run dev - Navigate to the test components
- Perform authentication
- Test company creation with all fields
- Test asset creation with category-specific fields
- Verify data persistence in Supabase dashboard
- RLS Permissions - Ensure Row Level Security policies are correctly configured
- Foreign Key Constraints - Verify related data references existing records
- Data Type Mismatches - Check that form data matches database column types
- Authentication State - Ensure proper session management in components
The migration to Supabase provides a more robust and scalable backend solution. The new implementation:
- Reduces backend complexity
- Provides real-time capabilities
- Improves data consistency
- Enhances security with built-in RLS
- Simplifies deployment and maintenance
For any issues during migration, refer to the Supabase documentation or contact the development team.