Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle model changes in pyramid

During production phase I would most probably look into migrate functionality (with versions and such), but while I'm at the development stage I'm wondering what the most common way of handling any changes in my models.py would be? The app is setup with SQLAlchemy.

I'm relatively new to python web frameworks. My background is PHP and most recently I finished a project using Symfony 1.4 where I could normally just do symfony doctrine:build --all --and-load and that would take care of rebuilding model classes, recreating the database, and loading data fixtures, among a few other things.

Currently what I'm doing is just dropping the database, recreating it, and serving up the app with paster which takes care of recreating the tables and such.

This is probably a noob question, but there you go.

like image 552
rhyek Avatar asked Mar 31 '11 01:03

rhyek


2 Answers

I'm using right now sql alchemy migrate and it's pretty easy.

heres a tutorial: http://spyced.blogspot.com/2008/07/sqlalchemy-migrate-for-dummies.html

and a pdf with more info and tutorials: http://www.google.com/url?sa=t&source=web&cd=5&sqi=2&ved=0CC4QFjAE&url=http%3A%2F%2Fsqlalchemy-migrate.googlecode.com%2Ffiles%2Fsqlalchemy-migrate-0.5.1.3-docs.pdf&rct=j&q=sqlalchemy%20migrate&ei=QgCUTYGGEcPPiALH65SdCQ&usg=AFQjCNHG-1IdCiIPSslwK_hTMiCzrYVvoA&sig2=b_5-I3D-nebSVR_7FccRvQ&cad=rja

it's easy to install, to make changes (upgrades downgrade) to the database in a expresive sqlalchemy way.

like image 77
Roberto Alarcon Avatar answered Nov 17 '22 05:11

Roberto Alarcon


Alright nevermind. I modified my initialize_sql like so:

def initialize_sql(engine):
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.drop_all(engine) #added this
    Base.metadata.create_all(engine)
    try:
        populate()
    except IntegrityError:
        pass

Thankfully this only drops the tables, not the whole database, so it runs quickly.

like image 43
rhyek Avatar answered Nov 17 '22 07:11

rhyek