Skip to content

Commit 80a29ce

Browse files
Remove makemigrations from scripts (#11638)
* remove automatic make migrations * remove automatic make migrations * restore unit-tests.sh
1 parent bd613d1 commit 80a29ce

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

docker/entrypoint-initializer.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ initialize_data()
1616
python3 manage.py initialize_permissions
1717
}
1818

19-
create_announcement_banner()
19+
create_announcement_banner()
2020
{
2121
# Load the announcement banner
2222
if [ -z "$DD_CREATE_CLOUD_BANNER" ]; then
@@ -103,8 +103,26 @@ then
103103
exit 47
104104
fi
105105

106-
echo "Making migrations"
107-
python3 manage.py makemigrations dojo
106+
107+
python3 manage.py makemigrations --no-input --check --dry-run --verbosity 3 || {
108+
cat <<-EOF
109+
110+
********************************************************************************
111+
112+
You made changes to the models without creating a DB migration for them.
113+
114+
**NEVER** change existing migrations, create a new one.
115+
116+
If you're not familiar with migrations in Django, please read the
117+
great documentation thoroughly:
118+
https://docs.djangoproject.com/en/5.0/topics/migrations/
119+
120+
********************************************************************************
121+
122+
EOF
123+
exit 1
124+
}
125+
108126
echo "Migrating"
109127
python3 manage.py migrate
110128

@@ -139,7 +157,7 @@ fi
139157
if [ -z "${ADMIN_EXISTS}" ]
140158
then
141159
. /entrypoint-first-boot.sh
142-
160+
143161
create_announcement_banner
144162
initialize_data
145163
fi

docker/entrypoint-unit-tests-devDocker.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,25 @@ unset DD_CELERY_BROKER_URL
1818

1919
wait_for_database_to_be_reachable
2020

21-
python3 manage.py makemigrations dojo
21+
python3 manage.py makemigrations --no-input --check --dry-run --verbosity 3 || {
22+
cat <<-EOF
23+
24+
********************************************************************************
25+
26+
You made changes to the models without creating a DB migration for them.
27+
28+
**NEVER** change existing migrations, create a new one.
29+
30+
If you're not familiar with migrations in Django, please read the
31+
great documentation thoroughly:
32+
https://docs.djangoproject.com/en/5.0/topics/migrations/
33+
34+
********************************************************************************
35+
36+
EOF
37+
exit 1
38+
}
39+
2240
python3 manage.py migrate
2341

2442
# do the check with Django stack
@@ -56,10 +74,10 @@ echo "------------------------------------------------------------"
5674

5775
# Removing parallel and shuffle for now to maintain stability
5876
python3 manage.py test unittests -v 3 --keepdb --no-input --exclude-tag="non-parallel" || {
59-
exit 1;
77+
exit 1;
6078
}
6179
python3 manage.py test unittests -v 3 --keepdb --no-input --tag="non-parallel" || {
62-
exit 1;
80+
exit 1;
6381
}
6482

6583
# you can select a single file to "test" unit tests

docker/entrypoint-unit-tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ You made changes to the models without creating a DB migration for them.
6464
6565
If you're not familiar with migrations in Django, please read the
6666
great documentation thoroughly:
67-
https://docs.djangoproject.com/en/1.11/topics/migrations/
67+
https://docs.djangoproject.com/en/5.0/topics/migrations/
6868
6969
********************************************************************************
7070
@@ -82,8 +82,8 @@ echo "------------------------------------------------------------"
8282

8383
# Removing parallel and shuffle for now to maintain stability
8484
python3 manage.py test unittests -v 3 --keepdb --no-input --exclude-tag="non-parallel" || {
85-
exit 1;
85+
exit 1;
8686
}
8787
python3 manage.py test unittests -v 3 --keepdb --no-input --tag="non-parallel" || {
88-
exit 1;
88+
exit 1;
8989
}

docker/unit-tests.sh

100755100644
File mode changed.

readme-docs/CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ For changes that require additional settings, you can now use local_settings.py
6565
## Python3 Version
6666
For compatibility reasons, the code in dev branch should be python3.11 compliant.
6767

68+
## Database migrations
69+
When changes are made to the database model, a database migration is needed. This migration can be generated using something like
70+
`docker compose exec uwsgi bash -c "python manage.py makemigrations"`.
71+
This will result in a new file in the `dojo/db_migrations` folder that can be committed to `git`
72+
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.
73+
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.
6874

6975
## Submitting Pull Requests
7076

0 commit comments

Comments
 (0)