How to configure multiple databases

48 views
Skip to first unread message

Charles Reese

unread,
May 12, 2014, 9:27:27 PM5/12/14
to sqlalchem...@googlegroups.com
I need to specify different databases for different configurations, one for running migrations, one for units tests, one for Jenkins...

Here is what I currently do:

alembic/env.py:

def run_migrations_online():
    engine = create_engine(
        create_app('settings.yaml').config['DATABASE_URL'],
        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()

That works for regular migrations, but not for tests. What is the standard way to do this?

Michael Bayer

unread,
May 12, 2014, 11:52:14 PM5/12/14
to sqlalchem...@googlegroups.com

there’s no standard per se.  I’m partial to .ini files and in particular a test.ini file for tests.  Environment variables are another option.     The app overall needs a way to differentiate database urls for tests vs. running normally, so migrations aren't special.  The migration environment should draw upon the same source of connectivity as that of the rest of the app.   



--
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.

Charles Reese

unread,
May 13, 2014, 10:22:54 AM5/13/14
to sqlalchem...@googlegroups.com
Hi Mike,

I can't use ini files because I don't know which database to use until the test is running. However, I was able to solve via tags.


--
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy-alembic/UzGMaIPjyhk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy-alem...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages