]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
settings: Unify database connection variables
authorYou-Sheng Yang <vicamo@gmail.com>
Thu, 9 Dec 2021 03:38:36 +0000 (11:38 +0800)
committerStephen Finucane <stephen@that.guru>
Wed, 23 Feb 2022 13:43:59 +0000 (13:43 +0000)
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@gmail.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
[stephenfin] Tweaked release notes

.github/workflows/ci.yaml
docker-compose-pg.yml
docker-compose.yml
docs/deployment/installation.rst
docs/development/installation.rst
lib/uwsgi/patchwork.ini
patchwork/settings/dev.py
releasenotes/notes/settings-unify-database-connection-variables-ac716f59ee7b8b48.yaml [new file with mode: 0644]
tools/docker/entrypoint.sh
tox.ini

index f4a33b36a1263d8aee92ec82aaa9865e66f73e32..59bc752cbe1f0706f4afb09a6d7992ce3d4d37db 100644 (file)
@@ -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
index 44c49fb6113d3e953fa402053019b50b0fc4f8ae..8056d62e98273d2f05b27de2e1cc2213a79c055b 100644 (file)
@@ -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
index 1d49c51e0e795a85437a9def538dcb1566df2c69..103f19f927119e85e0b3c7c0f249e97c1caae702 100644 (file)
@@ -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
index 1abf187c79ae30fc3cc4a897bcd9f0f8ccfe9d5a..14ad746225426e3fc1a20791ebcb76cd5c72d138 100644 (file)
@@ -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 \
index d16177ccd282369b16e7bd13da113ac1e359e984..3507f4357d33a5e92b9cc74e0e679490c618dedd 100644 (file)
@@ -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``
index 95a0613a54e370adb560dbde02c9fbb0a033422a..dbff5084bb59228592e033b8ef7c1c513a543b58 100644 (file)
@@ -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=
index 2b7fc954cd0e992ce2b17d1231be2b4beef988c4..4487494fd286045504e72aa989506ea72de46d5f 100644 (file)
@@ -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 (file)
index 0000000..98867a1
--- /dev/null
@@ -0,0 +1,7 @@
+---
+upgrade:
+  - |
+    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 replaced with ``DATABASE_PASSWORD`` to follow the convention.
index 5450a535e956196fa22431c059e3674cd2065325..7ae9803d9dd0d81742c51d3bca40d9ff7b4802fa 100755 (executable)
@@ -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 3275600820b15b976c01733907152bce32c60c81..374cbb94d2afb673f665c71bb0d94c525747caeb 100644 (file)
--- 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}