[web2py] Re: Schema Changes in GAE

2011-10-07 Thread Joseph Jude
I was able to successfully added a field, filled with content and also 
renamed a field (add a filed, copy and then delete). If it would be of some 
use for others, here is how I did:

Ref the below stackflow thread. Alex offers a simple solution. 
http://stackoverflow.com/questions/2906746/updating-model-schema-in-google-app-engine

You write this code in migrate.py
Then in app.yaml have a url like below:

- url: /admin/migrate
  script: migrate.py

You can choose the url (I choose /admin).

Then launch the app  call this url. Voila GAE DB modified.

My modified app now lives on http://123-check.appspot.com/

Regards,
Joseph



[web2py] Re: Schema Changes in GAE

2011-10-07 Thread howesc
yes, i import the GAE libraries into a web2py controller and run my 
migrations as web2py controllers (so i can use a mix of DAL and GAE).  your 
method below is also valid.


[web2py] Re: Schema Changes in GAE

2011-10-06 Thread howesc
adding columns is a no-op.  just add them in the model and viola.

keep in mind that if there is no data in the columns for existing records 
they will not be returned in queries that filter on those columns.

to rename the column (and pretty similarly to add data to a new column):
 - create a model that has both the old column and the new column name
 - create a controller that iterates over every row in the table.  copy data 
from the first column to the new column with the new name
 - if you have more than say 100 rows you will need to run as a taskqueue or 
backend task.  more than say 1000 rows and you might have to split taskqueue 
tasks
 - remember that ID's are not strictly increasing, so if the app is live and 
writes may happen to this table during the migration don't sort by ID.
 - if you care to delete the old column, create a true google model as a 
expando class with the old field not defined, query the rows, delete the old 
field and put.

here is a sample method that clears fields from a table (i'm certain that 
this does not properly iterate over more than 1000 rows, but i can't find 
the fixed version in my source control):

#remove recording to and from fields
def clear_recording_to_from():

remove the device_id and device_token fields from end_user

from google.appengine.ext import db as gdb
from google.appengine.api.datastore_types import Key
from google.appengine.api import taskqueue
  
class recording(gdb.Expando):
title = gdb.StringProperty(required=False)
  
#use a random (but invalid) string to make sure we find all objects,
# even those with explicit NULL
rows = recording.gql(WHERE title != 'asegsebob').fetch(limit=1000)
for r in rows:
del r['to']
del r['from']
gdb.put(rows)
  
if len(rows) == 1000:
#there are probably more to process
taskqueue.add(url=URL(r=request))
 
return dict(message=Updating recordings)


[web2py] Re: Schema Changes in GAE

2011-10-06 Thread Joseph Jude
Thank you for your reply. Is there a way to run gae specific code (with gae 
objects) within web2py? or should this be executed only within gae 
environment (may be I need to modify app.yaml too then?)

Thank you in advance,
Joseph