Multiple DB's, Ofer Malbin

Get Started. It's Free
or sign up with your email address
Rocket clouds
Multiple DB's, Ofer Malbin by Mind Map: Multiple DB's, Ofer Malbin

1. must have default entry

2. from 1.4, you'll have to use this syntax

3. How to use

3.1. need dictionary of database settings

3.2. syncdb --database=<db name>

4. automatic db routing

4.1. 2 styles

4.1.1. automatic define rules & then automatically decide which db to use

4.1.2. manual

4.2. default routing scheme

4.2.1. sticky Untitled

4.2.2. fallback to default db, if no definition

4.3. new class

4.3.1. Database Router define 4 methods where to read where to write allow relation allow syncdb using routers define routers in settings

4.3.2. example MasterSlaveRouter write on master reads on slave db's allow relation see full example here:

5. manual db selection

5.1. for example

5.1.1. Author.objects.using('default').all()

5.1.2.'legcy') if you did get with certain db, you can use save & it will stick to that db

5.2. or

5.2.1. Untitled

6. Django & SaaS

6.1. sites app

6.1.1. 1 db

6.1.2. relate models to sites

6.1.3. problem: data of multiple customers on same db

6.2. multiple db's

6.2.1. 1 per customer

6.2.2. example sub-domain per customer decide on db by sub-domain full example middleware saves the db in a dictionary (registry(, with the current thread as key identify the sub-domain looks up the db for this sub-domain stores in the dictionary provides a getter & setter to access the registry db router read & write relation & syncdb

7. issues

7.1. support in libraries is slowly arriving

7.2. transactions are problematic