diff --git a/docker-compose.override.dev.yml b/docker-compose.override.dev.yml index f30a1eb3780..db1da0d9d7a 100644 --- a/docker-compose.override.dev.yml +++ b/docker-compose.override.dev.yml @@ -16,6 +16,10 @@ services: DD_ADMIN_PASSWORD: "${DD_ADMIN_PASSWORD:-admin}" DD_EMAIL_URL: "smtp://mailhog:1025" celeryworker: + build: + context: . + dockerfile: Dockerfile.django-${DEFECT_DOJO_OS:-debian} + target: development entrypoint: ['/wait-for-it.sh', '${DD_DATABASE_HOST:-postgres}:${DD_DATABASE_PORT:-5432}', '-t', '30', '--', '/entrypoint-celery-worker-dev.sh'] volumes: - '.:/app:z' @@ -24,12 +28,20 @@ services: DD_DEBUG: 'True' DD_EMAIL_URL: "smtp://mailhog:1025" celerybeat: + build: + context: . + dockerfile: Dockerfile.django-${DEFECT_DOJO_OS:-debian} + target: development volumes: - '.:/app:z' environment: PYTHONWARNINGS: error # We are strict about Warnings during development DD_DEBUG: 'True' initializer: + build: + context: . + dockerfile: Dockerfile.django-${DEFECT_DOJO_OS:-debian} + target: development volumes: - '.:/app:z' environment: diff --git a/dojo/db_migrations/max_migration.txt b/dojo/db_migrations/max_migration.txt new file mode 100644 index 00000000000..30e998c379d --- /dev/null +++ b/dojo/db_migrations/max_migration.txt @@ -0,0 +1 @@ +0257_pghistory_tags_backfill diff --git a/dojo/settings/settings.dist.py b/dojo/settings/settings.dist.py index f219c1c0db1..c0c92ddfad6 100644 --- a/dojo/settings/settings.dist.py +++ b/dojo/settings/settings.dist.py @@ -2061,6 +2061,14 @@ def saml2_attrib_map_format(din): MIDDLEWARE = ["debug_toolbar.middleware.DebugToolbarMiddleware", *MIDDLEWARE] +# Linear migrations for development +# Helps avoid merge migration conflicts by tracking the latest migration +if DEBUG: + INSTALLED_APPS = ( + "django_linear_migrations", # Must be before dojo to override makemigrations + *INSTALLED_APPS, + ) + def show_toolbar(request): return True diff --git a/readme-docs/CONTRIBUTING.md b/readme-docs/CONTRIBUTING.md index 27f8093355e..4c0b8a2210c 100644 --- a/readme-docs/CONTRIBUTING.md +++ b/readme-docs/CONTRIBUTING.md @@ -65,6 +65,19 @@ This will result in a new file in the `dojo/db_migrations` folder that can be co When making downstream database model changes in your fork of Defect Dojo please be aware of the risks of getting out of sync with our upstream migrations. It requiers proper knowledge of [Django Migrations](https://docs.djangoproject.com/en/5.0/topics/migrations/) to reconcile the migrations before you can upgrade to a newer version of Defect Dojo. +### Linear Migration History + +DefectDojo uses [django-linear-migrations](https://github.com/adamchainz/django-linear-migrations) to maintain a linear migration history and avoid merge migration conflicts. + +**What this means for you:** +- When you run `makemigrations`, a `max_migration.txt` file is automatically updated in `dojo/db_migrations/` +- This file tracks the latest migration and must be committed along with your migration file +- If you're working on a feature branch and migrations are added to `dev` branch, you may encounter a merge conflict in `max_migration.txt` + +**Resolving migration conflicts:** + +If you encounter a conflict in `dojo/db_migrations/max_migration.txt` during a rebase or merge, rename the migrations and update max_migrations.txt to contain the name of the latest migration of your branch. You can also try to use the `python manage.py rebase_migration dojo` inside the `uwsgi` container, but that requires some hassling with selective container startup and branch switching. + ## Submitting Pull Requests The following are things to consider before submitting a pull request to diff --git a/requirements-dev.txt b/requirements-dev.txt index d2a367fca58..802033bbae3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -13,3 +13,7 @@ parameterized==0.9.0 # Development file watching (hot reload) watchdog==6.0.0 + +# Migration management - allows for easy rebasing via manage.py rebase_migration +django-linear-migrations==2.19.0 +