# Scripts Cleanup Plan

Generated: 2025-11-05

## 📊 Summary
- **Total scripts**: ~90 files
- **Proposed to KEEP**: 30 files
- **Proposed to REMOVE**: 60 files
- **Space savings**: ~60% reduction

---

## ✅ KEEP - Core Deployment & Atomic Tools (7 files)

These are the atomic deployment system - ESSENTIAL for infrastructure:

```
_db-helper.sh              # Database helper atoms
_deploy-atoms.sh           # Atomic deployment tools
_deploy-molecules.sh       # Molecular deployment tools
_deploy-organisms.sh       # Organism deployment tools
deploy-dev.sh              # Deploy to dev server
deploy-production.sh       # Deploy to production server
conductor-setup.sh         # Deployment setup
```

---

## ✅ KEEP - Essential Database Operations (3 files)

Critical for data management:

```
backup-db.sh               # Current backup script (uses atomic tools)
restore-db.sh              # Current restore script (uses atomic tools)
compare-db.sh              # Compare local vs remote databases
```

---

## ✅ KEEP - Queue Management (5 files)

Essential for background job processing:

```
start-queue-worker.sh      # Start queue worker
queue-monitor.sh           # Monitor queue status
queue-worker-cron.sh       # Cron job for queue worker (server)
queue-worker-cron-LOCAL.sh # Cron job for queue worker (local)
queue-worker-monitor.sh    # Advanced queue monitoring
```

---

## ✅ KEEP - Development Environment (4 files)

Daily dev workflow scripts:

```
start-dev-servers.sh       # Start all dev services
start-local-dev-with-email.sh # Start dev + Mailpit
stop-local-dev.sh          # Stop all dev services
emergency-reset.sh         # Emergency environment reset
```

---

## ✅ KEEP - Health Checks & Validation (4 files)

Deployment verification and environment checks:

```
test-health-check.sh       # Health check testing
health-check-comprehensive.sh # Comprehensive health check
validate-dev-environment.sh # Validate dev environment
validate-environment.php   # PHP environment validation
```

---

## ✅ KEEP - Data Management & Utilities (4 files)

Useful operational tools:

```
clear-test-payment-data.php # Clear test payment data
fix-venue-template-ids.sh  # Fix venue template IDs
migrate-storage-to-public.sh # Storage migration tool
redis-manager.sh           # Redis operations
```

---

## ✅ KEEP - Documentation & Quick Reference (3 files)

Helpful utilities and docs:

```
QUICK_TEST_COMMANDS.sh     # Quick command reference
timestamp-docs.sh          # Documentation timestamping
diagnose-storage-symlink.sh # Storage symlink diagnostics
test-deploy.sh             # Deployment testing workflow
verify-backup-integrity.sh # Backup verification
README.md                  # Scripts documentation
```

---

## ✅ KEEP - Cron Jobs (2 files in /cron/)

Active cron monitoring scripts:

```
cron/email-deliverability-monitor.sh # Monitor email health
cron/queue-health-check.sh          # Monitor queue health
```

---

## ❌ REMOVE - Old/Backup MySQL Scripts (5 files)

Superseded by current unified scripts:

```
backup-db-mysql.sh         # Old MySQL-specific version
backup-db-mysql.sh.bak     # Backup file
compare-db-mysql.sh        # Old MySQL-specific version
compare-db-mysql.sh.bak    # Backup file
restore-db-mysql.sh        # Old MySQL-specific version
restore-db-mysql.sh.bak    # Backup file
```

**Why remove**: Current scripts (`backup-db.sh`, `restore-db.sh`, `compare-db.sh`) already handle MySQL

---

## ❌ REMOVE - One-Off Seeding/Data Scripts (7 files)

Temporary test data scripts - not needed on server:

```
seed-mohamed-abdo-event.sh  # One-off event seeding
seed-test-chargeback.sh     # One-off chargeback test
setup-test-data.php         # Test data setup
generate-test-tickets.php   # Test ticket generation
generate-test-metrics.php   # Test metrics generation
simulate-ticket-metrics.php # Metric simulation
fix-seat-rotations.php      # One-off rotation fix
```

**Why remove**: One-time use, can regenerate if needed

---

## ❌ REMOVE - Comprehensive Audit Scripts (8 files)

Extensive audit scripts - can regenerate when needed:

```
frontend-a11y-audit.sh      # Accessibility audit (23KB)
frontend-performance-audit.sh # Performance audit (16KB)
frontend-security-audit.sh   # Security audit (17KB)
security-audit-advanced.sh   # Advanced security audit (19KB)
security-audit-booking.sh    # Booking security audit (13KB)
security-audit.sh            # General security audit (8.9KB)
security-pentest.sh          # Penetration testing (13KB)
security-test-all.sh         # All security tests (9KB)
```

**Why remove**: Run occasionally, not daily. Can regenerate when needed. Save ~120KB.

---

## ❌ REMOVE - Load/Performance Test Scripts (6 files)

Specific performance testing - not for production server:

```
concurrent-booking-stress.sh # Concurrent booking stress test
run-load-tests.sh            # Load testing suite
run-payment-tests.sh         # Payment load tests
test-db-durability.sh        # Database durability test (14KB)
test-rate-limiting.sh        # Rate limiting tests
test-time-drift.sh           # Time drift testing
performance-gate-check.sh    # Performance gate checks
```

**Why remove**: Use proper load testing tools (k6, Artillery). These are too specific.

---

## ❌ REMOVE - Email Testing Scripts (8 files)

Keep one general email test, remove specific ones:

```
check-email-deliverability.sh   # Deliverability check
test-email-deliverability.sh    # Duplicate deliverability
test-email-system.sh            # KEEP THIS ONE (most general)
test-email-triggers-live.sh     # One-off trigger test
test-email-triggers.sh          # One-off trigger test
test-newsletter-template.sh     # One-off template test
test-newsletter-templates.sh    # One-off template test
test-password-reset-flow.sh     # One-off flow test
```

**Actually KEEP**: `test-email-system.sh` (most useful general test)
**Why remove others**: Too specific, can test manually or with PHPUnit

---

## ❌ REMOVE - API Testing Scripts (6 files)

Use PHPUnit instead of shell scripts for API testing:

```
run-api-tests.sh            # API test runner
test-admin-api.sh           # Admin API tests
test-customer-api.sh        # Customer API tests
test-critical-endpoints.sh  # Critical endpoint tests
test-phase1-live.sh         # Phase 1 live tests
test-phase1-simple.sh       # Phase 1 simple tests
```

**Why remove**: Better to use PHPUnit for API tests. More maintainable.

---

## ❌ REMOVE - CI/CD Scripts (2 files)

Not actively used in CI pipeline:

```
ci-cache-smoke-test.sh      # CI cache testing
ci-check-production-routes.sh # CI route checking
```

**Why remove**: Not integrated into CI/CD pipeline

---

## ❌ REMOVE - E2E Scripts (3 files)

Frontend handles E2E testing:

```
setup-e2e-comprehensive.sh  # E2E setup
setup-e2e.sh                # E2E setup
start-e2e-server.sh         # E2E server
```

**Why remove**: Frontend repo handles E2E with Playwright/Cypress

---

## ❌ REMOVE - JavaScript Test Files (6 files)

Should be in `tests/` directory, not `scripts/`:

```
assert-mix-matrix.js
assert-no-wp5-keys.js
size-budget.js
test-improved-seat-management.js
test-new-endpoints-simple.js
validate-holdseats-flow.js
```

**Why remove**: Move to proper test directory if needed, not in scripts

---

## ❌ REMOVE - One-Off Verification Scripts (4 files)

Temporary verification scripts:

```
verify-capacity-fix.sh      # One-off capacity fix verification
verify-mysql57-compatibility.sh # MySQL 5.7 compatibility check
test-real-chargeback.sh     # One-off chargeback test
test-queue-worker-monitor.sh # Queue worker monitoring test
```

**Why remove**: One-time verification, not needed ongoing

---

## ❌ REMOVE - Folders (3 directories)

```
archive/                    # Already archived old scripts
MBS_discovery/              # MBS discovery work (completed)
working/                    # Work in progress (duplicates exist)
```

**Why remove**:
- `archive/` - Already archived, contains old JS test files
- `MBS_discovery/` - Discovery work completed, not needed
- `working/` - Contains duplicates of files already in scripts/

---

## 🎯 Cleanup Commands

### Backup First (REQUIRED)
```bash
cd /Users/charlie/code/showprima
tar -czf scripts-backup-$(date +%Y%m%d).tar.gz scripts/
```

### Remove Old MySQL Scripts
```bash
rm scripts/backup-db-mysql.sh*
rm scripts/compare-db-mysql.sh*
rm scripts/restore-db-mysql.sh*
```

### Remove One-Off Data Scripts
```bash
rm scripts/seed-*.sh
rm scripts/setup-test-data.php
rm scripts/generate-test-*.php
rm scripts/simulate-ticket-metrics.php
rm scripts/fix-seat-rotations.php
```

### Remove Audit Scripts
```bash
rm scripts/frontend-*-audit.sh
rm scripts/security-audit*.sh
rm scripts/security-pentest.sh
rm scripts/security-test-all.sh
```

### Remove Load Test Scripts
```bash
rm scripts/concurrent-booking-stress.sh
rm scripts/run-load-tests.sh
rm scripts/run-payment-tests.sh
rm scripts/test-db-durability.sh
rm scripts/test-rate-limiting.sh
rm scripts/test-time-drift.sh
rm scripts/performance-gate-check.sh
```

### Remove Email Test Scripts (except test-email-system.sh)
```bash
rm scripts/check-email-deliverability.sh
rm scripts/test-email-deliverability.sh
rm scripts/test-email-triggers*.sh
rm scripts/test-newsletter-template*.sh
rm scripts/test-password-reset-flow.sh
```

### Remove API Test Scripts
```bash
rm scripts/run-api-tests.sh
rm scripts/test-admin-api.sh
rm scripts/test-customer-api.sh
rm scripts/test-critical-endpoints.sh
rm scripts/test-phase1-*.sh
```

### Remove CI/E2E Scripts
```bash
rm scripts/ci-*.sh
rm scripts/setup-e2e*.sh
rm scripts/start-e2e-server.sh
```

### Remove JS Test Files
```bash
rm scripts/assert-*.js
rm scripts/size-budget.js
rm scripts/test-*.js
rm scripts/validate-*.js
```

### Remove One-Off Verification
```bash
rm scripts/verify-capacity-fix.sh
rm scripts/verify-mysql57-compatibility.sh
rm scripts/test-real-chargeback.sh
rm scripts/test-queue-worker-monitor.sh
```

### Remove Folders
```bash
rm -rf scripts/archive/
rm -rf scripts/MBS_discovery/
rm -rf scripts/working/
```

---

## 📋 Final Scripts Directory Structure

After cleanup, you'll have ~30 essential scripts organized like:

```
scripts/
├── _db-helper.sh              # Atomic: DB helpers
├── _deploy-atoms.sh           # Atomic: Deployment atoms
├── _deploy-molecules.sh       # Atomic: Deployment molecules
├── _deploy-organisms.sh       # Atomic: Deployment organisms
├── backup-db.sh               # Database backup
├── restore-db.sh              # Database restore
├── compare-db.sh              # Database comparison
├── deploy-dev.sh              # Deploy to dev
├── deploy-production.sh       # Deploy to production
├── conductor-setup.sh         # Deployment setup
├── start-queue-worker.sh      # Start queue worker
├── queue-monitor.sh           # Monitor queue
├── queue-worker-cron.sh       # Queue cron (server)
├── queue-worker-cron-LOCAL.sh # Queue cron (local)
├── queue-worker-monitor.sh    # Queue monitoring
├── start-dev-servers.sh       # Start dev environment
├── start-local-dev-with-email.sh # Start dev + email
├── stop-local-dev.sh          # Stop dev environment
├── emergency-reset.sh         # Emergency reset
├── test-health-check.sh       # Health check test
├── health-check-comprehensive.sh # Comprehensive health
├── validate-dev-environment.sh # Validate dev env
├── validate-environment.php   # PHP env validation
├── clear-test-payment-data.php # Clear test data
├── fix-venue-template-ids.sh  # Fix venue templates
├── migrate-storage-to-public.sh # Storage migration
├── redis-manager.sh           # Redis operations
├── QUICK_TEST_COMMANDS.sh     # Quick reference
├── timestamp-docs.sh          # Doc timestamps
├── diagnose-storage-symlink.sh # Storage diagnostics
├── test-deploy.sh             # Test deployment
├── test-email-system.sh       # Email system test
├── verify-backup-integrity.sh # Verify backups
├── README.md                  # Documentation
└── cron/
    ├── email-deliverability-monitor.sh
    └── queue-health-check.sh
```

---

## ✅ Benefits

1. **Cleaner repository**: 60% fewer files
2. **Faster navigation**: Easier to find what you need
3. **Better organization**: Only essential, reusable scripts
4. **Server efficiency**: Less to sync, less storage
5. **Maintenance**: Fewer scripts to update/maintain

---

## ⚠️ Safety Notes

1. **Always backup first**: `tar -czf scripts-backup-$(date +%Y%m%d).tar.gz scripts/`
2. **Review before deleting**: Check if any scripts are referenced elsewhere
3. **Git history preserved**: Deleted files still in git history if needed
4. **Can regenerate**: Most removed scripts can be regenerated if needed
5. **Test after cleanup**: Run `./scripts/test-health-check.sh` to verify

---

## 🎯 Execution Plan

1. Review this plan
2. Create backup tarball
3. Execute removal commands (or use a script)
4. Test with `./scripts/test-health-check.sh`
5. Commit cleanup: `git add scripts/ && git commit -m "chore: cleanup scripts directory - remove 60 obsolete scripts"`
6. Push to dev branch
7. Sync to server

---

**Ready to proceed?** Review the KEEP list to make sure nothing critical is being removed.
