howto do databases "fixtures"

29 views
Skip to first unread message

Horst

unread,
Jan 15, 2008, 5:54:53 PM1/15/08
to web2py Web Framework
In my web app, I need to pre-populate the database with some records
before it is used for the first time.

Lets say, I need the table "groups", with pre-defined records "admin",
"editor", "registered"

How can I do this from within web2py, other than by distributing
database dumps? Any way to add insert statements to the model so that
they are executed only once at database initialization?

I guess I could roll my own, but would be nice if there was a
"standard" way to do this in web2py

Did I miss something in the documentation?

Massimo Di Pierro

unread,
Jan 15, 2008, 6:00:25 PM1/15/08
to web...@googlegroups.com
What about this?

if not len(db().select(db.table.id)):
for i in range(1000):
db.table.insert(whatever=random())

Massimo

voltron

unread,
Jan 16, 2008, 2:41:31 AM1/16/08
to web2py Web Framework
Maybe a Fixtures app for the daily app list? In Pylons there is a file
called "web_setup.py", one can add init values and test values, call
it and it would setup things. An app that can be externally called
from the terminal or from the database admin page would be great. The
fixture app would just have to "reflect" the field types in the
database and generate sane values according to the criteria given

On Jan 16, 12:00 am, Massimo Di Pierro <mdipie...@cs.depaul.edu>
wrote:

mdipierro

unread,
Jan 16, 2008, 10:11:32 AM1/16/08
to web2py Web Framework
cool idea. If you make it I will post it on applicances.
Reply all
Reply to author
Forward
0 new messages