Files
hub/scripts/migration-check.sh
Jon Leopard c8987b1c95 feat: comprehensive test data setup and account type analysis
- Add complete test data seeders with business relationships
- Create BusinessFactory for generating test businesses
- Add foundation migrations for user_type and business tables
- Fix User model with name accessor for Filament compatibility
- Switch test suite from SQLite to PostgreSQL for production parity
- Document account type recommendations based on LeafLink model
- Create migration best practices and automation scripts
- Update seeders to use updateOrCreate for idempotent runs

Test accounts now available:
- nobusiness@example.com (no business attached)
- onebusiness@example.com (single business)
- multibusiness@example.com (multiple businesses)
- dispensary@example.com (retailer user)
- brand@example.com (brand user)

All test accounts use 'password' for authentication.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-21 09:10:28 -07:00

120 lines
3.0 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# migration-check.sh
# Pre-migration safety check script for Cannabrands
# Usage: ./scripts/migration-check.sh [environment]
set -e
ENV=${1:-local}
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
echo "🔍 Migration Safety Check - Environment: $ENV"
echo "============================================="
# Check if we're in the right directory
if [ ! -f "artisan" ]; then
echo "❌ Error: Not in Laravel project root"
exit 1
fi
# Check migration status
echo ""
echo "📊 Current Migration Status:"
php artisan migrate:status
# Show what will run
echo ""
echo "🚀 Migrations to Execute:"
PENDING=$(php artisan migrate --pretend)
if [ -z "$PENDING" ]; then
echo "✅ No pending migrations"
else
echo "$PENDING"
fi
# Environment-specific checks
case $ENV in
"production")
echo ""
echo "🏭 Production Environment Checks:"
# Create backup
echo "📦 Creating backup..."
BACKUP_FILE="backups/pre_migration_${TIMESTAMP}.sql"
mkdir -p backups
if command -v pg_dump &> /dev/null; then
pg_dump "${DB_DATABASE:-cannabrands_app}" > "$BACKUP_FILE"
echo "✅ Backup created: $BACKUP_FILE"
else
echo "⚠️ Warning: pg_dump not found. Please create manual backup!"
fi
# Verify backup
if [ -f "$BACKUP_FILE" ] && [ -s "$BACKUP_FILE" ]; then
echo "✅ Backup verified ($(du -h $BACKUP_FILE | cut -f1))"
else
echo "❌ Backup verification failed!"
exit 1
fi
;;
"staging")
echo ""
echo "🧪 Staging Environment Checks:"
echo "✅ Safe to test on staging data"
;;
"local")
echo ""
echo "💻 Local Environment Checks:"
echo "✅ Safe for local development"
;;
esac
# Test rollback capability (staging/local only)
if [ "$ENV" != "production" ]; then
echo ""
echo "🔄 Rollback Capability Check:"
# Get the last migration batch
LAST_BATCH=$(php artisan migrate:status | grep 'Y' | tail -1 | awk '{print $1}' || echo "none")
if [ "$LAST_BATCH" != "none" ]; then
echo "📋 Last migration batch rollback preview:"
php artisan migrate:rollback --pretend
else
echo " No migrations to rollback"
fi
fi
# Final checklist
echo ""
echo "✅ Pre-Migration Checklist:"
echo " 🔍 Migration status reviewed"
echo " 📝 SQL preview examined"
if [ "$ENV" = "production" ]; then
echo " 💾 Backup created and verified"
fi
if [ "$ENV" != "production" ]; then
echo " 🔄 Rollback capability confirmed"
fi
echo ""
echo "🚦 Ready to proceed with migration!"
echo ""
echo "Next steps:"
echo " php artisan migrate"
if [ "$ENV" = "production" ]; then
echo " # Monitor application health"
echo " # Verify key functionality"
fi
echo ""
echo "Emergency rollback (if needed):"
if [ "$ENV" = "production" ]; then
echo " psql cannabrands_app < $BACKUP_FILE"
else
echo " php artisan migrate:rollback"
fi