Running migrations programmatically for automated tests

261 views
Skip to first unread message

Diogo Baeder

unread,
Feb 9, 2015, 4:16:46 PM2/9/15
to sqlalchem...@googlegroups.com
Hi guys,

I'm trying to run database migrations programmatically, inside a setUpClass() method, sharing a preconfigured connection, but the migration execution gets stuck at the "alembic_version" table creation (somehow the cursor just gets stuck at this point, not sure why). It's important that I can run the migrations at this point, since I do a rollback at tearDownClass() to throw away any database changes.

Is there any tutorial or recipe for how to use alembic programmatically this way?

Thanks,
Diogo

Michael Bayer

unread,
Feb 9, 2015, 4:28:40 PM2/9/15
to sqlalchem...@googlegroups.com
the latest recipe that shows this is:

http://alembic.readthedocs.org/en/latest/cookbook.html#sharing-a-connection-with-a-series-of-migration-commands-and-environments

that includes sharing the connection and running command.upgrade.

cursors getting stuck usually happens when tables are being dropped, because they are locked. this is more unusual on the setup, but you’d need to see if the cursor is attempting to execute a statement against a resource that is locked by another connection (often a previous test that didn’t tear down).
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alem...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Diogo Baeder

unread,
Feb 9, 2015, 9:52:23 PM2/9/15
to sqlalchem...@googlegroups.com
Thanks, I didn't notice that I had to run it through alembic.command. After I worked a bit more on it, it worked. :-)

Cheers,
Diogo
> To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages