Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyramid equivalent to Django's syncdb command?

I noticed in the Pyramid + SQLAlchemy + URL Dispatch Wiki Tutorial that the database is initialized in the main function when the application is run.

def main(global_config, **settings):
    """ This function returns a WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    initialize_sql(engine)
    # -- and so on ---

where initialize_sql is defined as follows:

def initialize_sql(engine):
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    try:
        session = DBSession()
        page = Page('FrontPage', 'initial data')
        session.add(page)
        transaction.commit()
    except IntegrityError:
        # already created
        pass

which essentially creates all of the tables (if they don't exist) and populates it with some initial values. Easy enough to understand, BUT...

This is just a tutorial to demonstrate a small application, so how it is typically done in production may differ (or not...). This brings me to my question:

When using Pyramid with SQLAlchemy, is it a typical pattern in production for a database to be initialized this way, or is it typical to use something equivalent to a manage syncdb command in Django that is invoked manually?

like image 459
kes Avatar asked Jul 19 '11 21:07

kes


1 Answers

Since Pyramid does not make any assumptions about data models, it does not attempt to manage them for you. This is entirely up to you and what specific data layer you are using.

With respect to using SQLAlchemy, it is possible to manage migrations using the SQLAlchemy-migrate package. When you set this up, it provides you with a manage command to perform migrations.

like image 147
Michael Merickel Avatar answered Sep 20 '22 06:09

Michael Merickel