We are a small team, trying to work with Django with a restricted access to a futurely unmanaged PostgreSQL database (i.e: only views and stored procedures ; no access to any tables) for security reasons.
- We tried to give (within Postgre) the user external_test the rights to create any tables inside his own schema on external, and to use the following settings (
settings.py
):
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'external': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgre_db',
'USER': 'external_user',
'PASSWORD': 'password',
'HOST': 'integration.project.net',
'PORT': '5432',
'TEST': {
'NAME': 'test_db',
'USER': 'external_test',
'PASSWORD': 'password',
...
- Using simple passing unit tests (
project/app/tests/test_views.py
):
...
class InternalTest(TestCase):
database = ['default']
def test_something(self):
pass
class StoredProcedureTest(TestCase):
databases = ['external']
def test_one_procedure(self):
with connections["external"].cursor() as cursor:
cursor.callproc("some_procedure", [42, ])
pass
...
If we try the first one with
./manage.py test app.tests.test_views.InternalTest
→ okIf we try the other one with
./manage.py test app.tests.test_views.StoredProcedureTest
→ circular dependency issue
(ImproperlyConfigured: Circular dependency in TEST[DEPENDENCIES]
)
probably because it's skipping the configuration of default- If we try both tests with
./manage.py test app.tests.test_views
:
→ permission denied
(Django try to create a database test_db as the user external_user)Creating test database for alias 'default'... Creating test database for alias 'external'... Got an error creating the test database: permission denied to create database
We don't really get what Django is trying to do and how to properly configure it.
If we give the rights to external_user to create their own databases:
- the database test_db is created by external_user
- the schema of default (sqlite) is created in test_db of external (postgre)
- the schema of external (postgre) is not created in test_db
Questions
- Is django able to handle this ?
- What are we doing wrong ?
- What is the point of specifying a user external_user for TEST if in the end django is using the normal user external_user ?
- Why does it write the schema of default in test_db ? Is there a way to create only models of some apps in it ?
- Why isn't it able to create the schema of external in test_db ?
I hope it was described enough. Thank you in advance for your responses =)