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
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.
:param verbose: output in verbose mode.
+ :param indicate_current: indicate current revision.
+
+ ..versionadded:: 0.9.9
+
"""
script = ScriptDirectory.from_config(config)
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(
):
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)
action="store",
help="Specify a revision range; "
"format is [start]:[end]")
+ ),
+ 'indicate_current': (
+ "-i", "--indicate-current",
+ dict(
+ action="store_true",
+ help="Indicate the current revision"
+ )
)
}
positional_help = {
path = None
"""Filesystem path of the script."""
+ _db_current_indicator = None
+ """Utility variable which when set will cause string output to indicate
+ this is a "current" version in some database"""
+
@property
def doc(self):
"""Return the docstring given in the script."""
@property
def log_entry(self):
- entry = "Rev: %s%s%s%s\n" % (
+ entry = "Rev: %s%s%s%s%s\n" % (
self.revision,
" (head)" if self.is_head else "",
" (branchpoint)" if self.is_branch_point else "",
" (mergepoint)" if self.is_merge_point else "",
+ " (current)" if self._db_current_indicator else ""
)
if self.is_merge_point:
entry += "Merges: %s\n" % (self._format_down_revision(), )
if include_branches and self.branch_labels:
text += " (%s)" % util.format_as_comma(self.branch_labels)
if head_indicators or tree_indicators:
- text += "%s%s" % (
+ text += "%s%s%s" % (
" (head)" if self._is_real_head else "",
" (effective head)" if self.is_head and
- not self._is_real_head else ""
+ not self._is_real_head else "",
+ " (current)" if self._db_current_indicator else ""
)
if tree_indicators:
text += "%s%s" % (
--- /dev/null
+.. change::
+ :tags: feature, commands
+ :tickets: 481
+
+ 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.
""")
- def _eq_cmd_output(self, buf, expected, env_token=False):
+ def _eq_cmd_output(self, buf, expected, env_token=False, currents=()):
script = ScriptDirectory.from_config(self.cfg)
# test default encode/decode behavior as well,
# rev B has a non-ascii char in it + a coding header.
- assert_lines = [
- script.get_revision(rev).log_entry
- for rev in expected
- ]
+ assert_lines = []
+ for _id in expected:
+ rev = script.get_revision(_id)
+ if _id in currents:
+ rev._db_current_indicator = True
+ assert_lines.append(rev.log_entry)
+
if env_token:
assert_lines.insert(0, "environment included OK")
command.history(self.cfg, verbose=True)
self._eq_cmd_output(buf, [self.c, self.b, self.a], env_token=True)
+ def test_history_indicate_current(self):
+ command.stamp(self.cfg, (self.b,))
+ self.cfg.stdout = buf = self._buf_fixture()
+ command.history(self.cfg, indicate_current=True, verbose=True)
+ self._eq_cmd_output(
+ buf, [self.c, self.b, self.a], currents=(self.b,), env_token=True)
+
class CurrentTest(_BufMixin, TestBase):