Issues

Issue #120 resolved

specify certain database in command-line

holsety
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. Mike 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. Mike 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)
        else:
            engine = engine_from_config(
                    config.get_section(config.config_ini_section),
                    prefix='sqlalchemy.',
                    poolclass=pool.NullPool)
    
        connection = engine.connect()
    
  3. Log in to comment