From 996dbc5aa8a1fe4a1337e4a153f91456361b26e3 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 9 Jul 2026 20:41:56 +1000 Subject: [PATCH] Adjust default behavior of "migrate" command (#12320) * Adjust default behavior of "migrate" command - Does not create new migration files automatically * Add dummy field - ensure detected by CI * Revert "Add dummy field - ensure detected by CI" This reverts commit e7a101fe8798456c573bb6479c7f6b554a33eb78. * Fix typo * Adjust contributing docs * Add CHANGELOG entry --- .github/workflows/check_translations.yaml | 4 +++- .github/workflows/qc_checks.yaml | 4 +++- CHANGELOG.md | 1 + CONTRIBUTING.md | 4 ++-- docs/docs/develop/contributing.md | 2 +- tasks.py | 9 ++++++--- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check_translations.yaml b/.github/workflows/check_translations.yaml index 2ce87a8c1d..1849cb63ac 100644 --- a/.github/workflows/check_translations.yaml +++ b/.github/workflows/check_translations.yaml @@ -46,4 +46,6 @@ jobs: run: | python ./.github/scripts/check_source_strings.py --frontend --backend - name: Check Migration Files - run: python3 .github/scripts/check_migration_files.py + run: | + invoke migrate --detect + python3 .github/scripts/check_migration_files.py diff --git a/.github/workflows/qc_checks.yaml b/.github/workflows/qc_checks.yaml index bc6aa64641..a5fd6ae8ae 100644 --- a/.github/workflows/qc_checks.yaml +++ b/.github/workflows/qc_checks.yaml @@ -405,7 +405,9 @@ jobs: - name: Test Translations run: invoke dev.translate - name: Check Migration Files - run: python3 .github/scripts/check_migration_files.py + run: | + invoke migrate --detect + python3 .github/scripts/check_migration_files.py - name: Coverage Tests run: invoke dev.test --check --coverage --translations - name: Upload raw coverage to artifacts diff --git a/CHANGELOG.md b/CHANGELOG.md index bd7c1a6be1..dbc38cfdda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking Changes +- [#12320](https://github.com/inventree/InvenTree/pull/12320) changes the default behavior of the `invoke migrate` command. Now, it no longer generates new migrations by default. Instead, it will only apply existing migrations to the database. If you want to detect and generate new migrations, you must now explicitly use the `--detect` flag. This change was made to prevent accidental generation of migrations when running the command, which could lead to unexpected changes in the database schema. Additionally, `invoke update` will no longer result in new migrations being generated, and will only apply existing migrations to the database. This change was made to ensure that the update process is predictable and does not introduce unexpected changes to the database schema. - [#12223](https://github.com/inventree/InvenTree/pull/12223) removes support for python 3.11 and stops providing packages for Debian 11 and Ubuntu 20.04. ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7b48b0db69..e9115615dc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -104,8 +104,8 @@ The project uses [Invoke](https://www.pyinvoketasks.com/) (`tasks.py`) as the ta # One-time setup: creates venv at dev/venv/, installs deps, sets up pre-commit hooks invoke dev.setup-dev -# Apply database migrations -invoke migrate +# Apply database migrations (and detect/create new migration files if required) +invoke migrate --detect # Create an admin account (required to log in) invoke superuser diff --git a/docs/docs/develop/contributing.md b/docs/docs/develop/contributing.md index 181ae3ab02..c27d1d5801 100644 --- a/docs/docs/develop/contributing.md +++ b/docs/docs/develop/contributing.md @@ -184,7 +184,7 @@ django-upgrade --target-version {{ config.extra.django_version }} `find . -name ## Migration Files -Any required migration files **must** be included in the commit, or the pull-request will be rejected. If you change the underlying database schema, make sure you run `invoke migrate` and commit the migration files before submitting the PR. +Any required migration files **must** be included in the commit, or the pull-request will be rejected. If you change the underlying database schema, make sure you run `invoke migrate --detect` and commit the migration files before submitting the PR. *Note: A github action checks for unstaged migration files and will reject the PR if it finds any!* diff --git a/tasks.py b/tasks.py index 388c43c192..6e086e2c30 100644 --- a/tasks.py +++ b/tasks.py @@ -1070,10 +1070,13 @@ def listbackups(c): }, ) @state_logger -def migrate(c, detect: bool = True, verbose: bool = False): - """Performs database migrations. +def migrate(c, detect: bool = False, verbose: bool = False): + """Performs database migrations. This is a critical step if the database schema has been altered. - This is a critical step if the database schema have been altered! + Arguments: + c: Command line context. + detect: Whether to detect and create new migrations based on changes to models. Default is False. + verbose: Whether to print verbose output from migration commands. Default is False. """ info('Running InvenTree database migrations...')