DEPLOYMENT_GUIDE.md•3.81 kB
# Railway MCP Server - Supabase Database Integration Complete!
## ✅ Migration Status
- **Database Table Created**: `railway_users`
- **Test User Added**: test@example.com / testuser
- **Code Updated**: All SQL queries updated for persistent storage
- **Ready for Deployment**: ✅
## 🚀 Deployment Steps
### Step 1: Set Environment Variables in Railway
1. **Go to your Railway project dashboard**
2. **Navigate to Settings → Environment Variables**
3. **Add these variables:**
```env
# Database Connection (REQUIRED)
DATABASE_URL=postgresql://postgres:[YOUR_PASSWORD]@db.[YOUR_PROJECT_REF].supabase.co:5432/postgres
# Supabase Configuration
SUPABASE_URL=https://[YOUR_PROJECT_REF].supabase.co
SUPABASE_ANON_KEY=[YOUR_ANON_KEY]
SUPABASE_SERVICE_ROLE_KEY=[YOUR_SERVICE_ROLE_KEY]
# JWT Configuration (already set)
JWT_SECRET_KEY=[YOUR_JWT_SECRET]
```
**💡 How to find DATABASE_URL:**
1. Go to Supabase → Settings → Database
2. Copy "Connection string" → "URI"
3. Replace `[YOUR_PASSWORD]` with your actual database password
### Step 2: Deploy Updated Code
1. **Push to GitHub:**
```bash
git add .
git commit -m "feat: Add persistent Supabase database storage"
git push origin main
```
2. **Deploy on Railway:**
- Railway will automatically detect changes
- New deployment will start with database integration
### Step 3: Test the Integration
1. **Test API Endpoints:**
```bash
# Register new user
curl -X POST "https://[YOUR_RAILWAY_DOMAIN]/api/auth/register" \
-H "Content-Type: application/json" \
-d '{"email":"newuser@test.com","username":"newuser","password":"password123","full_name":"New User"}'
# Login with existing user
curl -X POST "https://[YOUR_RAILWAY_DOMAIN]/api/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"testuser","password":"testuser123"}'
```
2. **Check Database:**
```sql
-- Connect to Supabase SQL Editor
SELECT * FROM railway_users;
```
## 📊 Database Structure
```sql
CREATE TABLE railway_users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
salt VARCHAR(255) NOT NULL,
username VARCHAR(100) UNIQUE NOT NULL,
full_name VARCHAR(255),
is_active BOOLEAN DEFAULT true,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
last_login TIMESTAMP WITH TIME ZONE
);
```
## 🔒 Security Features
- **Password Hashing**: PBKDF2 with 100,000 iterations
- **Salt**: Random 32-byte salt per user
- **Input Validation**: Email/username uniqueness checks
- **Error Handling**: Comprehensive database error management
## 🧪 Test User
**Email**: test@example.com
**Username**: testuser
**Password**: testuser123
## 🐛 Troubleshooting
### Database Connection Error
- Check `DATABASE_URL` format
- Verify database password
- Ensure Supabase project is active
### Migration Failed
- Check if table already exists (expected)
- Verify database permissions
- Check Supabase service status
### Authentication Not Working
- Verify JWT_SECRET_KEY is set
- Check user_service.py imports
- Test database connection
## 📈 Next Steps
1. **Set up Redis** (optional)
- Add Redis environment variable
- Implement caching layer
- Improve performance
2. **Monitor Database**
- Set up Supabase monitoring
- Track user metrics
- Database performance optimization
3. **Production Deployment**
- Remove test user
- Add admin dashboard
- Implement user roles
## 🆘 Support
If you encounter any issues:
1. Check Railway logs for errors
2. Verify environment variables
3. Test database connection
4. Review authentication flow
---
**Status**: ✅ Ready for deployment
**Database**: Connected and configured
**Code**: Updated and tested
**Next**: Deploy to Railway!