[web2py] Re: database replication

2011-07-22 Thread Nils Olofsson
Hi, I'm still not sure as to how to go about using this. Say, I have a controller with the function list: and a function called write: if the function is list then read from slaves, if the function is write, write to master. So the correct code should be: if request.function in

[web2py] Re: database replication

2011-07-22 Thread Anthony
You could define 'read_only_actions' anywhere it makes sense, for example: read_only_actions = ['list','another_read_action','yet_another_read_action'] if request.function in read_only_actions: db =... ... else db = Of course, if that one 'if' statement is the only place you

[web2py] Re: database replication

2011-07-22 Thread Nils Olofsson
Hi, I did something similar, if add in request.function: db = DAL(['mysql://Database connection string']) else: print Using Slave Database db = DAL(shuffle(['database connection string']) That would and uses the slave database (readonly) but, I get this error message.

[web2py] Re: database replication

2011-07-22 Thread Anthony
Have all the tables already been created in the slave databases (web2py may be trying to create tables or run migrations)? What happens if you do: db = DAL(shuffle(['connection string']), migrate_enabled=False) Anthony On Friday, July 22, 2011 9:28:40 AM UTC-4, Nils Olofsson wrote: Hi, I

Re: [web2py] Re: database replication

2011-07-22 Thread nils
Hi Anthony, That worked, maybe the docs should be updated. I did try migrate=False, thought they were both the same thing. Regards, Nils On Fri, Jul 22, 2011 at 3:05 PM, Anthony abasta...@gmail.com wrote: Have all the tables already been created in the slave databases (web2py may be trying

Re: [web2py] Re: database replication

2011-07-22 Thread Anthony
On Friday, July 22, 2011 10:12:01 AM UTC-4, nils wrote: Hi Anthony, That worked, maybe the docs should be updated. Indeed. I did try migrate=False, thought they were both the same thing. migrate=False (as an argument to DAL) doesn't turn off migrations -- it merely determines the

Re: [web2py] Re: database replication

2011-07-22 Thread nils
Hi Anthony, yes, migrate is set for fields in the aut table. Also another note, shuffle did not work for me I have to, from random import sample. then change DAL(sample(['mysql connection string','mysql connection string'],1),migrate_enabled=False) Regards, Nils On Fri, Jul 22, 2011 at 4:02

Re: [web2py] Re: database replication

2011-07-22 Thread Anthony
On Friday, July 22, 2011 12:28:24 PM UTC-4, nils wrote: Hi Anthony, yes, migrate is set for fields in the aut table. Also another note, shuffle did not work for me I have to, from random import sample. then change DAL(sample(['mysql connection string','mysql connection

Re: [web2py] Re: database replication

2011-07-22 Thread Anthony
Just changed the book example to use random.sample. Anthony On Friday, July 22, 2011 12:55:46 PM UTC-4, Anthony wrote: On Friday, July 22, 2011 12:28:24 PM UTC-4, nils wrote: Hi Anthony, yes, migrate is set for fields in the aut table. Also another note, shuffle did not work for me

[web2py] Re: database replication

2011-07-21 Thread Massimo Di Pierro
You would only use this if you have a replicated database. I.e. you are running many database servers synced with each other. For example: http://en.wikipedia.org/wiki/Multi-master_replication On Jul 21, 12:44 pm, Nils Olofsson nils.olofs...@gmail.com wrote: Hi, I see this in the

[web2py] Re: database replication

2011-07-21 Thread Nils Olofsson
Hi Massimo, I'm testing amazon's RDS and EC2 , 1 master many slaves. I could not find out where exactly I am suppose to be putting this code. Regards, Nils On Jul 21, 6:48 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: You would only use this if you have a replicated database. I.e.

[web2py] Re: database replication

2011-07-21 Thread Anthony
It would go in your model file -- the same place where you would normally define the db connection. Anthony On Thursday, July 21, 2011 2:29:45 PM UTC-4, Nils Olofsson wrote: Hi Massimo, I'm testing amazon's RDS and EC2 , 1 master many slaves. I could not find out where exactly I am

[web2py] Re: database replication

2011-07-21 Thread Nils Olofsson
Hi, I did this but i got : Traceback (most recent call last): File /var/www/web2py/gluon/restricted.py, line 192, in restricted exec ccode in environment File /var/www/web2py/applications/Event/models/db.py, line 18, in module if request.action in read_only_actions: NameError: name

[web2py] Re: database replication

2011-07-21 Thread Anthony
That's just some (incomplete) example code. You have to define 'read_only_actions' yourself. In that example, it would be a list functions that only need to read (but not write) the database and can therefore be given access to one of the slave databases. Actually, it looks like the code has