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

4.1.1.1. define rules & then automatically decide which db to use

4.1.2. manual

4.2. default routing scheme

4.2.1. sticky

4.2.1.1. Untitled

4.2.2. fallback to default db, if no definition

4.3. new class

4.3.1. Database Router

4.3.1.1. define 4 methods

4.3.1.1.1. where to read

4.3.1.1.2. where to write

4.3.1.1.3. allow relation

4.3.1.1.4. allow syncdb

4.3.1.2. using routers

4.3.1.2.1. define routers in settings

4.3.2. example

4.3.2.1. MasterSlaveRouter

4.3.2.1.1. write on master

4.3.2.1.2. reads on slave db's

4.3.2.1.3. allow relation

4.3.2.2. see full example here:

4.3.2.2.1. http://github.com/jbalogh/django-multidb-router

5. manual db selection

5.1. for example

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

5.1.2. my_object.save(using='legcy')

5.1.2.1. 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:

6.1.3.1. data of multiple customers on same db

6.2. multiple db's

6.2.1. 1 per customer

6.2.2. example

6.2.2.1. sub-domain per customer

6.2.2.2. decide on db by sub-domain

6.2.2.3. full example

6.2.2.3.1. http://tidbits.posterous.com/saas-with-django-and-postgresql

6.2.2.4. middleware

6.2.2.4.1. saves the db in a dictionary (registry(, with the current thread as key

6.2.2.4.2. identify the sub-domain

6.2.2.4.3. looks up the db for this sub-domain

6.2.2.4.4. stores in the dictionary

6.2.2.4.5. provides a getter & setter to access the registry

6.2.2.5. db router

6.2.2.5.1. read & write

6.2.2.5.2. relation & syncdb

7. issues

7.1. support in libraries is slowly arriving

7.2. transactions are problematic