Thursday, February 23, 2017

DatabaseRouter and connections

Hi,

For long time we use a DatabaseRouter and a middleware to choose database to use on the fly. With the time going we have now a lot too much databases configurations in our settings.
So we have made something to dynamically load database configuration in django.db.connections when they are not present but present in a database storying the configurations.

Everything is working well, but before putting it in production, we will be happy to have some feedback about this way of doing things and be sure that it's the good way to load dynamically database configurations.

So is-it correct to add new connections by using this function :

from django.db import connections
def add_db_connection(system_id, name, user, password, host, protocol):
    connections.databases[system_id] = {
        'ENGINE': 'django.db.backends.' + protocol,
        'NAME': name,
        'USER': user,
        'PASSWORD': password,
        'HOST': host,
        'CONN_MAX_AGE': 0
    }

or is they a better way to load new databases configurations ?


Thanks a lot for your answers,

Matthieu

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a140261d-87b5-4b75-9ec7-1b5e1622f2ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment