This document provides comprehensive instructions for migrating the Elriel application from SQLite to Supabase and deploying it to a hosting platform.
- Setting Up Supabase
- Configuring Your Environment
- Creating Supabase Tables
- Running the Migration Script
- Converting Your Application Code
- Deployment Options
- Troubleshooting
-
Create a Supabase Account:
- Go to https://supabase.com/ and sign up for a free account
- Create a new project with a name like "elriel"
- Wait for the database to be created (1-2 minutes)
-
Get Your API Credentials:
- Navigate to Project Settings > API in the Supabase dashboard
- Note down:
- Project URL (
https://[your-project-id].supabase.co) - API Key (anon public key for client access)
- Service Role Key (for migration and admin operations)
- Project URL (
-
Update Your .env File:
# Supabase configuration SUPABASE_URL=your_supabase_url SUPABASE_KEY=your_supabase_anon_key SUPABASE_SERVICE_KEY=your_supabase_service_key -
Install Required Packages:
npm install @supabase/supabase-js pg
You have two options for creating tables:
-
Go to the "Table Editor" in the Supabase dashboard
-
Click "Create a new table"
-
Create tables matching your SQLite schema:
users table:
- id (serial, primary key)
- username (text, unique, not null)
- password (text, not null)
- email (text, unique, not null)
- created_at (timestamptz, default now())
- last_login (timestamptz)
- is_admin (integer, default 0)
- status (text, default 'active')
Continue creating all tables according to your init.js schema.
- Go to the "SQL Editor" in the Supabase dashboard
- Create a new query and paste the SQL schema from the SQL file provided in this repository
-
Make sure your Supabase environment is set up:
- Verify your .env file has the correct Supabase credentials
- Ensure all tables have been created in Supabase
-
Run the Migration:
npm run migrate-to-supabase
-
Monitor the Output:
- The script will show progress for each table migration
- If any errors occur, they will be displayed in the console
You'll need to update your route files to use Supabase instead of SQLite. We've provided two example conversions:
routes/auth_supabase.js- Shows how to convert authentication routesroutes/feed_supabase.js- Shows how to convert feed/posts routes
Key differences to note:
Supabase queries are Promise-based rather than synchronous like SQLite:
// Old SQLite code
const user = db.prepare('SELECT * FROM users WHERE username = ?').get(username);
// New Supabase code
const { data: user, error } = await supabase
.from('users')
.select('*')
.eq('username', username)
.single();Your route handlers need to be async functions:
// Old
router.get('/profile', (req, res) => { ... });
// New
router.get('/profile', async (req, res) => { ... });Supabase can handle relationships in a single query:
const { data: posts } = await supabase
.from('posts')
.select(`
*,
users:user_id (username),
glyphs:glyph_id (svg_data)
`)Once your application is migrated to Supabase, you can deploy it to various platforms:
- Create a Render account at https://render.com/
- Connect your GitHub repository
- Create a new Web Service
- Configure the service:
- Build Command:
npm install - Start Command:
npm start - Environment Variables: Add your Supabase credentials
- Build Command:
- Deploy your application
- Set up a custom domain if you have one
- Create a Railway account at https://railway.app/
- Connect your GitHub repository
- Create a new project and select your repo
- Configure environment variables
- Deploy your application
- Create a Fly.io account
- Install the Fly CLI
- Run
fly launchin your project directory - Configure your app and deploy
-
Connection Errors:
- Verify your Supabase URL and API keys are correct in .env
- Check if your IP is allowed in Supabase
-
Database Errors:
- Ensure table schemas match exactly (case matters)
- Check for missing foreign key relationships
-
Migration Timeouts:
- For large datasets, try increasing batch sizes in the migration script
- Join the Supabase Discord community for help
- Check the Supabase documentation at https://supabase.com/docs
- For Elriel-specific questions, create an issue in the GitHub repository
Once your migration is complete, consider enhancing your application:
- Implement Supabase Auth for more secure authentication
- Set up Row Level Security (RLS) policies
- Configure database backups
- Add real-time features using Supabase's real-time capabilities