]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
settings: Move database settings into base
authorYou-Sheng Yang <vicamo@gmail.com>
Thu, 9 Dec 2021 03:38:37 +0000 (11:38 +0800)
committerStephen Finucane <stephen@that.guru>
Wed, 23 Feb 2022 13:43:59 +0000 (13:43 +0000)
Signed-off-by: You-Sheng Yang <vicamo@gmail.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
[stephenfin] Reworked release note

patchwork/settings/base.py
patchwork/settings/dev.py
patchwork/settings/production.example.py
releasenotes/notes/settings-move-database-settings-into-base-f0d05cf75170d55f.yaml [new file with mode: 0644]

index ff14d91b8ff46d771fd28177a35346a199e43f93..c2703a27bb14b19764b10335fbf937abd8c96fb1 100644 (file)
@@ -105,6 +105,45 @@ STATICFILES_DIRS = [
     os.path.join(ROOT_DIR, 'htdocs'),
 ]
 
+# Database
+#
+# If you're using a postgres database, connecting over a local unix-domain
+# socket, then the following setting should work for you. Otherwise,
+# see https://docs.djangoproject.com/en/2.2/ref/settings/#databases
+
+if os.getenv('DATABASE_TYPE') == 'postgres':
+    DATABASES = {
+        'default': {
+            'ENGINE': 'django.db.backends.postgresql_psycopg2',
+            'HOST': os.environ.get('DATABASE_HOST', 'localhost'),
+            'PORT': os.environ.get('DATABASE_PORT', ''),
+            'NAME': os.environ.get('DATABASE_NAME', 'patchwork'),
+            'USER': os.environ.get('DATABASE_USER', 'patchwork'),
+            'PASSWORD': os.environ.get('DATABASE_PASSWORD', 'password'),
+        },
+    }
+elif os.getenv('DATABASE_TYPE') == 'sqlite3':
+    DATABASES = {
+        'default': {
+            'ENGINE': 'django.db.backends.sqlite3',
+            'NAME': os.environ.get('DATABASE_NAME', ''),
+        },
+    }
+else:  # mysql
+    DATABASES = {
+        'default': {
+            'ENGINE': 'django.db.backends.mysql',
+            'HOST': os.getenv('DATABASE_HOST', 'localhost'),
+            'PORT': os.getenv('DATABASE_PORT', ''),
+            'NAME': os.getenv('DATABASE_NAME', 'patchwork'),
+            'USER': os.getenv('DATABASE_USER', 'patchwork'),
+            'PASSWORD': os.getenv('DATABASE_PASSWORD', 'password'),
+            'TEST': {
+                'CHARSET': 'utf8',
+            },
+        },
+    }
+
 #
 # Third-party application settings
 #
index 4487494fd286045504e72aa989506ea72de46d5f..cb4cb19fe08d88f0412594129e5d232eed44275d 100644 (file)
@@ -7,8 +7,6 @@ Design based on:
     http://www.revsys.com/blog/2014/nov/21/recommended-django-project-layout/
 """
 
-import os
-
 from .base import *  # noqa
 
 try:
@@ -36,30 +34,8 @@ SECRET_KEY = '00000000000000000000000000000000000000000000000000'  # noqa
 
 DEBUG = True
 
-DATABASES = {
-    'default': {
-        'ENGINE': 'django.db.backends.mysql',
-        '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('DATABASE_TYPE', None) == 'postgres':
-    DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
-    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']
-    del DATABASES['default']['PORT']
-    del DATABASES['default']['USER']
-    del DATABASES['default']['PASSWORD']
+if DATABASES['default']['ENGINE'] == 'mysql':  # noqa: F405
+    DATABASES['default']['TEST'] = {'CHARSET': 'utf8'}  # noqa: F405
 
 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
 
index caaf4294b2ca58a39ec4d6110e69038e0e93fe8d..ff0562946fe188b37add849b34894fdbfbe769df 100644 (file)
@@ -48,23 +48,6 @@ ADMINS = (
     # ('Jeremy Kerr', 'jk@ozlabs.org'),
 )
 
-# Database
-#
-# If you're using a postgres database, connecting over a local unix-domain
-# socket, then the following setting should work for you. Otherwise,
-# see https://docs.djangoproject.com/en/2.2/ref/settings/#databases
-
-DATABASES = {
-    'default': {
-        'ENGINE': 'django.db.backends.postgresql_psycopg2',
-        'NAME': os.environ.get('DATABASE_NAME', ''),
-        'USER': os.environ.get('DATABASE_USER', ''),
-        'PASSWORD': os.environ.get('DATABASE_PASSWORD', ''),
-        'HOST': os.environ.get('DATABASE_HOST', ''),
-        'PORT': os.environ.get('DATABASE_PORT', ''),
-    },
-}
-
 #
 # Static files settings
 # https://docs.djangoproject.com/en/2.2/ref/settings/#static-files
diff --git a/releasenotes/notes/settings-move-database-settings-into-base-f0d05cf75170d55f.yaml b/releasenotes/notes/settings-move-database-settings-into-base-f0d05cf75170d55f.yaml
new file mode 100644 (file)
index 0000000..772bc81
--- /dev/null
@@ -0,0 +1,19 @@
+---
+upgrade:
+  - |
+    Database configuration has been added to ``patchwork.settings.base``.
+    Previously, this had to be specified in the ``settings.py`` file manually
+    created by admins. The following environment variables can now be used to
+    configure the settings:
+
+    - ``DATABASE_TYPE`` (one of: ``postgres``, ``sqlite3``, ``mysql``;
+      default: ``mysql``)
+    - ``DATABASE_HOST`` (default: ``localhost``)
+    - ``DATABASE_PORT`` (default: ``<unset>``)
+    - ``DATABASE_NAME`` (default: ``patchwork``)
+    - ``DATABASE_USER`` (default: ``patchwork``)
+    - ``DATABASE_PASSWORD`` (default: ``patchwork``)
+
+    If you are manually defining ``DATABASES`` in your ``settings.py`` file,
+    this should have no impact. However, you may wish to rework your deployment
+    to use environment variables instead.