コード例 #1
0
    def test___init__(self, scripts_dir):
        with pytest.raises(AmbixError) as err_info:
            MigrationHome(home_path=pathlib.Path("/not/a/valid/path"))
        assert "doesn't exist" in str(err_info.value)

        home = MigrationHome(scripts_dir)
        # Starting graph should look like this:
        # .......................
        # .                     .
        # .      aaaaaa         .
        # .        |            .
        # .      bbbbbb         .
        # .       / \           .
        # .      /   \          .
        # .  ccccc  dddddd      .
        # .     \    /  \       .
        # .      \  /    \      .
        # .      eeeee  ffffff  .
        # .         \    /      .
        # .          \  /       .
        # .         gggggg      .
        # .                     .
        # .......................
        assert home.home_path == scripts_dir
        assert sorted([s for s in home.migrations]) == [
            "aaaaaa",
            "bbbbbb",
            "cccccc",
            "dddddd",
            "eeeeee",
            "ffffff",
            "gggggg",
        ]
コード例 #2
0
 def test_rebase__normal_rebase(self, scripts_dir):
     home = MigrationHome(scripts_dir)
     home.migrations["gggggg"].change_down_revision("cccccc")
     home.migrations["eeeeee"].change_down_revision("dddddd")
     # now, the graph should look like this:
     # .......................
     # .                     .
     # .      aaaaaa         .
     # .        |            .
     # .      bbbbbb         .
     # .       / \           .
     # .      /   \          .
     # .  ccccc  dddddd      .
     # .   |      /  \       .
     # .   |     /    \      .
     # .   |  eeeee  ffffff  .
     # .   |                 .
     # .  gggggg             .
     # .                     .
     # .                     .
     # .......................
     home.rebase("dddddd", "gggggg")
     assert home.generate_dependency_graph() == {
         "aaaaaa": {None},
         "bbbbbb": {"aaaaaa"},
         "cccccc": {"bbbbbb"},
         "dddddd": {"gggggg"},
         "eeeeee": {"dddddd"},
         "ffffff": {"dddddd"},
         "gggggg": {"cccccc"},
     }
コード例 #3
0
ファイル: flatten.py プロジェクト: dusktreader/ambix
def flatten(
    alembic_home_dir: pathlib.Path = typer.Option(
        "etc/alembic/versions",
        exists=True,
        help="The directory where the alembic migrations live",
    ),
):
    home = MigrationHome(alembic_home_dir)
    home.flatten()
コード例 #4
0
 def test_generate_dependency_graph(self, scripts_dir):
     home = MigrationHome(scripts_dir)
     assert home.generate_dependency_graph() == {
         "aaaaaa": {None},
         "bbbbbb": {"aaaaaa"},
         "cccccc": {"bbbbbb"},
         "dddddd": {"bbbbbb"},
         "eeeeee": {"cccccc", "dddddd"},
         "ffffff": {"dddddd"},
         "gggggg": {"eeeeee", "ffffff"},
     }
コード例 #5
0
 def test_move__multiple_new_base(self, scripts_dir):
     home = MigrationHome(scripts_dir)
     home.move("eeeeee", "ffffff", "dddddd")
     assert home.generate_dependency_graph() == {
         "aaaaaa": {None},
         "bbbbbb": {"aaaaaa"},
         "cccccc": {"bbbbbb"},
         "dddddd": {"bbbbbb"},
         "ffffff": {"dddddd"},
         "gggggg": {"ffffff", "cccccc", "dddddd"},
         "eeeeee": {"ffffff", "dddddd"},
     }
コード例 #6
0
ファイル: prune.py プロジェクト: dusktreader/ambix
def prune(
    revision: str = typer.Argument(
        ...,
        help="The revision hash to be moved",
    ),
    alembic_home_dir: pathlib.Path = typer.Option(
        "etc/alembic/versions",
        exists=True,
        help="The directory where the alembic migrations live",
    ),
):
    home = MigrationHome(alembic_home_dir)
    home.prune(revision)
コード例 #7
0
 def test_prune__delete_head(self, scripts_dir):
     home = MigrationHome(scripts_dir)
     assert scripts_dir.joinpath("gggggg-dummy-migration.py").exists()
     home.prune("gggggg")
     assert home.generate_dependency_graph() == {
         "aaaaaa": {None},
         "bbbbbb": {"aaaaaa"},
         "cccccc": {"bbbbbb"},
         "dddddd": {"bbbbbb"},
         "eeeeee": {"cccccc", "dddddd"},
         "ffffff": {"dddddd"},
     }
     assert not scripts_dir.joinpath("gggggg-dummy-migration.py").exists()
コード例 #8
0
 def test_prune__delete_complex_branch(self, scripts_dir):
     home = MigrationHome(scripts_dir)
     assert os.path.exists(
         os.path.join(scripts_dir, "dddddd-dummy-migration.py"))
     home.prune("dddddd")
     assert home.generate_dependency_graph() == {
         "aaaaaa": {None},
         "bbbbbb": {"aaaaaa"},
         "cccccc": {"bbbbbb"},
         "eeeeee": {"bbbbbb", "cccccc"},
         "ffffff": {"bbbbbb"},
         "gggggg": {"eeeeee", "ffffff"},
     }
     assert not os.path.exists(
         os.path.join(scripts_dir, "dddddd-dummy-migration.py"))
コード例 #9
0
    def test_ancestors(self, scripts_dir):
        home = MigrationHome(scripts_dir)
        assert list(home.ancestors("eeeeee")) == [
            "aaaaaa",
            "bbbbbb",
            "cccccc",
            "dddddd",
        ]

        assert list(home.ancestors("eeeeee")) == [
            "aaaaaa",
            "bbbbbb",
            "cccccc",
            "dddddd",
        ]
コード例 #10
0
ファイル: render.py プロジェクト: dusktreader/ambix
def render(
    alembic_home_dir: pathlib.Path = typer.Option(
        "etc/alembic/versions",
        exists=True,
        help="The directory where the alembic migrations live",
    ),
):
    home = MigrationHome(alembic_home_dir)
    graph = home.generate_dependency_graph()
    print("strict digraph {")
    for (key, value) in graph.items():
        for child in value:
            if child is None:
                continue
            print(f"  {key} -> {child}")
    print("}")
コード例 #11
0
ファイル: move.py プロジェクト: dusktreader/ambix
def move(
    revision: str = typer.Argument(
        ...,
        help="The revision hash to be moved",
    ),
    new_bases: typing.List[str] = typer.Argument(
        ...,
        help="The new base(s) to base the revision upon",
    ),
    alembic_home_dir: pathlib.Path = typer.Option(
        "etc/alembic/versions",
        exists=True,
        help="The directory where the alembic migrations live",
    ),
):
    home = MigrationHome(alembic_home_dir)
    home.move(revision, *new_bases)
コード例 #12
0
 def test_rebase__fails_if_new_ancestry_is_incoherent(self, scripts_dir):
     home = MigrationHome(scripts_dir)
     with pytest.raises(AmbixError, match="Cannot rebase"):
         home.rebase("dddddd", "gggggg")
コード例 #13
0
 def test_heads(self, scripts_dir):
     home = MigrationHome(scripts_dir)
     assert home.heads() == {"gggggg"}
     home.prune("gggggg")
     assert home.heads() == {"eeeeee", "ffffff"}