Skip to content

Add stairway test for DB migrations - #64905

Merged
jason810496 merged 5 commits into
apache:mainfrom
iting0321:stairway-test
Apr 29, 2026
Merged

Add stairway test for DB migrations#64905
jason810496 merged 5 commits into
apache:mainfrom
iting0321:stairway-test

Conversation

@iting0321

@iting0321 iting0321 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Adds a test that walks every incremental Alembic migration one step at a time upgrade → downgrade → re-upgrade to verify all migrations are fully reversible.

Why:

Silent breakage can occur when a downgrade forgets to drop a constraint/column added by its upgrade, or references something that doesn't exist. The existing test_database_schema_and_sqlalchemy_model_are_in_sync only checks the final state; it won't catch a broken intermediate step.

How to test:

uv run --project airflow-core pytest airflow-core/tests/unit/migrations/test_migration_utils.py -xvs

When a step fails, the error message includes the specific revision ID so the broken migration is immediately identifiable in CI logs.

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below) Claude Code following the guidelines

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for hardening the migration test.

Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated
Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new “stairway” unit test intended to validate that each Alembic migration step is reversible by performing upgrade → downgrade → re-upgrade per revision, starting from the squashed baseline revision.

Changes:

  • Introduces a helper to enumerate migration revisions in upgrade order after the squashed base.
  • Adds a parametrized migration test that runs upgrade/downgrade/re-upgrade for each revision.
  • Attempts to reduce parallel-test DB conflicts via an xdist_group marker.

Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated
Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated
Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated
Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated
@potiuk

potiuk commented Apr 9, 2026

Copy link
Copy Markdown
Member

Interesting idea. Can you please address the comments from copilot ?

@jason810496
jason810496 requested a review from Copilot April 9, 2026 09:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.

Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated
Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated
Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated
Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated
Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py
@iting0321

Copy link
Copy Markdown
Contributor Author

Interesting idea. Can you please address the comments from copilot ?

No problem, thank you for your feedback!

@kaxil
kaxil requested a review from Copilot April 10, 2026 19:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread airflow-core/tests/unit/migrations/test_migration_utils.py
@potiuk

potiuk commented Apr 27, 2026

Copy link
Copy Markdown
Member

@iting0321 A few things need addressing before review — see our Pull Request quality criteria.

  • Pre-commit / static checks: The Static checks job is failing. Static-check failures are deterministic and need a code fix — re-running CI won't help. Run prek run --from-ref main --stage pre-commit locally to reproduce, then push the fix.

No rush.


Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM for hardening the DB migration tests.

@jason810496
jason810496 merged commit 8a6a79f into apache:main Apr 29, 2026
77 checks passed
@boring-cyborg

boring-cyborg Bot commented Apr 29, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

seruman pushed a commit to seruman/airflow that referenced this pull request Apr 30, 2026
* add stairway tests for Airflow DB migrations to verify reversibility

* refactor migration stairway test to use _REVISION_HEADS_MAP for baseline and improve DB state management

* refactor stairway test to start from 3.0.0 revision and improve migration handling

* refactor stairway test failure handling to raise AssertionError for better clarity

* fix: add space in return statement for consistency in revision order

---------

Co-authored-by: iting0321 <iting0321@MacBook-11111156.local>
@jason810496 jason810496 added this to the Airflow 3.2.2 milestone May 2, 2026
potiuk pushed a commit to jason810496/airflow that referenced this pull request May 2, 2026
* add stairway tests for Airflow DB migrations to verify reversibility

* refactor migration stairway test to use _REVISION_HEADS_MAP for baseline and improve DB state management

* refactor stairway test to start from 3.0.0 revision and improve migration handling

* refactor stairway test failure handling to raise AssertionError for better clarity

* fix: add space in return statement for consistency in revision order

---------
(cherry picked from commit 8a6a79f)

Co-authored-by: iting0321 <137410100+iting0321@users.noreply.github.com>
Co-authored-by: iting0321 <iting0321@MacBook-11111156.local>
potiuk pushed a commit that referenced this pull request May 2, 2026
* add stairway tests for Airflow DB migrations to verify reversibility

* refactor migration stairway test to use _REVISION_HEADS_MAP for baseline and improve DB state management

* refactor stairway test to start from 3.0.0 revision and improve migration handling

* refactor stairway test failure handling to raise AssertionError for better clarity

* fix: add space in return statement for consistency in revision order

---------
(cherry picked from commit 8a6a79f)

Co-authored-by: iting0321 <137410100+iting0321@users.noreply.github.com>
Co-authored-by: iting0321 <iting0321@MacBook-11111156.local>
vatsrahul1001 pushed a commit that referenced this pull request May 20, 2026
* add stairway tests for Airflow DB migrations to verify reversibility

* refactor migration stairway test to use _REVISION_HEADS_MAP for baseline and improve DB state management

* refactor stairway test to start from 3.0.0 revision and improve migration handling

* refactor stairway test failure handling to raise AssertionError for better clarity

* fix: add space in return statement for consistency in revision order

---------
(cherry picked from commit 8a6a79f)

Co-authored-by: iting0321 <137410100+iting0321@users.noreply.github.com>
Co-authored-by: iting0321 <iting0321@MacBook-11111156.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants