[PATCH v4 1/8] settings: unify database connection variables
You-Sheng Yang
vicamo at gmail.com
Thu Dec 9 14:38:36 AEDT 2021
This changeset replaces all PW_TEST_DB_* with corresponding DATABASE_*
variables and fixes inconsistent DATABASE_PASS/DATABASE_PASSWORD usages.
Signed-off-by: You-Sheng Yang <vicamo at gmail.com>
---
.github/workflows/ci.yaml | 8 ++++----
docker-compose-pg.yml | 12 +++++------
docker-compose.yml | 10 +++++++---
docs/deployment/installation.rst | 4 ++--
docs/development/installation.rst | 13 ++++++------
lib/uwsgi/patchwork.ini | 2 +-
patchwork/settings/dev.py | 16 +++++++--------
...connection-variables-ac716f59ee7b8b48.yaml | 7 +++++++
tools/docker/entrypoint.sh | 20 +++++++++----------
tox.ini | 4 ++--
10 files changed, 53 insertions(+), 43 deletions(-)
create mode 100644 releasenotes/notes/settings-unify-database-connection-variables-ac716f59ee7b8b48.yaml
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index f4a33b3..59bc752 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -76,10 +76,10 @@ jobs:
- name: Run unit tests (via tox)
run: tox
env:
- PW_TEST_DB_TYPE: "${{ matrix.db }}"
- PW_TEST_DB_USER: "patchwork"
- PW_TEST_DB_PASS: "patchwork"
- PW_TEST_DB_HOST: "127.0.0.1"
+ DATABASE_TYPE: "${{ matrix.db }}"
+ DATABASE_USER: "patchwork"
+ DATABASE_PASSWORD: "patchwork"
+ DATABASE_HOST: "127.0.0.1"
docs:
name: Build docs
runs-on: ubuntu-latest
diff --git a/docker-compose-pg.yml b/docker-compose-pg.yml
index 44c49fb..8056d62 100644
--- a/docker-compose-pg.yml
+++ b/docker-compose-pg.yml
@@ -24,9 +24,9 @@ services:
environment:
- UID
- GID
- - PW_TEST_DB_HOST=db
- - PW_TEST_DB_PORT=5432
- - PW_TEST_DB_TYPE=postgres
- - PW_TEST_DB_USER=postgres
- - PW_TEST_DB_PASS=password
- - PGPASSWORD=password
+ - DATABASE_TYPE=postgres
+ - DATABASE_HOST=db
+ - DATABASE_PORT=5432
+ - DATABASE_NAME=patchwork
+ - DATABASE_USER=patchwork
+ - DATABASE_PASSWORD=password
diff --git a/docker-compose.yml b/docker-compose.yml
index 1d49c51..103f19f 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -5,7 +5,7 @@ services:
volumes:
- ./tools/docker/db/data:/var/lib/mysql
environment:
- - MYSQL_ROOT_PASSWORD=password
+ - MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=patchwork
- MYSQL_PASSWORD=password
@@ -26,5 +26,9 @@ services:
environment:
- UID
- GID
- - PW_TEST_DB_HOST=db
- - PW_TEST_DB_PORT=3306
+ # skip DATABASE_TYPE explicitly as mysql should be the default type.
+ - DATABASE_HOST=db
+ - DATABASE_PORT=3306
+ - DATABASE_USER=patchwork
+ - DATABASE_PASSWORD=password
+ - MYSQL_ROOT_PASSWORD=root
diff --git a/docs/deployment/installation.rst b/docs/deployment/installation.rst
index 1abf187..14ad746 100644
--- a/docs/deployment/installation.rst
+++ b/docs/deployment/installation.rst
@@ -64,7 +64,7 @@ used to ease deployment:
Username that the Patchwork web application will access the database with. We
will use ``www-data``, for reasons described later in this guide.
-``DATABASE_PASS=``
+``DATABASE_PASSWORD=``
Password that the Patchwork web application will access the database with. As
we're going to use *peer* authentication (more on this later), this will be
unset.
@@ -323,7 +323,7 @@ Once done, we should be able to check that all requirements are met using the
$ sudo -u www-data \
--preserve-env=DATABASE_NAME \
--preserve-env=DATABASE_USER \
- --preserve-env=DATABASE_PASS \
+ --preserve-env=DATABASE_PASSWORD \
--preserve-env=DATABASE_HOST \
--preserve-env=DATABASE_PORT \
--preserve-env=STATIC_ROOT \
diff --git a/docs/development/installation.rst b/docs/development/installation.rst
index d16177c..3507f43 100644
--- a/docs/development/installation.rst
+++ b/docs/development/installation.rst
@@ -316,7 +316,7 @@ if necessary:
The ``patchwork`` username and ``password`` password are the defaults
expected by the provided ``dev`` settings files. If using something
- different, export the ``PW_TEST_DB_USER`` and ``PW_TEST_DB_PASS`` variables
+ different, export the ``DATABASE_USER`` and ``DATABASE_PASSWORD`` variables
described in the :ref:`Environment Variables <dev-envvar>` section below.
Alternatively, you can create your own settings file with these variables
hardcoded and change the value of ``DJANGO_SETTINGS_MODULE`` as described
@@ -470,17 +470,16 @@ __ https://django-dbbackup.readthedocs.io/en/stable/
Environment Variables
---------------------
-The following environment variables are available to configure settings when
-using the provided ``dev`` settings file.
+The following environment variables are available to configure settings.
-``PW_TEST_DB_NAME=patchwork``
+``DATABASE_NAME=patchwork``
Name of the database
-``PW_TEST_DB_USER=patchwork``
+``DATABASE_USER=patchwork``
Username to access the database with
-``PW_TEST_DB_PASS=password``
+``DATABASE_PASSWORD=password``
Password to access the database with<
-``PW_TEST_DB_TYPE=mysql``
+``DATABASE_TYPE=mysql``
Type of database to use. Options: ``mysql``, ``postgres``
diff --git a/lib/uwsgi/patchwork.ini b/lib/uwsgi/patchwork.ini
index 95a0613..dbff508 100644
--- a/lib/uwsgi/patchwork.ini
+++ b/lib/uwsgi/patchwork.ini
@@ -10,7 +10,7 @@ url = /
# env = DJANGO_SECRET_KEY=
# env = DATABASE_NAME=
# env = DATABASE_USER=
-# env = DATABASE_PASS=
+# env = DATABASE_PASSWORD=
# env = DATABASE_HOST=
# env = DATABASE_PORT=
# env = STATIC_ROOT=
diff --git a/patchwork/settings/dev.py b/patchwork/settings/dev.py
index 2b7fc95..4487494 100644
--- a/patchwork/settings/dev.py
+++ b/patchwork/settings/dev.py
@@ -39,21 +39,21 @@ DEBUG = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
- 'HOST': os.getenv('PW_TEST_DB_HOST', 'localhost'),
- 'PORT': os.getenv('PW_TEST_DB_PORT', ''),
- 'USER': os.getenv('PW_TEST_DB_USER', 'patchwork'),
- 'PASSWORD': os.getenv('PW_TEST_DB_PASS', 'password'),
- 'NAME': os.getenv('PW_TEST_DB_NAME', 'patchwork'),
+ 'HOST': os.getenv('DATABASE_HOST', 'localhost'),
+ 'PORT': os.getenv('DATABASE_PORT', ''),
+ 'USER': os.getenv('DATABASE_USER', 'patchwork'),
+ 'PASSWORD': os.getenv('DATABASE_PASSWORD', 'password'),
+ 'NAME': os.getenv('DATABASE_NAME', 'patchwork'),
'TEST': {
'CHARSET': 'utf8',
},
},
}
-if os.getenv('PW_TEST_DB_TYPE', None) == 'postgres':
+if os.getenv('DATABASE_TYPE', None) == 'postgres':
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
- DATABASES['default']['HOST'] = os.getenv('PW_TEST_DB_HOST', '')
-elif os.getenv('PW_TEST_DB_TYPE', None) == 'sqlite':
+ DATABASES['default']['HOST'] = os.getenv('DATABASE_HOST', '')
+elif os.getenv('DATABASE_TYPE', None) == 'sqlite':
DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
DATABASES['default']['NAME'] = '/dev/shm/patchwork.test.db.sqlite3'
del DATABASES['default']['HOST']
diff --git a/releasenotes/notes/settings-unify-database-connection-variables-ac716f59ee7b8b48.yaml b/releasenotes/notes/settings-unify-database-connection-variables-ac716f59ee7b8b48.yaml
new file mode 100644
index 0000000..37dc2a3
--- /dev/null
+++ b/releasenotes/notes/settings-unify-database-connection-variables-ac716f59ee7b8b48.yaml
@@ -0,0 +1,7 @@
+---
+critical:
+ - |
+ Database configuration variables PW_TEST_DB_* are renamed to their
+ corresponding DATABASE_* names to sync development & production environments
+ setup. Some mistaken references to DATABASE_PASS are also corrected with
+ DATABASE_PASSWORD to follow the convention.
diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh
index 5450a53..7ae9803 100755
--- a/tools/docker/entrypoint.sh
+++ b/tools/docker/entrypoint.sh
@@ -1,28 +1,28 @@
#!/bin/bash
set -euo pipefail
-PW_TEST_DB_TYPE=${PW_TEST_DB_TYPE:-mysql}
+DATABASE_TYPE=${DATABASE_TYPE:-mysql}
# functions
test_db_connection() {
- if [ ${PW_TEST_DB_TYPE} = "postgres" ]; then
- echo ';' | psql -h $PW_TEST_DB_HOST -U postgres 2> /dev/null > /dev/null
+ if [ ${DATABASE_TYPE} = "postgres" ]; then
+ echo ';' | psql -h $DATABASE_HOST -U postgres 2> /dev/null > /dev/null
else
- mysqladmin -h $PW_TEST_DB_HOST -u patchwork --password=password ping > /dev/null 2> /dev/null
+ mysqladmin -h $DATABASE_HOST -u patchwork --password=password ping > /dev/null 2> /dev/null
fi
}
test_database() {
- if [ ${PW_TEST_DB_TYPE} = "postgres" ]; then
- echo ';' | psql -h $PW_TEST_DB_HOST -U postgres patchwork 2> /dev/null
+ if [ ${DATABASE_TYPE} = "postgres" ]; then
+ echo ';' | psql -h $DATABASE_HOST -U postgres patchwork 2> /dev/null
else
- echo ';' | mysql -h $PW_TEST_DB_HOST -u patchwork -ppassword patchwork 2> /dev/null
+ echo ';' | mysql -h $DATABASE_HOST -u patchwork -ppassword patchwork 2> /dev/null
fi
}
reset_data_mysql() {
- mysql -uroot -ppassword -h $PW_TEST_DB_HOST << EOF
+ mysql -uroot -ppassword -h $DATABASE_HOST << EOF
DROP DATABASE IF EXISTS patchwork;
CREATE DATABASE patchwork CHARACTER SET utf8;
GRANT ALL ON patchwork.* TO 'patchwork' IDENTIFIED BY 'password';
@@ -32,14 +32,14 @@ EOF
}
reset_data_postgres() {
- psql -h $PW_TEST_DB_HOST -U postgres <<EOF
+ psql -h $DATABASE_HOST -U postgres <<EOF
DROP DATABASE IF EXISTS patchwork;
CREATE DATABASE patchwork WITH ENCODING = 'UTF8';
EOF
}
reset_data() {
- if [ x${PW_TEST_DB_TYPE} = x"postgres" ]; then
+ if [ x${DATABASE_TYPE} = x"postgres" ]; then
reset_data_postgres
else
reset_data_mysql
diff --git a/tox.ini b/tox.ini
index 3275600..374cbb9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -25,8 +25,8 @@ setenv =
py{37,38,39}: PYTHONWARNINGS = once
passenv =
http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
- PW_TEST_DB_TYPE PW_TEST_DB_USER PW_TEST_DB_PASS PW_TEST_DB_HOST
- PW_TEST_DB_PORT PW_TEST_DB_NAME DJANGO_TEST_PROCESSES
+ DATABASE_TYPE DATABASE_USER DATABASE_PASSWORD DATABASE_HOST
+ DATABASE_PORT DATABASE_NAME DJANGO_TEST_PROCESSES
commands =
python {toxinidir}/manage.py test --noinput --parallel -- {posargs:patchwork}
--
2.32.0
More information about the Patchwork
mailing list