- Go to supabase.com
- Sign up/Login to your account
- Click "New project"
- Fill in project details:
- Name:
agricredit-production(or your preferred name) - Database Password: Choose a strong password (save this!)
- Region: Select the closest region to your users
- Name:
- Click "Create new project"
- Wait for project creation (usually 2-3 minutes)
- In your Supabase dashboard, go to Settings → Database
- Copy the Connection string (choose "URI" format)
- It should look like:
postgresql://postgres:[password]@db.[project-ref].supabase.co:5432/postgres - Update your
backend/.envfile with this connection string
- In your Supabase dashboard, go to SQL Editor
- Click "New query"
- Copy the entire content from
database_schema.sql - Paste it into the SQL Editor
- Click Run (or press Ctrl+Enter)
If Supabase reports RLS (Row Level Security) issues after deployment:
- Go to SQL Editor → "New query"
- Copy and run the content from
fix_rls_security.sql - This will enable RLS for all tables and add proper security policies
After running the schema, you should see:
✅ AgriCredit database schema deployed successfully!
📊 Created 17 tables with proper indexes and relationships
🔒 Enabled Row Level Security for data protection
📈 Created analytics views for dashboard
⚡ Enabled realtime subscriptions for key tables
👤 Inserted sample data for testing
If you want to use Supabase Auth instead of custom JWT:
- Go to Authentication → Settings
- Configure your site URL and redirect URLs
- Enable email confirmations if desired
- Update your frontend to use Supabase Auth client
The schema automatically enables realtime for key tables:
sensor_readingsnotificationsmarketplace_listingsloans
Run the test script to verify everything works:
cd backend
python3 test_db_connection.pyYou should see:
✅ Database connection successful!
📊 PostgreSQL version: 15.x
✅ Database write operations working!
🎉 Database connection test PASSED!
users- User profiles and authenticationnotifications- User notifications
sensor_devices- IoT device registrysensor_readings- Sensor data time series
loans- Loan applications and managementloan_repayments- Loan repayment trackingcredit_scores- AI-generated credit scoresyield_predictions- AI crop yield predictions
marketplace_listings- Agricultural product listings
carbon_credits- Carbon credit transactionsgovernance_proposals- DAO governance proposalsgovernance_votes- Governance voting recordsfarm_nfts- Farm NFT metadataharvest_records- NFT harvest tracking
liquidity_positions- Liquidity pool positionspool_rewards- Pool reward claimscross_chain_transactions- Cross-chain bridge transactions
climate_analyses- Climate impact analyses
- Row Level Security (RLS): Users can only access their own data
- Comprehensive RLS Policies: All 18 tables protected with proper access controls
- Multi-tenant Security: Isolated data access per user
- Admin Override: Administrative users can access all data
- Public Access: Marketplace and governance data available to all users
- Proper indexing: Optimized for query performance
- Foreign key constraints: Data integrity
- Enum types: Data validation at database level
user_stats- User activity metricssystem_stats- System-wide statistics
Update your .env file with the Supabase connection:
# Database
DATABASE_URL=postgresql://postgres:[YOUR_PASSWORD]@db.[YOUR_PROJECT_REF].supabase.co:5432/postgres
# Supabase (optional, for auth)
SUPABASE_URL=https://[YOUR_PROJECT_REF].supabase.co
SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key- Test the backend:
cd backend && python3 test_comprehensive.py - Start the backend:
cd backend && python -m uvicorn app.main:app --reload - Start the frontend:
cd src && npm run dev - Deploy smart contracts to testnet
- Configure monitoring (optional)
The database includes built-in analytics views. You can query:
-- User statistics
SELECT * FROM user_stats;
-- System statistics
SELECT * FROM system_stats;- Never commit database passwords to version control
- Use environment variables for all sensitive data
- Enable RLS policies (already done)
- Regular backups through Supabase dashboard
- Monitor query performance in Supabase dashboard
- Verify your DATABASE_URL is correct
- Check if your IP is allowlisted (Supabase allows all by default)
- Ensure SSL is enabled (it's automatic with Supabase)
- Re-run the SQL script in Supabase SQL Editor
- Check the Supabase logs for any errors
- Verify all extensions are enabled
- Check query performance in Supabase dashboard
- Add additional indexes if needed
- Consider Supabase Edge Functions for heavy computations
🎉 Your AgriCredit database is now deployed and ready for production!