Database replication is tricky to set up and maintain. RestAuth provides two Database routers that should help you with the most common replication situations. If you desire more information, please consult the Multiple databases chapter in the Django documentation.
Warning
Only use database routers when you actually use multiple databases. Adding a router does introduce a (negligible) performance overhead.
To use a database router (you can either write your own or use an existing one), simply add it to the DATABASE_ROUTERS setting in RestAuth/localsettings.py. For example, if you want to use our MasterSlave router, simply add:
DATABASE_ROUTERS = ['RestAuth.common.routers.MasterSlave']
Note
Routers shipping with RestAuth are not intended to be used together with other routers. If you require a more complex database routing schema you can either:
You can also implement your own router if you require a more complex configuration. Writing routers is documented in in the Django documentation and requires you to be able to code in Python.
This router assumes that you have a single master (that can perform write operations) and multiple slaves that perform read operations.
Read operations will be redirected to a random database (including the master) and write operations will be directed to the “default” database, which should be the master.
This router handles multiple (read/write) masters and (read-only) slaves.
Read operations will be redirected to a random database (including any masters). Write-operations will be redirected to a random database with a designation starting with ‘master’.
Example:
DATABASES = {
'master-a': { ... }, # will get write operations
'master-b': { ... }, # will get write operations
'slave': { ... }, # this is a read-only slave
}