mirror of
https://github.com/thecyberlearn/quantum-ai.git
synced 2026-08-18 10:52:58 +00:00
**Fixed Railway Startup Issues:** - Reorder commands: migrate before backup_users - Make backup_users handle missing tables gracefully - Add proper error handling for unmigrated databases - Check for table existence before querying users **Added Railway Setup Guide:** - Complete PostgreSQL configuration instructions - Environment variables template - Database verification commands - Troubleshooting steps for persistent storage **Key Issue Resolution:** - Railway using SQLite (ephemeral) instead of PostgreSQL - Users disappear because SQLite resets on each deployment - Need to add PostgreSQL database addon in Railway **Next Steps:** 1. Add PostgreSQL database in Railway dashboard 2. Verify DATABASE_URL environment variable 3. Deploy with persistent database 4. Create admin user via Railway console 🤖 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!