Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: javaes/alembic-viz
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: dfmedia/alembic-viz
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dfmedia-master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 5 commits
  • 4 files changed
  • 2 contributors

Commits on Feb 25, 2020

  1. Use format for digraph output

    mschmo committed Feb 25, 2020
    Copy the full SHA
    711075b View commit details

Commits on Mar 24, 2020

  1. highlight and label release revisions

    Elliott Shugerman committed Mar 24, 2020
    Copy the full SHA
    c9d8667 View commit details
  2. fix readme headings

    Elliott Shugerman committed Mar 24, 2020
    Copy the full SHA
    8623bce View commit details
  3. Merge pull request #1 from eeshugerman/master

    highlight and label release revisions
    mschmo authored Mar 24, 2020
    Copy the full SHA
    7d43401 View commit details

Commits on Jun 30, 2020

  1. update requirements.txt

    - remove autogenerated pip-compile stuff
    - permit newer versions of alembic
    Elliott Shugerman authored and mschmo committed Jun 30, 2020
    Copy the full SHA
    00b5ef3 View commit details
Showing with 38 additions and 22 deletions.
  1. +4 −4 README.md
  2. +1 −1 alembic_viz/alembic_viz.py
  3. +32 −6 alembic_viz/utils.py
  4. +1 −11 requirements.txt
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]

@@ -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
@@ -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)


38 changes: 32 additions & 6 deletions alembic_viz/utils.py
Original file line number Diff line number Diff line change
@@ -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)

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


def generate_revision_graph(revisions, format):
dot = Digraph(format='png')
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
12 changes: 1 addition & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements.txt requirements.in
#
alembic==1.3.0
alembic>=1.3.0
click==7.0
graphviz==0.13
Mako==1.1.0 # via alembic
MarkupSafe==1.1.1 # via mako
python-editor==1.0.4 # via alembic
SQLAlchemy==1.3.10 # via alembic