-
Notifications
You must be signed in to change notification settings - Fork 84
Adding test to verify downgrades for new migrations #6873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
Adds automated testing for migration downgrades to ensure migrations can be safely reversed.
Key Changes:
- Implements
check_new_migrations_upgrade_downgrade()function that detects new migration files via git diff and tests their upgrade/downgrade functionality - Adds new CI job
Migration-Checksthat runs bothcheck_migrationsandcheck_migration_downgradein parallel - Separates migration checks from
Misc-Testsinto dedicated job for better organization
Critical Issue Found:
The logic in _test_migration_upgrade_downgrade() has a serious bug when testing multiple new migrations in sequence. After testing migration A, the database is left at revision A, but testing migration B expects the database to be at HEAD (revision B). This will cause the downgrade test for migration B to fail.
Confidence Score: 1/5
- This PR contains a critical logic error that will cause test failures when multiple migrations are added in sequence
- The migration downgrade testing logic has a critical bug that breaks when testing multiple sequential migrations. The test leaves the database in an incorrect state between iterations, causing subsequent tests to fail. This needs to be fixed before merging.
- src/fides/api/db/database.py requires immediate attention - the loop testing multiple migrations needs to restore database to HEAD after each iteration
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| .github/workflows/backend_checks.yml | 5/5 | Adds new Migration-Checks job to test migration downgrades separately, moves check_migrations from Misc-Tests to dedicated job for better organization |
| noxfiles/ci_nox.py | 5/5 | Adds check_migration_downgrade nox session, minor formatting improvement to tuple unpacking for consistency |
| src/fides/api/db/database.py | 1/5 | Adds migration downgrade testing logic with git-based detection; contains critical bug when testing multiple sequential migrations |
3 files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR adds automated testing for migration downgrades by introducing a new check_migration_downgrade nox command that:
- Detects new migrations via git diff against the target/base branch
- Tests each migration's upgrade and downgrade in sequence
- Integrates into CI via a new
Migration-Checksjob in the GitHub workflow
The implementation uses a two-phase approach: first downgrading through all new migrations (newest to oldest), then upgrading back (oldest to newest). This validates that migrations can be safely reversed and tests interactions between sequential migrations.
Key changes:
- Added
check_new_migrations_upgrade_downgrade()function and supporting helpers indatabase.py - Created
check_migration_downgradenox session inci_nox.py - Split migration checks into dedicated
Migration-Checksworkflow job (previously inMisc-Tests) - Matrix strategy runs both
check_migrationsandcheck_migration_downgradetests
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The code adds comprehensive testing for migration downgrades without modifying any production code paths. The implementation is well-structured with proper error handling, clear documentation, and logical flow. The sequential testing approach correctly validates migrations by downgrading through all new migrations and then upgrading back. All changes are additive (new test infrastructure) with no modifications to existing functionality.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| src/fides/api/db/database.py | 5/5 | Added comprehensive migration upgrade/downgrade testing that detects new migrations via git diff and validates them in sequence |
1 file reviewed, no comments
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (9.87%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #6873 +/- ##
==========================================
- Coverage 87.47% 87.29% -0.19%
==========================================
Files 523 523
Lines 34088 34169 +81
Branches 3916 3931 +15
==========================================
+ Hits 29820 29827 +7
- Misses 3412 3485 +73
- Partials 856 857 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
erosselli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool, let's send out a message in the eng channel about it so people know what the new CI check is :)
| print("No migrations need to be generated.") | ||
|
|
||
|
|
||
| def _get_base_branch_for_comparison() -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add # pragma: no cover to this function and the one below so they don't get counted for coverage reports?
|
Deployment failed with the following error: View Documentation: https://vercel.com/docs/two-factor-authentication |
Description Of Changes
Added a test to validate migration downgrades. A diff is generated against the target branch to determine the new migrations. The downgrade and upgrade steps are then tested for each migration.
Code Changes
nox -s check_migration_downgradecommandMigration-Checksstep to.github/workflows/backend_checks.ymlMigration-Checksis included in the backend checks summarySteps to verify
nox -s check_migration_downgradelocally. It will generate a diff againstmainand verify the migration in ENG-1704-identity-definition-modelsPre-Merge Checklist
CHANGELOG.mdupdatedmaindowngrade()migration is correct and works