Skip to content

Commit

Permalink
Merge pull request #1 from eeshugerman/master
Browse files Browse the repository at this point in the history
highlight and label release revisions
  • Loading branch information
mschmo authored Mar 24, 2020
2 parents 711075b + 8623bce commit 7d43401
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
####Installation
#### Installation
`pip install alembic-viz --user`

####Usage
#### Usage
```bash
Usage: alembic-viz [OPTIONS]

Expand All @@ -13,8 +13,8 @@ Options:
--help Show this message and exit.
```

####Todo
#### Todo
* add revision commit messages to graph
* handle `depends_on` relationships properly
* add test cases
* ...
* ...
2 changes: 1 addition & 1 deletion alembic_viz/alembic_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def cli(config, name, filename, format):
revisions = get_revisions(alembic_config)
except CommandError as e:
sys.exit(e)
dot = generate_revision_graph(revisions, format)
dot = generate_revision_graph(revisions, format, alembic_config)
dot.render(filename=filename)


Expand Down
36 changes: 31 additions & 5 deletions alembic_viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
from graphviz import Digraph


RELEASE_REVISION_TAG = '[RELEASE-MERGE]'


def is_release_revision(revision):
rval = revision.doc.startswith(RELEASE_REVISION_TAG)
return rval


def get_node_name(revision):
if is_release_revision(revision):
return revision.doc[len(RELEASE_REVISION_TAG) + 1:]
else:
return revision.revision


def get_revisions(config, rev_range=None):
script = ScriptDirectory.from_config(config)

Expand All @@ -19,16 +34,27 @@ def get_revisions(config, rev_range=None):
)


def generate_revision_graph(revisions, fmt):
def generate_revision_graph(revisions, fmt, config):
script = ScriptDirectory.from_config(config)
dot = Digraph(format=fmt)
for revision in revisions:
dot.node(revision.revision)
color = 'turquoise' if is_release_revision(revision) else None
node_name = get_node_name(revision)
dot.node(node_name, color=color)

if revision.down_revision is None:
dot.edge('base', revision.revision)
dot.edge('base', get_node_name(revision))
continue

if isinstance(revision.down_revision, str):
dot.edge(revision.down_revision, revision.revision)
down_revision = script.get_revision(revision.down_revision)
down_node_name = get_node_name(down_revision)
dot.edge(down_node_name, get_node_name(revision))
continue

for down_revision in revision.down_revision:
dot.edge(down_revision, revision.revision)
down_revision = script.get_revision(down_revision)
down_node_name = get_node_name(down_revision)
dot.edge(down_node_name, node_name)

return dot

0 comments on commit 7d43401

Please sign in to comment.