mirror of
https://github.com/thecyberlearn/quantum-ai-v2.git
synced 2026-08-18 12:52:59 +00:00
**PostgreSQL Development Setup:** - Update .env with PostgreSQL configuration options - Add comprehensive PostgreSQL setup guide (Docker + native) - Configure development-production database parity **Migration Conflict Resolution:** - Create fix_migrations command to handle Railway migration conflicts - Add reset_database command for clean development resets - Update Railway deployment with migration conflict handling - Add fake migration strategy for duplicate column errors **New Management Commands:** - `fix_migrations`: Diagnose and fix migration conflicts - `reset_database`: Clean reset of migrations and database - Support for both PostgreSQL and SQLite environments **Railway Deployment Fixes:** - Add migration conflict handling to railway.json - Use --fake-initial and --fake strategies for deployment - Better error recovery for existing schema conflicts **Developer Experience:** - Step-by-step PostgreSQL setup (Docker option for easy setup) - Migration troubleshooting guide - Development workflow documentation - Local-production environment matching **Fixes Railway Issue:** - Resolves "column data_file already exists" error - Handles existing database schema gracefully - Prevents future migration conflicts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4.2 KiB
4.2 KiB
Railway Deployment Setup Guide
Current Issue: SQLite Database (Ephemeral)
Your Railway deployment is currently using SQLite, which is ephemeral and loses all data on every deployment. This is why your users disappear.
Solution: Add PostgreSQL Database
Step 1: Add PostgreSQL to Railway Project
- Go to your Railway project dashboard
- Click "New" → "Database" → "Add PostgreSQL"
- Railway will automatically create a PostgreSQL database
- Railway will automatically set the
DATABASE_URLenvironment variable
Step 2: Verify Environment Variables
After adding PostgreSQL, check that these environment variables are set in Railway:
Required Variables:
DATABASE_URL- Should be automatically set by Railway PostgreSQL addonSECRET_KEY- Set to a secure random stringDEBUG- Set toFalsefor productionALLOWED_HOSTS- Set tonetcop.up.railway.app,*.railway.appCSRF_TRUSTED_ORIGINS- Set tohttps://netcop.up.railway.app
API Keys:
OPENWEATHER_API_KEY- Your OpenWeather API keySTRIPE_SECRET_KEY- Your Stripe secret keySTRIPE_WEBHOOK_SECRET- Your Stripe webhook secretNEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY- Your Stripe publishable key
Webhook URLs:
N8N_WEBHOOK_DATA_ANALYZER- Your N8N webhook URLN8N_WEBHOOK_JOB_POSTING- Your N8N webhook URLN8N_WEBHOOK_SOCIAL_ADS- Your N8N webhook URL
Step 3: Deploy with PostgreSQL
Once PostgreSQL is added:
- Your next deployment will use PostgreSQL
- The database will persist between deployments
- Users and data will be preserved
Step 4: Create Your Admin User
After successful deployment with PostgreSQL, create your admin user:
Option A: Use Railway Console
# In Railway project console, run:
python manage.py create_user your-email@example.com your-password --superuser --balance 100
Option B: Use Django Admin
# Create superuser via Railway console:
python manage.py createsuperuser
Database Verification Commands
Use these commands in Railway console to check database status:
# Check database info and user count
python manage.py backup_users --action info
# Create a new user with wallet balance
python manage.py create_user user@example.com password123 --balance 50.00
# Create admin user
python manage.py create_user admin@yoursite.com securepassword --superuser --balance 100
Environment Variables Template
Copy these to Railway environment variables:
# Django Core
SECRET_KEY=your-very-long-random-secret-key-here
DEBUG=False
ALLOWED_HOSTS=netcop.up.railway.app,*.railway.app
CSRF_TRUSTED_ORIGINS=https://netcop.up.railway.app
# Database (automatically set by Railway PostgreSQL addon)
DATABASE_URL=postgresql://...
# OpenWeather API
OPENWEATHER_API_KEY=your-openweather-api-key
# Stripe
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
# N8N Webhooks
N8N_WEBHOOK_DATA_ANALYZER=https://your-n8n.com/webhook/data-analyzer
N8N_WEBHOOK_JOB_POSTING=https://your-n8n.com/webhook/job-posting
N8N_WEBHOOK_SOCIAL_ADS=https://your-n8n.com/webhook/social-ads
Quick Fix Steps
- Add PostgreSQL database in Railway
- Wait for deployment to complete
- Run:
python manage.py backup_users --action info - Create your user:
python manage.py create_user your@email.com password --superuser --balance 100 - Test login at https://netcop.up.railway.app/auth/login/
Troubleshooting
If still using SQLite:
- Check that
DATABASE_URLenvironment variable is set in Railway - Restart the Railway app after adding PostgreSQL
- Check Railway logs for connection errors
If users still disappearing:
- Verify PostgreSQL addon is active
- Check Railway database tab shows PostgreSQL (not empty)
- Run database info command to verify connection
If login still fails:
- Check CSRF_TRUSTED_ORIGINS includes your Railway domain
- Verify ALLOWED_HOSTS includes your Railway domain
- Check browser network tab for CSRF errors
Expected Railway Logs (After PostgreSQL)
=== DATABASE INFO ===
Database Engine: django.db.backends.postgresql
Database Name: railway
Total Users: X
Superusers: 1
Key: Look for postgresql engine, not sqlite3!