How does on run a script to Populate the datastore via GAE?

19 views
Skip to first unread message

John

unread,
May 27, 2008, 11:55:10 AM5/27/08
to Google App Engine
Hello,

When I work with a relation database, I often want to populate the
database before running my web app. So, I'll run some script to
populate the database. This is separate from the web app.

With the GAE, I wrote a class based on db.Model. The Populate()
method stores the data. In the dev environment, I just added this to
my main handler and commented it out on subsequent runs. Lame. How do
i do this right? Is there some way to have dev_appserver.py run the
populate script on demand instead of the webapp?

Thanks for your time and consideration.

Sincerely,

John

gg

unread,
May 27, 2008, 6:20:53 PM5/27/08
to Google App Engine
Have you looked at bulkloader????

Mahmoud

unread,
May 27, 2008, 6:29:19 PM5/27/08
to Google App Engine
So there is Bulkloader, which lets you convert CSV data into entities,
and inserts them into the datastore:
http://code.google.com/appengine/articles/bulkload.html

However, I found this to be easier to do:
1. Just like in the Bulkloader tutorial, insert this into app.yaml:
- url: /load
script: loader.py
login: admin

2. Now write loader.py so that it would create your initial/test data
and put()'s them into the datastore.

John

unread,
May 28, 2008, 11:07:52 AM5/28/08
to Google App Engine
Hello Mahmoud,

Thinking of the entry point as a python handler did the trick for me.

Thanks,

-John
Reply all
Reply to author
Forward
0 new messages