-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Em 31-03-2012 07:17, Alex escreveu: > ok, I think now I understand how the request_tenant works. So there would be > just one database for everything but every table is filtered by the field? If > that is the case that's really not what I want. > > I also thought about selecting the db by the request.env.http_host etc. this > also seems like a hack to me but I guess I could live with that... only > problem > is this will not work with cron jobs (accessing the db), at least that is > what I > assume. I'm currently using enviroment variables for the db config but this > fails now because of the cron jobs (external cron). > > I'm now thinking of reading the db config from a config file in db.py but this > also seems like a really bad solution. Then I'd probably have the file I/O for > every request just to get the db configuration. >
I'm facing the same problem as you (the 'all-in-one' solution doesn't fit either) and the best solution I found so far was to read the DB connection parameters based on a config file. The drawback is that you have to read that file on each request... one day I'll try to figure how to cache it. An alternative might be a script that changed the URI in models/db.py, like this one from Francisco Ribeiro: http://www.web2pyslices.com/slice/show/1472/deployment-script-with-inline-code-replacement > Am Samstag, 31. März 2012 03:05:27 UTC+2 schrieb nick name: > > The database connection is initialized in models/db.py (assuming you used > the wizard to generate your application). Look for the line that says > "db=DAL(...)", and make it select the right database according to your > request, e.g. request.host, or however else you determine the > configuration > environment. > > Alternatively, you could keep it all in the same database with a > "request_tenant' field: > https://groups.google.com/d/topic/web2py/CixV2qflqkk/discussion - > > if you add a field such as the following to a table: > > ... > Field('request_tenant', default=request.host), > ... > (where the default is however you identify the specific environment) > > web2py will add a "and request_tenant=''+request.host+''" to every query > relating to that table, and of course would insert it to new records. > Effectively, this means every record in a table with such a field will > only > be seen when the default value of the field in this request is the same as > when it was generated. (You can still get all records by either setting > the > default to None, or adding an "ignore_common_filter=True") > > On Friday, March 30, 2012 4:55:16 PM UTC-4, Alex wrote: > > Hello, > > I need to configure my data source for different instances. Currently > this is the last problem preventing me from going productive. I run my > application for multiple customer instances and of course the database > connection is different for each customer. This issue also occurs if > you > have a test and a productive environment. I think this is a fairly > common use case and necessary for most real world applications, so I'm > really surprised that I didn't see any solution for this in web2py > (especially since web2py is so easy and powerful for everything else). > Or did I just miss something? > > Massimo, in case you read this, do you have an advice for me? is an > environment configuration a feature that could be added in the > future? I > think that I read somewhere that web2py developers don't think this is > necessary but I really don't understand why. > > Is there a workaround for me? I have some ideas but nothing seems to > be > optimal. I'd prefer to avoid dirty hacks... > > thanks, > Alex > - -- Com os melhores cumprimentos, Carlos Correia ========================= MEMÓRIA PERSISTENTE, Lda. Tel.: 219 291 591 - GSM: 917 157 146 / 967 511 762 e-mail: ge...@memoriapersistente.pt - URL: http://www.memoriapersistente.pt Jabber: m...@jabber.org GnuPG: wwwkeys.eu.pgp.net URL Suporte (experimental): https://ky.m16e.com (certificado auto-assinado) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk95aPsACgkQ90uzwjA1SJUfHACeMsGn4Npt70baxB9ZJkuUanIJ EO0AoMlxgT+3Hwc323vzcaqyXjvebGx6 =ASOO -----END PGP SIGNATURE-----