Database connection: Check DATABASE_URL, Neon dashboard status, connection pool limits in server/db.tsMigrations: Run npm run migrate manually to debug. Check drizzle/migrations/ exists. Failures are logged but don’t block startup.Quiz errors: Ensure quiz_answers table exists (migrations). Verify learner has active lesson. Check browser console.Build errors:npx tsc --noEmit to check types. rm -rf client/dist server/dist to clear cache. TS_NODE_TRANSPILE_ONLY=true for deployment.Auth issues: Verify JWT_SECRET is set. Check token expiration. Parent users scoped to own learners only.
# Check if PostgreSQL is runningsudo systemctl status postgresql# orbrew services list | grep postgresql# Start PostgreSQLsudo systemctl start postgresql# orbrew services start postgresql@15# Test connectionpsql -U postgres -h localhost -c "SELECT version();"
# Verify connection string formatecho $DATABASE_URL# Should be: postgresql://user:pass@ep-xxx.region.aws.neon.tech/dbname# Test with psqlpsql "$DATABASE_URL" -c "SELECT current_database();"# Check Neon dashboard for project status# https://console.neon.tech/
# Get current DATABASE_URL from Railwayrailway variables# Test connectionrailway run psql $DATABASE_URL -c "SELECT 1;"# Check service status in Railway dashboard
// Increase pool sizeexport const pool = new Pool({ connectionString: DATABASE_URL, max: 20, // Increase from 10 idleTimeoutMillis: 30000, connectionTimeoutMillis: 5000, // Increase timeout});
Or close idle connections:
# Find idle connectionspsql $DATABASE_URL -c "SELECT pid, usename, state, query FROM pg_stat_activity WHERE state = 'idle';"# Kill idle connectionspsql $DATABASE_URL -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE state = 'idle' AND pid <> pg_backend_pid();"
Error: OpenRouter API request failed: 401 Unauthorized
Solution:
# Verify API keycurl https://openrouter.ai/api/v1/auth/key \ -H "Authorization: Bearer $OPENROUTER_API_KEY"# Should return: {"data":{"label":"..."}}# If invalid, get new key from:# https://openrouter.ai/keys# Update .envOPENROUTER_API_KEY="sk-or-v1-..."
{ "error": "Not authorized to view this learner's lessons"}
Cause: Learner doesn’t belong to parent.Solution:
# Check parent-child relationshippsql $DATABASE_URL -c \ "SELECT u.id, u.name, u.role, u.parent_id FROM users u WHERE u.role = 'LEARNER' ORDER BY u.parent_id;"# Fix parent_id if wrongpsql $DATABASE_URL -c \ "UPDATE users SET parent_id = (SELECT id FROM users WHERE username = 'parent_user') WHERE id = 123;"
Symptom: Lesson generation succeeds but contains “Lorem ipsum” or “[Placeholder]”.Cause: Validation not working properly.Solution:Check server/services/lesson-validator.ts:
// Should reject placeholdersconst placeholderPatterns = [ /lorem ipsum/i, /\[placeholder\]/i, /\[insert.*here\]/i, /\[TODO\]/i,];for (const pattern of placeholderPatterns) { if (pattern.test(content)) { throw new Error('Lesson contains placeholder content'); }}
# Check if learner has active lessonpsql $DATABASE_URL -c \ "SELECT id, learner_id, status, subject FROM lessons WHERE learner_id = 123 AND status = 'ACTIVE';"# Should return one row# If no results, create new lesson via UI or API
Symptom: API requests taking > 5 seconds.Debugging:
# Check database query performancepsql $DATABASE_URL -c "SELECT calls, mean_exec_time, query FROM pg_stat_statements ORDER BY mean_exec_time DESC LIMIT 10;"# Enable query logging (PostgreSQL)psql $DATABASE_URL -c "ALTER DATABASE sunschool SET log_statement = 'all';ALTER DATABASE sunschool SET log_duration = on;"
Solutions:
Add missing indexes:
CREATE INDEX idx_lessons_learner_status ON lessons(learner_id, status);CREATE INDEX idx_quiz_answers_learner_date ON quiz_answers(learner_id, answered_at DESC);
Optimize queries:
// Bad: N+1 query problemfor (const lesson of lessons) { const learner = await storage.getUser(lesson.learnerId);}// Good: Join or batch queryconst lessons = await db .select() .from(lessons) .leftJoin(users, eq(lessons.learnerId, users.id));