예제 #1
0
 def save(self, session=None):
     """Save this object."""
     if not session:
         session = sa.get_session()
     # NOTE(boris-42): This part of code should be look like:
     #                       sesssion.add(self)
     #                       session.flush()
     #                 But there is a bug in sqlalchemy and eventlet that
     #                 raises NoneType exception if there is no running
     #                 transaction and rollback is called. As long as
     #                 sqlalchemy has this bug we have to create transaction
     #                 explicity.
     with session.begin(subtransactions=True):
         session.add(self)
         session.flush()
예제 #2
0
파일: env.py 프로젝트: ShooterTT/gringotts
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = sa_session.get_session().get_bind()
    #engine = engine_from_config(
    #        config.get_section(config.config_ini_section),
    #        prefix='sqlalchemy.',
    #        poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(
                connection=connection,
                target_metadata=target_metadata
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
예제 #3
0
def get_session():
    return db_session.get_session()
예제 #4
0
def get_session():
    return db_session.get_session()