Generate raw SQL files from Django migrations for deployment reference. Use when the user wants SQL backup files before deploying migrations.
Generate raw SQL from Django migrations and save them as .sql files for deployment reference. These files are useful as a safety net in case something breaks during deployment.
There are two modes:
If the user specifies one or more migrations (e.g., shared 0150_customfield_soft_delete or a full path like app/shared/migrations/0150_customfield_soft_delete.py), use those directly. Extract <app_label> and <migration_name> (without .py) from the input.
If no specific migrations are given, find all migrations that are new compared to master:
git diff master --name-only -- '*.py' | grep '/migrations/' | grep -v '__pycache__'
Parse each result to extract <app_label> and <migration_name> (without .py).
If no new migrations are found, inform the user and stop.
Use docker compose exec to run sqlmigrate for each migration:
docker compose exec sytex bash -c "cd app && python manage.py sqlmigrate <app_label> <migration_name>"
IMPORTANT:
--settings sytex.settings-tests — use default settings (MySQL)uv run — run inside the Docker container directlyjust bash -c — it doesn't support passing -c to the container shellSave each SQL output to migrations_sql/<migration_name>.sql (relative to the project root).
Add a comment header to each file:
-- Migration: <app_label>.<migration_name>
Create the migrations_sql/ directory if it doesn't exist.
List all generated files with their paths.
For a migration at app/shared/migrations/0150_customfield_soft_delete.py:
docker compose exec sytex bash -c "cd app && python manage.py sqlmigrate shared 0150_customfield_soft_delete"
Saved to: migrations_sql/0150_customfield_soft_delete.sql
docker compose up -dmigrations_sql/ directory should be gitignored — these files are for local reference only