Arunodoy18 opened a new pull request, #60012:
URL: https://github.com/apache/airflow/pull/60012
What does this PR do?
- Refactors the `0015_2_9_0_update_trigger_kwargs_type.py` migration script
to remove ORM model imports and usage
- Removes direct imports of `airflow.models.Trigger` from the migration
- Adds a pre-commit hook (`check-no-orm-in-migrations`) that prevents ORM
model imports in future Alembic migration scripts
- Adds explanatory comments about why the original ORM-based operations were
unnecessary
### Why is this needed?
Using ORM models directly in Alembic migration scripts causes issues when
the model schema changes. Specifically:
1. If a new column is added to the Trigger model in a future version (e.g.,
3.2.0)
2. The ORM reference in the 2.9.0 migration script will include that new
column
3. Downgrades from 3.2.X to ≤ 2.9.0 will fail with errors like:
\`\`\`
sqlalchemy.exc.ProgrammingError: column trigger.trigger_queue does not
exist
\`\`\`
This is a well-known anti-pattern in Alembic migrations. The general
recommendation is to use SQLAlchemy Core (table reflection) or raw SQL instead
of ORM models.
### How to test
1. Run the pre-commit hook: `python dev/check_no_orm_in_migrations.py`
2. Verify no ORM imports are detected in migration scripts
3. Test upgrade/downgrade scenarios:
\`\`\`bash
breeze shell 'airflow db reset --skip-init -y && airflow db migrate
--to-revision heads' \
--use-airflow-version 2.11.0 --airflow-extras pydantic --answer y \
&& breeze shell \"export
AIRFLOW__DATABASE__EXTERNAL_DB_MANAGERS=airflow.providers.fab.auth_manager.models.db.FABDBManager
\
&& airflow db migrate --to-revision heads \
&& airflow db downgrade -n 2.7.0 -y \
&& airflow db migrate\"
\`\`\`
### Related Issues
Fixes issue with Alembic migrations using ORM models that prevent future
schema changes." --base main --head fix/remove-orm-from-alembic-migrations
Closes: 59871
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]