diff options
author | misebox <misebox@gmail.com> | 2018-03-07 16:20:00 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-03-07 17:09:12 -0500 |
commit | 22294fff73c017529d0c12bb212f789e600d9965 (patch) | |
tree | ff65311337673f9651161fffe3bbfa2d7b8a2cd4 /alembic/command.py | |
parent | 132ec8cf696ef9588599ae23d45ea349542197ce (diff) | |
download | alembic-22294fff73c017529d0c12bb212f789e600d9965.tar.gz |
Add indicate-current option into history command
Added new flag ``--indicate-current`` to the ``alembic history`` command.
When listing versions, it will include the token "(current)" to indicate
the given version is a current head in the target database. Pull request
courtesy Kazutaka Mise.
Fixes: #481
Change-Id: I7daa02b455aaba76c50d0e1febbdc6908693d4c9
Pull-request: https://bitbucket.org/zzzeek/alembic/pull-requests/77
Diffstat (limited to 'alembic/command.py')
-rw-r--r-- | alembic/command.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/alembic/command.py b/alembic/command.py index 8675005..cd61fd1 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -321,7 +321,7 @@ def show(config, rev): config.print_stdout(sc.log_entry) -def history(config, rev_range=None, verbose=False): +def history(config, rev_range=None, verbose=False, indicate_current=False): """List changeset scripts in chronological order. :param config: a :class:`.Config` instance. @@ -330,6 +330,10 @@ def history(config, rev_range=None, verbose=False): :param verbose: output in verbose mode. + :param indicate_current: indicate current revision. + + ..versionadded:: 0.9.9 + """ script = ScriptDirectory.from_config(config) @@ -344,25 +348,29 @@ def history(config, rev_range=None, verbose=False): environment = util.asbool( config.get_main_option("revision_environment") - ) + ) or indicate_current - def _display_history(config, script, base, head): + def _display_history(config, script, base, head, currents=()): for sc in script.walk_revisions( base=base or "base", head=head or "heads"): + + if indicate_current: + sc._db_current_indicator = sc.revision in currents + config.print_stdout( sc.cmd_format( verbose=verbose, include_branches=True, include_doc=True, include_parents=True)) - def _display_history_w_current(config, script, base=None, head=None): + def _display_history_w_current(config, script, base, head): def _display_current_history(rev, context): - if head is None: - _display_history(config, script, base, rev) - elif base is None: - _display_history(config, script, rev, head) + if head == 'current': + _display_history(config, script, base, rev, rev) + elif base == 'current': + _display_history(config, script, rev, head, rev) else: - _display_history(config, script, base, head) + _display_history(config, script, base, head, rev) return [] with EnvironmentContext( @@ -372,11 +380,7 @@ def history(config, rev_range=None, verbose=False): ): script.run_env() - if base == "current": - _display_history_w_current(config, script, head=head) - elif head == "current": - _display_history_w_current(config, script, base=base) - elif environment: + if base == "current" or head == "current" or environment: _display_history_w_current(config, script, base, head) else: _display_history(config, script, base, head) |