specify certain database in command-line

Issue #120 resolved
holsety huang
created an issue

I want something like:

alembic -d mysql://user:password@localhost/database upgrade head

specify the database in config file is not so convenient.

Comments (4)

  1. Michael Bayer repo owner

    because alembic has no notion of a single database URL, it can't be a fixed argument like that. the best approach would be an option like -x "opt=value" which allows arbitrary configuration options to be added to the command line.

  2. Michael Bayer repo owner

    amazingly, I added this feature the other day in response to a totally different issue, and I named it "-x" just like I proposed here.

    So with 0.6.0 you'd say:

    alembic -x dbname=mysql://user:pw@host/db upgrade head

    then in your env.py:

        cmd_line_url = context.get_x_argument(as_dictionary=True).get('dbname])
        if cmd_line_url:
            engine = create_engine(cmd_line_url)
            engine = engine_from_config(
        connection = engine.connect()
  3. Log in to comment