[web2py] Re: Can 2 apps use 1 database ?

2012-07-07 Thread Anthony

>
> Found this Was having trouble but i guess this -->  
> https://docs.google.com/viewer?a=v&q=cache:v2lgkygxA_cJ:www.packtpub.com/sites/default/files/5467OS-Chapter-3-Database-Abstraction-Layer.pdf+&hl=en&pid=bl&srcid=ADGEESgEeuJ9YUV1Lwvy1CubPMg-92-ZM0Rtdvc14RQhuwGE32cSVmd-p35Tw21hW2R4PB9UcXbXLwTVrGRcthvusLvcdRDhnz8B2g-LsohKy64TyJcMX0yuCw5qiypnsPSxUyWHHoPT&sig=AHIEtbQPUlFmojpWCTBBJKHdwdR34aZeuw
>  
>
> explained it. DRY is broken however, which isn't a good thing as the 
> database gets bigger.
>

The DAL does not inspect the database -- you have to tell it about your 
models for it to know what's in the database. This is necessary because the 
models can include many attributes that are not part of the database, such 
as defaults, validators, computed fields, etc.

DRY is not broken. If you need to share models across applications, you can 
put them in a module and import them (only Linux, you can also use symbolic 
links to model files). If you don't need all the DAL-specific attributes of 
the models, you can also 
auto-importthe
 model definitions from another app via:

db = DAL('sqlite://storage.sqlite', folder='path/to/app/databases', 
auto_import=True))


Note, if multiple apps are sharing a database, make sure for any given 
table within that database that migrations are being handled by at most one 
of the applications (i.e., for each table, set migrate to False in all but 
one app).

Anthony


[web2py] Re: Can 2 apps use 1 database ?

2012-07-07 Thread Horus
Found this Was having trouble but i guess this -->  
https://docs.google.com/viewer?a=v&q=cache:v2lgkygxA_cJ:www.packtpub.com/sites/default/files/5467OS-Chapter-3-Database-Abstraction-Layer.pdf+&hl=en&pid=bl&srcid=ADGEESgEeuJ9YUV1Lwvy1CubPMg-92-ZM0Rtdvc14RQhuwGE32cSVmd-p35Tw21hW2R4PB9UcXbXLwTVrGRcthvusLvcdRDhnz8B2g-LsohKy64TyJcMX0yuCw5qiypnsPSxUyWHHoPT&sig=AHIEtbQPUlFmojpWCTBBJKHdwdR34aZeuw
 

explained it. DRY is broken however, which isn't a good thing as the 
database gets bigger.

On Saturday, July 7, 2012 2:15:58 PM UTC-4, Horus wrote:
>
> I currently have 2 apps which i would like to share one database.
>
> one app is for authentication the other is the main app.
> When I run the app1 it creates the auth tables along with another table 
> called *base_tags*
>
> when I run app2 I get the following error. (the base_tags table in app1 is 
> referenced in app2 - same database).
>
> *In App2*
>  'base_tags'
>
> Traceback (most recent call last):
>   File "C:\web2py\gluon\restricted.py", line 205, in restricted
> exec ccode in environment
>   File "C:/web2py/applications/app2/models/db.py" 
> , line 433, in 
> 
> Field('tag_id', db.base_tags, label='Tag', required=True, notnull=True, 
> writable=False, readable=False)
>   File "C:\web2py\gluon\dal.py", line 6343, in __getattr__
> return self[key]
>   File "C:\web2py\gluon\dal.py", line 6337, in __getitem__
> return dict.__getitem__(self, str(key))
> KeyError: 'base_tags'
>
>
> db.define_table('places_tags',
> Field('place_id', db.places, label='Place', required=True, 
> notnull=True, writable=False, readable=False),
> *line 433*:Field('tag_id', *db.base_tags*, label='Tag', 
> required=True, notnull=True, writable=False, readable=False)
> )
>
>
> I am assuming that place_tags isn't seeing db.base_tags (no reference). 
> May be I don't understand DAL.
>
> 1. Isn't DAL an interface to the database? 
> 2. If the database exist why wouldn't I be able to access it from another 
> app and reference tables that already exist?
> 3. Should I assume that unless *base_tags* was defined in app2 I cannot 
> access it?
>
>