Move 9 init/seed scripts into scripts/seed/ and 7 validation scripts (+ validators/ subfolder) into scripts/validate/ to reduce clutter in the root scripts/ directory. Update all references across Makefile, CI/CD configs, pre-commit hooks, docs (~40 files), and Python imports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
236 lines
6.1 KiB
Markdown
236 lines
6.1 KiB
Markdown
# Makefile Refactoring - Implementation Complete ✅
|
|
|
|
**Date:** 2025-12-01
|
|
**Status:** ✅ COMPLETE
|
|
|
|
## Summary
|
|
|
|
Successfully refactored the Makefile to establish clear separation between **production initialization** and **demo data seeding**.
|
|
|
|
## Architecture Decision
|
|
|
|
### ✅ **Production vs Demo Separation**
|
|
|
|
**`init-prod`** - Production-safe platform initialization:
|
|
- ✅ Create admin user + platform alerts
|
|
- ✅ Initialize log settings
|
|
- ✅ Create CMS defaults (about, faq, etc.)
|
|
- ✅ Create platform pages and landing
|
|
- 🎯 Safe to run in production
|
|
- 🎯 Required for both production AND development
|
|
|
|
**`seed-demo`** - Development-only demo data:
|
|
- ✅ Create demo merchants (3)
|
|
- ✅ Create demo stores (1 per merchant)
|
|
- ✅ Create demo customers (15 per store)
|
|
- ✅ Create demo products (20 per store)
|
|
- ❌ NEVER run in production
|
|
- 🎯 For development/testing only
|
|
|
|
## Changes Made
|
|
|
|
### 1. Updated `init-prod` Command
|
|
|
|
**Before:**
|
|
```makefile
|
|
init-prod:
|
|
$(PYTHON) scripts/seed/init_production.py
|
|
```
|
|
|
|
**After:**
|
|
```makefile
|
|
init-prod:
|
|
@echo "🔧 Initializing production database..."
|
|
@echo "Step 1/4: Creating admin user and platform alerts..."
|
|
$(PYTHON) scripts/seed/init_production.py
|
|
@echo "Step 2/4: Initializing log settings..."
|
|
$(PYTHON) scripts/seed/init_log_settings.py
|
|
@echo "Step 3/4: Creating default CMS content pages..."
|
|
$(PYTHON) scripts/seed/create_default_content_pages.py
|
|
@echo "Step 4/4: Creating platform pages and landing..."
|
|
$(PYTHON) scripts/seed/create_platform_pages.py
|
|
@echo "✅ Production initialization completed"
|
|
```
|
|
|
|
### 2. Updated `db-setup` Workflow
|
|
|
|
**Before:**
|
|
```makefile
|
|
db-setup: migrate-up init-prod create-cms-defaults seed-demo
|
|
```
|
|
|
|
**After:**
|
|
```makefile
|
|
db-setup: migrate-up init-prod seed-demo
|
|
```
|
|
|
|
Now `init-prod` handles CMS defaults, so no separate step needed!
|
|
|
|
### 3. Updated `db-reset` Workflow
|
|
|
|
**Before:**
|
|
```makefile
|
|
db-reset: migrate-down migrate-up seed-demo-reset
|
|
```
|
|
|
|
**After:**
|
|
```makefile
|
|
db-reset: migrate-down migrate-up init-prod seed-demo-reset
|
|
```
|
|
|
|
Now properly re-initializes the platform after reset!
|
|
|
|
### 4. Added Utility Commands
|
|
|
|
```makefile
|
|
# Utility commands (usually not needed - init-prod handles these)
|
|
create-cms-defaults:
|
|
$(PYTHON) scripts/seed/create_default_content_pages.py
|
|
|
|
create-platform-pages:
|
|
$(PYTHON) scripts/seed/create_platform_pages.py
|
|
|
|
init-logging:
|
|
$(PYTHON) scripts/seed/init_log_settings.py
|
|
```
|
|
|
|
These are now available for advanced use cases or re-running specific steps.
|
|
|
|
### 5. Updated Help Documentation
|
|
|
|
Enhanced both `make help` and `make help-db` with:
|
|
- Clear separation between production and demo commands
|
|
- Step-by-step breakdown of what `init-prod` does
|
|
- Warning about NEVER running `seed-demo` in production
|
|
- Simplified workflow guidance
|
|
|
|
## Script Classification
|
|
|
|
### ✅ **Production Scripts** (Run in both prod + dev)
|
|
- `init_production.py` - Create admin user + alerts
|
|
- `init_log_settings.py` - Initialize logging configuration
|
|
- `create_default_content_pages.py` - CMS defaults (about, faq, etc.)
|
|
- `create_platform_pages.py` - Platform pages + landing
|
|
|
|
### 🎪 **Demo Scripts** (Development only)
|
|
- `seed_demo.py` - Create demo merchants, stores, products
|
|
|
|
### 🛠️ **Utility Scripts** (Manual/advanced use)
|
|
- `backup_database.py` - Database backups
|
|
- `verify_setup.py` - Verify configuration
|
|
- `create_inventory.py` - One-off inventory creation
|
|
- `create_landing_page.py` - One-off landing page creation
|
|
|
|
### 🧪 **Test/Diagnostic Scripts**
|
|
- `test_*.py` - Testing scripts
|
|
- `route_diagnostics.py` - Debug routing
|
|
- `validate_architecture.py` - Architecture validation
|
|
|
|
## New Developer Workflow
|
|
|
|
### Quick Start (One Command)
|
|
```bash
|
|
make db-setup
|
|
# Equivalent to:
|
|
# 1. make migrate-up
|
|
# 2. make init-prod (4 steps)
|
|
# 3. make seed-demo
|
|
```
|
|
|
|
### Manual Step-by-Step
|
|
```bash
|
|
make migrate-up # Apply database schema
|
|
make init-prod # Initialize platform (admin, CMS, logging, pages)
|
|
make seed-demo # Add demo data
|
|
make dev # Start development server
|
|
```
|
|
|
|
## Production Deployment Workflow
|
|
|
|
```bash
|
|
# Set production environment
|
|
export ENV=production
|
|
|
|
# Run migrations
|
|
make migrate-up
|
|
|
|
# Initialize platform (uses .env credentials)
|
|
make init-prod
|
|
|
|
# Create merchants via admin panel
|
|
# DO NOT run seed-demo!
|
|
```
|
|
|
|
## Benefits Achieved
|
|
|
|
### ✅ **Clear Separation of Concerns**
|
|
- Production setup clearly separated from demo data
|
|
- No confusion about what to run in production
|
|
|
|
### ✅ **Simplified Workflow**
|
|
- `init-prod` handles everything needed for platform setup
|
|
- No manual steps for CMS, logging, or platform pages
|
|
|
|
### ✅ **Better Documentation**
|
|
- Help text clearly explains each command
|
|
- Production vs development distinction is obvious
|
|
|
|
### ✅ **Consistent Experience**
|
|
- Same commands work for production and development
|
|
- Only difference is whether to run `seed-demo`
|
|
|
|
### ✅ **Maintainable**
|
|
- Individual scripts can still be run manually
|
|
- Utility commands available for advanced use cases
|
|
|
|
## Testing Performed
|
|
|
|
✅ Verified `make help` output is clear
|
|
✅ Verified `make help-db` output is detailed
|
|
✅ Confirmed `db-setup` workflow is correct
|
|
✅ Confirmed `db-reset` workflow is correct
|
|
|
|
## Next Steps
|
|
|
|
### Immediate
|
|
- [ ] Test `make init-prod` with fresh database
|
|
- [ ] Test `make db-setup` end-to-end
|
|
- [ ] Verify all 4 scripts in init-prod execute successfully
|
|
|
|
### Future Enhancements (Optional)
|
|
- [ ] Add inventory creation to `seed_demo.py`
|
|
- [ ] Add landing page creation to `seed_demo.py`
|
|
- [ ] Move utility scripts to `scripts/utils/` directory
|
|
- [ ] Add `--help` flag to individual Python scripts
|
|
|
|
## Files Modified
|
|
|
|
1. ✅ `Makefile` - Main changes
|
|
- Updated `init-prod` to run 4 steps
|
|
- Updated `db-setup` workflow
|
|
- Updated `db-reset` workflow
|
|
- Added utility commands
|
|
- Enhanced help documentation
|
|
|
|
## Validation
|
|
|
|
Run these commands to verify:
|
|
|
|
```bash
|
|
# Show help
|
|
make help
|
|
make help-db
|
|
|
|
# Test workflows (with fresh database)
|
|
make db-setup
|
|
make db-reset
|
|
```
|
|
|
|
## Conclusion
|
|
|
|
The Makefile now properly separates:
|
|
- **Platform initialization** (production-safe) → `init-prod`
|
|
- **Demo data** (development-only) → `seed-demo`
|
|
|
|
This architecture is clean, maintainable, and production-ready! 🎉
|