Skip to content

ci: warn when a migration would break the previous release during a rolling upgrade - #17150

Open
rossops wants to merge 3 commits into
devfrom
ci/migration-safety-check
Open

rossops wants to merge 3 commits into
devfrom
ci/migration-safety-check

Conversation

@rossops

@rossops rossops commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A rolling upgrade migrates the database first and replaces the running containers afterwards. For a while the previous release's code runs against the new schema. A migration that drops a column that code still selects, or adds a NOT NULL column its INSERTs don't name, breaks it for that window.

This adds a check that reads the migrations a PR adds or edits and says whether each one is additive, meaning the previous release can't tell the difference. When one isn't, the report says how to split the change across releases.

It only advises. The job stays green. Each finding is an annotation on the migration's line in the diff, and the run summary lists every migration with its verdict.

How it works:

  • scripts/check_migration_safety.py needs ast and git only. No Django, no database, about a second.
  • "The previous release" is origin/master. A table or column that no migration on master created is unknown to running code, so anything may be done to it.
  • These draw a warning: column-drop, table-drop, column-rename, table-rename, not-null-add, set-not-null, type-narrowing.
  • Cautions are notices. They mark what the file can't show: a data migration, hand-written SQL, an index built without CONCURRENTLY, a constraint or type change that scans the table.
  • A column drop split over two releases passes on its second half. Once the migration that removed the field from the model is on master, no running code reads the column and the drop is fine.
  • When breaking the old code is the decision, a comment on the line above the operation records it: # migration-safety: ok <rule> (<reason>). The warning for that one operation becomes a notice that carries the reason.

The workflow runs on PRs that touch dojo/db_migrations/, the script, its tests or the workflow itself. If we ever want a migration that is not additive to fail the job, dropping --advisory from the workflow does that. The job does fail when the check could not run at all, a missing git ref for example.

Test results

  • python3 -m unittest unittests.test_migration_safety: 74 tests pass. Sixteen of them build a throwaway git repository and skip where git isn't installed, which is the case in the unit-test image. The workflow runs the file on the runner, where git is, before it runs the check.

  • One of them replays every migration in dojo/db_migrations, so a shape the reader can't follow shows up as a test failure here and not as a crash on someone's PR.

  • ruff check --config ruff.toml with ruff 0.16.10: clean.

  • Run against 0316_system_settings_behaviour_settings, the one migration dev has that master doesn't: additive.

  • Run against throwaway migrations that drop finding.cwe and add a plain index on finding: the drop is reported as column-drop with the two-release advice, the index as a caution, and the exit status stays 0 with --advisory.

  • Each of the 318 migrations in dojo/db_migrations, judged as if it were new on its day, comes out the same before and after the second commit, which widens how hand-written SQL is read (DO blocks, a drop without the word COLUMN, a dropped default).

The workflow has run on this PR. On the runner all 74 tests ran, none skipped, and the check found no migration in the diff to judge.

Documentation

No docs change. The workflow's header and the script's docstring describe the rules and the acknowledgement comment, and each annotation carries its own advice.

Checklist

  • Based on dev, six commits behind its tip when opened.
  • Submitted against dev.
  • Meaningful PR title.
  • Ruff compliant.
  • No model change, so no migration.
  • Unit tests added.
  • Label: maintenance.

🤖 Generated with Claude Code

…olling upgrade

A rolling upgrade migrates the database first and replaces the running
containers afterwards, so for a while the previous release's code runs
against the new schema. scripts/check_migration_safety.py reads the
migrations a pull request adds or edits (ast and git only: no Django, no
database) and reports each operation that code cannot survive: a dropped
or renamed column or table, a NOT NULL column with no database default,
a column tightened under values it can still write. The report says how
to split the change across releases.

The Migration Safety workflow runs it on pull requests that touch a
migration. It is advisory: each finding is an annotation on the
migration's line and the job stays green. A migration records a
deliberate decision with `# migration-safety: ok <rule> (<reason>)`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@rossops rossops added this to the 3.6.0 milestone Dec 3, 2026
@dryrunsecurity

dryrunsecurity Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

DryRun Security

This pull request contains multiple critical findings where the user 'rossops' modified numerous sensitive codepaths, including authorization, API, and template files, without being on the allowed authors list.

🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/product/admin.py (drs_01ed295e)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/product/admin.py' matches configured sensitive codepath pattern 'dojo/product/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/simple_metrics.html (drs_06a9c6cb)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/simple_metrics.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/view_engineer.html (drs_0c423444)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/view_engineer.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/delete_product_api_scan_configuration.html (drs_0c7ed523)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/delete_product_api_scan_configuration.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/importers/default_reimporter.py (drs_108eacfc)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/importers/default_reimporter.py' matches configured sensitive codepath pattern 'dojo/importers/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/authorization/roles_permissions.py (drs_120eaa17)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/authorization/roles_permissions.py' matches configured sensitive codepath pattern 'dojo/authorization/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/forms.py (drs_240101c4)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/forms.py' matches configured sensitive codepath pattern 'dojo/forms.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/product/models.py (drs_24b71174)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/product/models.py' matches configured sensitive codepath pattern 'dojo/product/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/importers/base_importer.py (drs_318e9877)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/importers/base_importer.py' matches configured sensitive codepath pattern 'dojo/importers/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/dashboard-metrics.html (drs_4743c89c)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/dashboard-metrics.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/search/views.py (drs_48f6d88e)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/search/views.py' matches configured sensitive codepath pattern 'dojo/search/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/tool_config/factory.py (drs_499742eb)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/tool_config/factory.py' matches configured sensitive codepath pattern 'dojo/tool_config/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/importers/default_importer.py (drs_59c32f9b)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/importers/default_importer.py' matches configured sensitive codepath pattern 'dojo/importers/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/product.html (drs_5d7ea671)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/product.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/finding/helper.py (drs_663d4ba6)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/finding/helper.py' matches configured sensitive codepath pattern 'dojo/finding/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/view_product_api_scan_configurations.html (drs_677190e9)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/view_product_api_scan_configurations.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/edit_product_api_scan_configuration.html (drs_69b8a903)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/edit_product_api_scan_configuration.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/authorization/authorization.py (drs_6a0883c5)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/authorization/authorization.py' matches configured sensitive codepath pattern 'dojo/authorization/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/product/queries.py (drs_6d91ef23)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/product/queries.py' matches configured sensitive codepath pattern 'dojo/product/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/base.html (drs_74a789ac)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/base.html' matches configured sensitive codepath pattern 'dojo/templates/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/simple_search.html (drs_78eafa07)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/simple_search.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/authorization/query_registrations.py (drs_7cbe46d3)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/authorization/query_registrations.py' matches configured sensitive codepath pattern 'dojo/authorization/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/view_product_details.html (drs_809faf8c)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/view_product_details.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/importers/options.py (drs_82e0b7a0)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/importers/options.py' matches configured sensitive codepath pattern 'dojo/importers/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/authorization/url_permissions.py (drs_975470bd)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/authorization/url_permissions.py' matches configured sensitive codepath pattern 'dojo/authorization/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/db_migrations/0317_remove_api_scan_configuration.py (drs_980b4361)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/db_migrations/0317_remove_api_scan_configuration.py' matches configured sensitive codepath pattern 'dojo/db_migrations/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/pt_counts.html (drs_9880cfa9)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/pt_counts.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/authorization/api_permissions.py (drs_a327e5f1)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/authorization/api_permissions.py' matches configured sensitive codepath pattern 'dojo/authorization/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/metrics/views.py (drs_a5f16a18)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/metrics/views.py' matches configured sensitive codepath pattern 'dojo/metrics/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/test/models.py (drs_b21b742b)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/test/models.py' matches configured sensitive codepath pattern 'dojo/test/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/filters.py (drs_b5e1395d)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/filters.py' matches configured sensitive codepath pattern 'dojo/filters.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/view_test.html (drs_ba6c30fa)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/view_test.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/metrics.html (drs_bac86e90)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/metrics.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/models.py (drs_c4dcbb90)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/models.py' matches configured sensitive codepath pattern 'dojo/models.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/api_v2/prefetch/registrations.py (drs_ce6e25dd)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/api_v2/prefetch/registrations.py' matches configured sensitive codepath pattern 'dojo/api_v2/**/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/add_product_api_scan_configuration.html (drs_d7d14072)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/add_product_api_scan_configuration.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/api_v2/serializers.py (drs_f6d9df2b)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/api_v2/serializers.py' matches configured sensitive codepath pattern 'dojo/api_v2/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/api_v2/views.py (drs_fd60950a)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/api_v2/views.py' matches configured sensitive codepath pattern 'dojo/api_v2/*.py' and was modified by 'rossops' (commit 53a85b1) who is not in the allowed authors list.

We've notified @mtesauro.


Comment to provide feedback on these findings.

Report false positive: @dryrunsecurity fp [FINDING ID] [FEEDBACK]
Report low-impact: @dryrunsecurity nit [FINDING ID] [FEEDBACK]

Example: @dryrunsecurity fp drs_90eda195 This code is not user-facing

All finding details can be found in the DryRun Security Dashboard.

…ledgements

The check read hand-written SQL too loosely. A DO block was dropped as if
it were a function body, so a column or table drop inside one came out
additive. A drop without the word COLUMN was missed, NOT NULL was lost
behind the comma in numeric(10,2), and adding a column with a default and
then dropping the default by hand passed, though that is the sequence
not-null-add exists for. All four are read now.

An acknowledgement covered every operation of its rule in the file, so a
comment written for one column also covered the next one added to the
same migration. It now covers the operation on the next line of code and
nothing else, and one that covers nothing is reported.

--annotate-on puts the annotations on another file, for a caller that
checks migrations its own pull request does not hold.

The real-history test now reaches the rules for added and altered fields,
and the workflow header says the verdict can go stale in both directions.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant