#!/bin/bash
# Script to reset migrations and recreate database tables with UUID support
# WARNING: This will delete all data in the internet app tables!

echo "WARNING: This script will delete all data in the internet app tables!"
echo "Press Ctrl+C to cancel, or Enter to continue..."
read

# Activate virtual environment if it exists
if [ -d "venv" ]; then
    source venv/bin/activate
fi

# Drop the problematic tables
echo "Dropping existing tables..."
python manage.py shell << EOF
from django.db import connection
cursor = connection.cursor()
cursor.execute("DROP TABLE IF EXISTS internet_packages CASCADE;")
cursor.execute("DROP TABLE IF EXISTS merchants CASCADE;")
cursor.execute("DROP TABLE IF EXISTS payments CASCADE;")
print("Tables dropped successfully")
EOF

# Fake the initial migration as unapplied
echo "Resetting migration state..."
python manage.py migrate internet zero --fake

# Now run migrations again
echo "Running migrations with UUID support..."
python manage.py migrate

echo "Migrations completed successfully!"
echo "You can now run: python manage.py seed_data"

