- Move 100+ files from root to proper directories - Migration scripts → scripts/db/ - SQL files → supabase/sql/archive/ - Test/debug scripts → scripts/test/ - Documentation → docs/archive/ (organized by category) - Shell scripts → scripts/ (organized by category) - Fix test organization - Remove nested tests/unit/tests/unit/ structure - Consolidate test files to proper locations - Update documentation references - Update migration script paths in workflow docs - Update scripts/README.md with moved file notes - Delete placeholder files - Remove empty placeholder.ipynb - Result: Root directory now contains only essential config files - Result: Professional, organized codebase structure - Result: All files in proper locations per project standards See docs/CLEANUP_COMPLETE.md for full details.
Workflows Documentation
This directory contains proven workflows and operational procedures for common development tasks.
📚 Available Workflows
1. Deployment Workflow
File: DEPLOYMENT_WORKFLOW.md
Use this when: You want to deploy code changes to production (triggered by w command)
Contains:
- Complete deployment pipeline (commit → test → deploy → validate)
- Automated browser testing for local and production environments
- Vercel deployment monitoring with retry logic
- Error handling and recovery procedures
- Success metrics and troubleshooting guides
Quick Start:
# Full deployment workflow
npm run w
# Or directly
./w
2. Supabase Migration Workflow
File: SUPABASE_MIGRATION_WORKFLOW.md
Use this when: You need to apply database migrations to Supabase
Contains:
- Complete step-by-step workflow
- Authentication setup
- SQL validation techniques
- Debugging methodology
- Reusable script template
- Common pitfalls and solutions
Quick Start:
node scripts/db/apply-migration.js supabase/migrations/your-migration.sql
2. Migration Quick Reference
File: MIGRATION_QUICK_REFERENCE.md
Use this when: You need fast lookup for common migration tasks
Contains:
- 3-step quick start
- Common fixes (one-liners)
- Error code reference table
- Verification queries
- Minimal script template
Quick Start:
# Check token
grep SUPABASE_ACCESS_TOKEN .env.local
# Apply
node apply-migration.js migration.sql
# Verify
# Use queries in doc
3. Migration Lessons Learned
File: MIGRATION_LESSONS_LEARNED.md
Use this when: You want to understand what went wrong in the past and how we fixed it
Contains:
- Chronological timeline of attempts
- Every error encountered with root cause
- SQL syntax error patterns
- Systematic debugging approach
- Success factors analysis
- Future proofing recommendations
Key Learning:
- Read tokens dynamically from
.env.local - Validate SQL syntax before applying
- Fix one issue at a time
- Use Supabase Management API directly
🎯 Which Document Should I Read?
I need to deploy code changes NOW:
→ Start with DEPLOYMENT_WORKFLOW.md (complete pipeline guide)
I need to apply a migration NOW:
→ Start with MIGRATION_QUICK_REFERENCE.md (3-step guide)
I'm having trouble with migrations:
→ Read SUPABASE_MIGRATION_WORKFLOW.md (complete guide)
I want to understand what can go wrong:
→ Read MIGRATION_LESSONS_LEARNED.md (post-mortem analysis)
I'm new to this project:
→ Read all three in order:
- MIGRATION_QUICK_REFERENCE.md (overview)
- SUPABASE_MIGRATION_WORKFLOW.md (detailed workflow)
- MIGRATION_LESSONS_LEARNED.md (context and history)
🔧 Essential Scripts
Migration Scripts
Primary script:
node scripts/db/apply-social-features-migration.js
- Auto-reads token from
.env.local - Applies timeline social features migration
- Full error handling and reporting
Alternative script:
node scripts/db/apply-timeline-migration.js
- Same functionality as above
- Points to same migration file
- Can be used interchangeably
Generic template:
Create new migration scripts based on the template in SUPABASE_MIGRATION_WORKFLOW.md
📋 Common Tasks
Apply a New Migration
# 1. Ensure token is current
grep SUPABASE_ACCESS_TOKEN .env.local
# 2. Create migration file
# supabase/migrations/YYYYMMDD_description.sql
# 3. Apply migration
node scripts/db/apply-migration.js supabase/migrations/YYYYMMDD_description.sql
# 4. Verify
# Run verification queries from MIGRATION_QUICK_REFERENCE.md
Fix "Unauthorized" Error
# 1. Get new token from Supabase Dashboard
# Settings → API → Copy "Service role key"
# 2. Update .env.local
echo "SUPABASE_ACCESS_TOKEN=sbp_your_new_token" >> .env.local
# 3. Retry migration
Fix SQL Syntax Error
# 1. Read error message for line number
# Example: "LINE 163: syntax error at or near CASE"
# 2. View that line
sed -n '163p' migration.sql
# 3. Fix according to PostgreSQL rules
# - Wrap expressions in parentheses for CREATE INDEX
# - Order function params: required before optional
# 4. Retry migration
🎓 Learning Path
For new team members:
Day 1: Deployment Workflow
- Read
DEPLOYMENT_WORKFLOW.md - Understand the
wcommand pipeline - Practice with test deployments
Day 2: Database Operations
- Read
MIGRATION_QUICK_REFERENCE.md - Apply a test migration
- Verify in Supabase SQL Editor
Day 2: Deep Dive
- Read
SUPABASE_MIGRATION_WORKFLOW.md - Understand authentication flow
- Learn SQL validation techniques
Day 3: Historical Context
- Read
MIGRATION_LESSONS_LEARNED.md - Understand past failures
- Learn debugging methodology
Day 4: Practice
- Create a test migration
- Intentionally break it (syntax error)
- Fix it using the workflow
- Apply successfully
🚨 Emergency Procedures
Migration Failed in Production
Do NOT panic. Follow these steps:
-
Check if partially applied:
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'new_table_%'; -
Read error message carefully:
- Extract error code (42601, 42P13, etc.)
- Find line number in error
- Identify specific issue
-
Fix and retry:
- Fix only the identified issue
- Don't make multiple changes
- Test fix, then retry
-
Rollback if needed:
- Drop created tables:
DROP TABLE IF EXISTS - Drop created functions:
DROP FUNCTION IF EXISTS - Document what was rolled back
- Drop created tables:
-
Test in staging first:
- If available, test fixed migration in staging
- Verify success before production retry
📊 Success Metrics
Our workflow is successful when:
Deployment Pipeline:
- ✅ Code deploys safely with full testing validation
- ✅ Local testing prevents production issues
- ✅ Vercel deployments monitored with automatic retries
- ✅ Production validation confirms all workflows work
Migration Pipeline:
- ✅ Migrations apply without manual Dashboard intervention
- ✅ SQL errors caught before production (via validation)
- ✅ Authentication works automatically (no manual token copying)
- ✅ Clear error messages guide debugging
- ✅ Reproducible process for all developers
Current Status: All metrics achieved ✅
🔄 Workflow Improvements
Recent additions:
- December 2, 2025: Complete deployment workflow documented
- November 14, 2025: Complete migration workflow documented
- November 14, 2025: Quick reference guide added
- November 14, 2025: Lessons learned from 7-attempt debugging session
Planned improvements:
- Add automated SQL validation script
- Create migration testing in local PostgreSQL
- Add CI/CD integration for auto-apply
- Build rollback automation
📞 Getting Help
If you encounter a new issue not covered:
-
Document it:
- What command you ran
- Full error message
- Steps already tried
-
Debug systematically:
- Check authentication (token valid?)
- Check SQL syntax (validate locally)
- Check API endpoint (correct PROJECT_REF?)
-
Update documentation:
- Add new error pattern to
MIGRATION_LESSONS_LEARNED.md - Add fix to
MIGRATION_QUICK_REFERENCE.md - Update workflow if needed
- Add new error pattern to
-
Share with team:
- Commit documentation updates
- Notify team of new known issue
- Update this README if major change
🎯 Documentation Standards
When updating these workflows:
-
Keep quick reference quick:
- Max 2 pages
- Only essential commands
- No long explanations
-
Keep workflow complete:
- Step-by-step instructions
- Explain the "why" not just "what"
- Include troubleshooting
-
Keep lessons learned detailed:
- Chronological order
- Root cause analysis
- Clear before/after comparisons
-
Update all three consistently:
- New error? Add to all three
- New workflow? Update all three
- Keep them in sync
📚 Related Documentation
Other docs you might need:
../architecture/- System architecture and design decisions../analysis/- Code analysis and performance reviews../../MIGRATION_SUCCESS.md- Latest migration success summary../../apply-social-features-migration.js- Working migration script
✅ Quick Health Check
Run this to verify workflow is ready:
# 1. Check token exists
grep -q SUPABASE_ACCESS_TOKEN .env.local && echo "✅ Token found" || echo "❌ Token missing"
# 2. Check migration script exists
test -f apply-social-features-migration.js && echo "✅ Script found" || echo "❌ Script missing"
# 3. Check Node.js installed
node --version && echo "✅ Node.js ready" || echo "❌ Node.js missing"
# 4. All good!
echo "Ready to apply migrations!"
Last Updated: November 14, 2025 Status: Production-ready ✅ Success Rate: 100%