# Supabase Migration Summary ## ✅ What Was Created ### 1. Documentation - **`SUPABASE_SETUP.md`** - Complete setup guide with step-by-step instructions - **`supabase/schema.sql`** - Full database schema with tables, indexes, RLS policies, and functions ### 2. Migration Script - **`scripts/migrate-to-supabase.ts`** - TypeScript script to migrate all data from SQLite to Supabase ### 3. New Supabase Client Code - **`src/lib/supabase/client.ts`** - Supabase client configuration - **`src/lib/supabase/database.types.ts`** - TypeScript types for database tables ### 4. Updated Server Modules - **`src/lib/server/auth.ts`** - Completely rewritten to use Supabase instead of SQLite - **`src/lib/server/taskDb.ts`** - Completely rewritten to use Supabase instead of SQLite ### 5. Environment Template - **`.env.local.example`** - Template for required environment variables ## 📊 Your Current Data - **2 users** → Will be migrated - **19 tasks** → Will be migrated - **3 projects** → Will be migrated - **3 sprints** → Will be migrated ## 🚀 Next Steps (In Order) ### Step 1: Create Supabase Project 1. Go to https://supabase.com/dashboard 2. Click "New Project" 3. Fill in details: - Name: `gantt-board` (or your choice) - Database Password: Generate a strong password - Region: Choose closest to you (e.g., `us-east-1`) 4. Wait for creation (~2 minutes) ### Step 2: Get Credentials 1. Go to **Project Settings** → **API** 2. Copy: - Project URL - `anon` public key - `service_role` secret key ### Step 3: Set Up Environment Variables ```bash cd /Users/mattbruce/Documents/Projects/OpenClaw/Web/gantt-board cp .env.local.example .env.local ``` Edit `.env.local` and fill in your actual Supabase credentials: ```bash NEXT_PUBLIC_SUPABASE_URL=https://your-project-ref.supabase.co NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key-here SUPABASE_SERVICE_ROLE_KEY=your-service-role-key-here ``` ### Step 4: Run the Database Schema 1. Go to Supabase Dashboard → **SQL Editor** 2. Click "New Query" 3. Copy contents of `supabase/schema.sql` 4. Click "Run" ### Step 5: Migrate Your Data ```bash cd /Users/mattbruce/Documents/Projects/OpenClaw/Web/gantt-board npx tsx scripts/migrate-to-supabase.ts ``` You should see output like: ``` 🚀 Starting SQLite → Supabase migration ✅ Connected to Supabase 📦 Migrating users... ✓ user@example.com ✅ Migrated 2 users 📦 Migrating sessions... ✅ Migrated X sessions ... ✅ Migration Complete! ``` ### Step 6: Test Locally ```bash npm run dev ``` Test all functionality: - Login/logout - Create/edit tasks - Create/edit projects - Create/edit sprints ### Step 7: Deploy to Vercel 1. Push code to git (the Supabase code is already in place) 2. Add environment variables in Vercel dashboard: - `NEXT_PUBLIC_SUPABASE_URL` - `NEXT_PUBLIC_SUPABASE_ANON_KEY` - `SUPABASE_SERVICE_ROLE_KEY` 3. Deploy! ## 🔐 Security Notes 1. **Never commit `.env.local`** - It's already in `.gitignore` 2. **Service Role Key** - Only used server-side, never expose to browser 3. **Row Level Security** - Enabled on all tables with appropriate policies 4. **Password Hashing** - Uses same scrypt algorithm as before ## 📁 Files Modified/Created ### New Files: - `SUPABASE_SETUP.md` - `supabase/schema.sql` - `scripts/migrate-to-supabase.ts` - `src/lib/supabase/client.ts` - `src/lib/supabase/database.types.ts` - `.env.local.example` ### Modified Files: - `package.json` - Added `@supabase/supabase-js` and `dotenv` - `src/lib/server/auth.ts` - Rewritten for Supabase - `src/lib/server/taskDb.ts` - Rewritten for Supabase ## 🔄 Rollback Plan If something goes wrong: 1. Keep your `data/tasks.db` file - it's untouched 2. You can revert the code changes with git: ```bash git checkout src/lib/server/auth.ts src/lib/server/taskDb.ts ``` 3. Remove Supabase env vars to fall back to SQLite ## ❓ Troubleshooting ### Migration fails with connection error - Check that your Supabase URL and keys are correct - Ensure your Supabase project is active (not paused) ### Data doesn't appear after migration - Check the migration script output for errors - Verify tables were created by checking Supabase Table Editor ### Auth issues after migration - Users will need to log in again (sessions aren't migrated by default) - Passwords are preserved - same login credentials work ## 🎉 You're All Set! Once you complete the steps above, your Gantt Board will be running on Supabase with: - ✅ Persistent data that survives server restarts - ✅ Works on Vercel (no file system dependencies) - ✅ Can scale to multiple servers - ✅ Real-time capabilities (future enhancement possible)