On Jun 3, 2014, at 10:37 PM, gbr <
doub...@directbox.com> wrote:
> I went ahead and made the modification as suggested. Alembic and my application are now using the application's database connection and sessions.
>
> However, the system locks up during a migration when I query for some application data which I need for data migration. I use Flask-SqlAlchemy and follow the way they described it to be used (and postgres):
>
> When I call
>
> > session.query(SomeClass)
>
> the migration process blocks in engine/default.py in cursor.execute (this is as far as I can trace it).
>
> > def do_execute(self, cursor, statement, parameters, context=None):
> > cursor.execute(statement, parameters)
>
> This is how I create a connection in env.py (Alembic) now:
>
> > engine = get_db().engine
> > connection = engine.connect()
>
> `get_db()` is part of the application. It returns an instance of `db = SQLAlchemy(flask_app)`
>
> I'm not sure how to debug this any further (I could try to throw out Flask-SqlAlchemy and see how it goes, but would like to find an easier way first). Any suggestions are appreciated.
well again, part of your system is saying:
conn = engine.connect()
and another part is saying:
sess = Session(engine)
sess.<do stuff> , which means, engine.connect(), which means, two connections concurrently.
A true integration would mean that your env.py would use that same Session for connectivity and transactional context:
env.py
from myapp import how_i_get_my_session
session = how_i_get_my_session()
connection = session.connection