>
> :-) I would be great if you could share it.
>>
>
Sure!

The logic I ended up using for Heroku is more explicit than 
gluon/contrib/heroku.py, and closer to how the doc handles GAE :

import os
detect_heroku = lambda: bool([n for n in os.environ.keys() if n[:18]+n[-4
:]=='HEROKU_POSTGRESQL__URL'])

# use environment variables to enable multiple deployment environments
request.step = os.getenv('STEP')

HEROKU_DATABASES = {'production':'HEROKU_POSTGRESQL_BLACK_URL',
                    'staging':'HEROKU_POSTGRESQL_PURPLE_URL'}

if detect_heroku():
  # find db URI
    database_name = HEROKU_DATABASES[request.step]
    heroku_uri = os.environ[database_name]
    if request.step == 'production':
        # store sessions in database
        session.connect(request, response, db=jdb, 
migrate='web2py_session.table')
    else:
        # store sessions in the filesystem
        session.connect(request, response)
else:
    db = DAL('postgres://...')
    session.connect(request, response, db=db, 
migrate='web2py_session.table')

To run the server locally, I use a shell script:
STEP = 'local'
export STEP
python web2py.py ...

When I first configure my Heroku applications, I always set the "STEP" 
variable environment either in the web-interface or using the CLI.

With this code you tacke several issues : using multiple databases, using 
multiple deployment environments & storing sessions.
Heroku's pricing makes it so that you only have 10000 rows available on 
free servers so if you're not in production, you're better off storing 
sessions in files (or cookies for that matter).

As for migrations, I track all .table files in my GIT repository as files.
I don't use the "HerokuPostgresAdapter" because some of the migration logic 
is broken. From what I recall it has to do with PostgresAdapter logic 
versus GoogleAppEngine logic in dal.py, which is hard-coded in the 
framework.

Tracking .table files allows me to know when migrations are to be done, so 
I end up altering my tables with pgAdmin3 (after creating a backup with 
Heroku's CLI tool).


This isn't the cleanest way to handle migrations, but it worked for me over 
the past few months.

I'm now trying to put all of this logic in a better-suited solution : a 
Buildpack dedicated to running web2py on Heroku.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to