Пример #1
0
 def test_downgrade_branch_dependency(self):
     """c2branch depends on c1branch so taking down c1branch requires taking
     down both"""
     destination = "c1branch@{}".format(self.b.revision)
     source = self.d1.revision, self.d2.revision
     revs = self.env._downgrade_revs(destination, source)
     # Drops c1, d1 as requested, also drops d2 due to dependence on d1.
     # Full ordering of migrations is not consistent so verify partial
     # ordering only.
     rev_ids = [rev.revision.revision for rev in revs]
     assert set(rev_ids) == {
         self.c1.revision,
         self.d1.revision,
         self.d2.revision,
     }
     assert rev_ids.index(self.d1.revision) < rev_ids.index(
         self.c1.revision)
     assert rev_ids.index(self.d2.revision) < rev_ids.index(
         self.c1.revision)
     # Verify final state.
     heads = set(util.to_tuple(source, default=()))
     head = HeadMaintainer(mock.Mock(), heads)
     for rev in revs:
         head.update_to_step(rev)
     eq_(head.heads, set([self.c2.revision]))
Пример #2
0
 def _assert_upgrade(self, destination, source, expected, expected_heads):
     revs = self.env._upgrade_revs(destination, source)
     eq_(revs, expected)
     heads = set(util.to_tuple(source, default=()))
     head = HeadMaintainer(mock.Mock(), heads)
     for rev in revs:
         head.update_to_step(rev)
     eq_(head.heads, expected_heads)
Пример #3
0
 def _assert_upgrade(self, destination, source, expected, expected_heads):
     revs = self.env._upgrade_revs(destination, source)
     eq_(revs, expected)
     heads = set(util.to_tuple(source, default=()))
     head = HeadMaintainer(mock.Mock(), heads)
     for rev in revs:
         head.update_to_step(rev)
     eq_(head.heads, expected_heads)
Пример #4
0
 def do_stamp(rev, context):
     return script._stamp_revs(util.to_tuple(destination_revs), rev)
Пример #5
0
    def stamp(self, revision, sql=False, tag=None, purge=False):
        """'stamp' the revision table with the given revision; don't
        run any migrations.

        :param revision: target revision or list of revisions.   May be a list
        to indicate stamping of multiple branch heads.

        .. note:: this parameter is called "revisions" in the command line
            interface.

        .. versionchanged:: 1.2  The revision may be a single revision or
            list of revisions when stamping multiple branch heads.

        :param sql: use ``--sql`` mode

        :param tag: an arbitrary "tag" that can be intercepted by custom
        ``env.py`` scripts via the :class:`.EnvironmentContext.get_tag_argument`
        method.

        :param purge: delete all entries in the version table before stamping.

        .. versionadded:: 1.2

        """

        config = self.config
        script = self.script_directory
        config.attributes["engine"] = self.engine

        output_buffer = io.StringIO()
        config.attributes["output_buffer"] = output_buffer

        starting_rev = None
        if sql:
            destination_revs = []
            for _revision in util.to_list(revision):
                if ":" in _revision:
                    srev, _revision = _revision.split(":", 2)

                    if starting_rev != srev:
                        if starting_rev is None:
                            starting_rev = srev
                        else:
                            raise util.CommandError(
                                "Stamp operation with --sql only supports a "
                                "single starting revision at a time")
                destination_revs.append(_revision)
        else:
            destination_revs = util.to_list(revision)

        def do_stamp(rev, context):
            return script._stamp_revs(util.to_tuple(destination_revs), rev)

        with EnvironmentContext(
                config,
                script,
                fn=do_stamp,
                as_sql=sql,
                starting_rev=starting_rev if sql else None,
                destination_rev=util.to_tuple(destination_revs),
                tag=tag,
                purge=purge,
        ):
            script.run_env()
            output_buffer.seek(0)
            return output_buffer.read()