Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion alembic/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ def history(
rev_range: Optional[str] = None,
verbose: bool = False,
indicate_current: bool = False,
reversed: bool = False,
) -> None:
"""List changeset scripts in chronological order.

Expand Down Expand Up @@ -592,7 +593,7 @@ def history(

def _display_history(config, script, base, head, currents=()):
for sc in script.walk_revisions(
base=base or "base", head=head or "heads"
base=base or "base", head=head or "heads", reversed=reversed
):
if indicate_current:
sc._db_current_indicator = sc.revision in currents
Expand Down
8 changes: 8 additions & 0 deletions alembic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,14 @@ def __init__(self, prog: Optional[str] = None) -> None:
"generating one",
),
),
"reversed": (
"-R",
"--reversed",
dict(
action="store_true",
help="Show the history in the reversed order",
),
),
"version_path": (
"--version-path",
dict(
Expand Down
8 changes: 6 additions & 2 deletions alembic/script/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def _catch_revision_errors(
raise util.CommandError(err.args[0]) from err

def walk_revisions(
self, base: str = "base", head: str = "heads"
self, base: str = "base", head: str = "heads", reversed: bool = False
) -> Iterator[Script]:
"""Iterate through all revisions.

Expand All @@ -261,7 +261,11 @@ def walk_revisions(
"""
with self._catch_revision_errors(start=base, end=head):
for rev in self.revision_map.iterate_revisions(
head, base, inclusive=True, assert_relative_length=False
head,
base,
inclusive=True,
assert_relative_length=False,
reversed=reversed,
):
yield cast(Script, rev)

Expand Down
8 changes: 7 additions & 1 deletion alembic/script/revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ def iterate_revisions(
inclusive: bool = False,
assert_relative_length: bool = True,
select_for_downgrade: bool = False,
reversed: bool = False,
) -> Iterator[Revision]:
"""Iterate through script revisions, starting at the given
upper revision identifier and ending at the lower.
Expand All @@ -819,7 +820,12 @@ def iterate_revisions(
assert_relative_length=assert_relative_length,
)

for node in self._topological_sort(revisions, heads):
topological_sort = (
self._topological_sort(revisions, heads)[::-1]
if reversed
else self._topological_sort(revisions, heads)
)
for node in topological_sort:
yield not_none(self.get_revision(node))

def _get_descendant_nodes(
Expand Down