diff --git a/install/install.py b/install/install.py index 9875685f7..6db4da790 100644 --- a/install/install.py +++ b/install/install.py @@ -2146,17 +2146,18 @@ password="%s" logging.InstallLog.writeToFile("Running Django migrations...") preFlightsChecks.stdOut("Running Django migrations...") - # Clean any existing migration files first (except __init__.py) + # Clean any existing migration files first (except __init__.py and excluding virtual environment) logging.InstallLog.writeToFile("Cleaning existing migration files...") - command = "find /usr/local/CyberCP -path '*/migrations/0*.py' -delete 2>/dev/null || true" + # Only delete migration files from app directories, not from lib/lib64/bin directories + command = "find /usr/local/CyberCP -type f -path '*/migrations/0*.py' ! -path '*/lib/*' ! -path '*/lib64/*' ! -path '*/bin/*' -delete 2>/dev/null || true" preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - # Clean any existing migration pyc files - command = "find /usr/local/CyberCP -path '*/migrations/*.pyc' -delete 2>/dev/null || true" + # Clean any existing migration pyc files (excluding virtual environment) + command = "find /usr/local/CyberCP -type f -path '*/migrations/*.pyc' ! -path '*/lib/*' ! -path '*/lib64/*' ! -path '*/bin/*' -delete 2>/dev/null || true" preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - # Clean __pycache__ directories in migrations folders - command = "find /usr/local/CyberCP -path '*/migrations/__pycache__' -type d -exec rm -rf {} + 2>/dev/null || true" + # Clean __pycache__ directories in migrations folders (excluding virtual environment) + command = "find /usr/local/CyberCP -type d -path '*/migrations/__pycache__' ! -path '*/lib/*' ! -path '*/lib64/*' ! -path '*/bin/*' -exec rm -rf {} + 2>/dev/null || true" preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) # Fix baseTemplate migrations - ensure required migration files exist @@ -2189,14 +2190,6 @@ password="%s" preFlightsChecks.stdOut("ERROR: No Python virtual environment found!", 0) return False - # Clean up old migration files before creating new ones (excluding virtual environment) - logging.InstallLog.writeToFile("Cleaning up old migration files...") - cleanup_command1 = 'find /usr/local/CyberCP -path "*/lib/*" -prune -o -path "*/lib64/*" -prune -o -path "*/bin/*" -prune -o -path "*/migrations/*.py" -not -name "__init__.py" -print -delete' - preFlightsChecks.call(cleanup_command1, self.distro, cleanup_command1, cleanup_command1, 1, 1, os.EX_OSERR) - - cleanup_command2 = 'find /usr/local/CyberCP -path "*/lib/*" -prune -o -path "*/lib64/*" -prune -o -path "*/bin/*" -prune -o -path "*/migrations/*.pyc" -print -delete' - preFlightsChecks.call(cleanup_command2, self.distro, cleanup_command2, cleanup_command2, 1, 1, os.EX_OSERR) - # Create all migrations at once - Django will handle dependencies logging.InstallLog.writeToFile("Creating fresh migrations for all apps...") command = f"{python_path} manage.py makemigrations --noinput"