Python alembic.command.merge() Examples

The following are 13 code examples of alembic.command.merge(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module alembic.command , or try the search function .
Example #1
Source File: cli.py    From yui with GNU Affero General Public License v3.0 6 votes vote down vote up
def merge(
    config,
    revisions: str,
    message: Optional[str],
    branch_label=Optional[str],
    rev_id=Optional[str],
):
    """Merge two revisions together.  Creates a new migration file."""
    bot = Bot(config)

    directory = os.path.join('yui', 'migrations')
    c = Config(os.path.join(directory, 'alembic.ini'))
    c.set_main_option('script_location', directory)
    c.set_main_option('sqlalchemy.url', bot.config.DATABASE_URL)
    c.attributes['Base'] = bot.orm_base

    command.merge(
        c, revisions, message=message, branch_label=branch_label, rev_id=rev_id
    ) 
Example #2
Source File: test_command.py    From alembic with MIT License 6 votes vote down vote up
def test_create_rev_plain_db_not_up_to_date_multi_heads(self):
        self._env_fixture()
        command.revision(self.cfg)
        rev2 = command.revision(self.cfg)
        rev3a = command.revision(self.cfg)
        command.revision(self.cfg, head=rev2.revision, splice=True)
        command.upgrade(self.cfg, "heads")
        command.revision(self.cfg, head=rev3a.revision)

        assert_raises_message(
            util.CommandError,
            "Multiple heads are present; please specify the head revision "
            "on which the new revision should be based, or perform a merge.",
            command.revision,
            self.cfg,
        ) 
Example #3
Source File: test_command.py    From alembic with MIT License 6 votes vote down vote up
def test_create_rev_autogen_need_to_select_head(self):
        self._env_fixture()
        command.revision(self.cfg)
        rev2 = command.revision(self.cfg)
        command.revision(self.cfg)
        command.revision(self.cfg, head=rev2.revision, splice=True)
        command.upgrade(self.cfg, "heads")
        # there's multiple heads present
        assert_raises_message(
            util.CommandError,
            "Multiple heads are present; please specify the head revision "
            "on which the new revision should be based, or perform a merge.",
            command.revision,
            self.cfg,
            autogenerate=True,
        ) 
Example #4
Source File: __init__.py    From jbox with MIT License 5 votes vote down vote up
def merge(directory=None, revisions='', message=None, branch_label=None,
          rev_id=None):
    """Merge two revisions together.  Creates a new migration file"""
    if alembic_version >= (0, 7, 0):
        config = current_app.extensions['migrate'].migrate.get_config(
            directory)
        command.merge(config, revisions, message=message,
                      branch_label=branch_label, rev_id=rev_id)
    else:
        raise RuntimeError('Alembic 0.7.0 or greater is required') 
Example #5
Source File: db.py    From flask-restplus-server-example with MIT License 5 votes vote down vote up
def merge(context, directory='migrations', revisions='', message=None, branch_label=None,
          rev_id=None):
    """Merge two revisions together.  Creates a new migration file"""
    if alembic_version >= (0, 7, 0):
        config = _get_config(directory)
        command.merge(config, revisions, message=message,
                      branch_label=branch_label, rev_id=rev_id)
    else:
        raise RuntimeError('Alembic 0.7.0 or greater is required') 
Example #6
Source File: test_command.py    From alembic with MIT License 5 votes vote down vote up
def test_create_rev_plain_need_to_select_head(self):
        self._env_fixture()
        command.revision(self.cfg)
        rev2 = command.revision(self.cfg)
        command.revision(self.cfg)
        command.revision(self.cfg, head=rev2.revision, splice=True)
        command.upgrade(self.cfg, "heads")
        # there's multiple heads present
        assert_raises_message(
            util.CommandError,
            "Multiple heads are present; please specify the head revision "
            "on which the new revision should be based, or perform a merge.",
            command.revision,
            self.cfg,
        ) 
Example #7
Source File: test_command.py    From alembic with MIT License 5 votes vote down vote up
def test_create_rev_plain_post_merge(self):
        self._env_fixture()
        command.revision(self.cfg)
        rev2 = command.revision(self.cfg)
        command.revision(self.cfg)
        command.revision(self.cfg, head=rev2.revision, splice=True)
        command.merge(self.cfg, "heads")
        command.revision(self.cfg) 
Example #8
Source File: test_command.py    From alembic with MIT License 5 votes vote down vote up
def test_create_rev_autogenerate_post_merge(self):
        self._env_fixture()
        command.revision(self.cfg)
        rev2 = command.revision(self.cfg)
        command.revision(self.cfg)
        command.revision(self.cfg, head=rev2.revision, splice=True)
        command.merge(self.cfg, "heads")
        command.upgrade(self.cfg, "heads")
        command.revision(self.cfg, autogenerate=True) 
Example #9
Source File: test_command.py    From alembic with MIT License 5 votes vote down vote up
def test_help_text(self):
        commands = {
            fn.__name__
            for fn in [getattr(command, n) for n in dir(command)]
            if inspect.isfunction(fn)
            and fn.__name__[0] != "_"
            and fn.__module__ == "alembic.command"
        }
        # make sure we found them
        assert commands.intersection(
            {"upgrade", "downgrade", "merge", "revision"}
        )

        # catch help text coming intersection
        with mock.patch("alembic.config.ArgumentParser") as argparse:
            config.CommandLine()
            for kall in argparse().add_subparsers().mock_calls:
                for sub_kall in kall.call_list():
                    if sub_kall[0] == "add_parser":
                        cmdname = sub_kall[1][0]
                        help_text = sub_kall[2]["help"]
                        if help_text:
                            commands.remove(cmdname)
                            # more than two spaces
                            assert not re.search(r"   ", help_text)

                            # no markup stuff
                            assert ":" not in help_text

                            # no newlines
                            assert "\n" not in help_text

                            # ends with a period
                            assert help_text.endswith(".")

                            # not too long
                            assert len(help_text) < 80
        assert not commands, "Commands without help text: %s" % commands 
Example #10
Source File: migrations.py    From lux with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def merge(self, message, branch_label=None, rev_id=None, revisions=None):
        alembic_cmd.merge(self.cfg, message=message,
                          branch_label=branch_label,
                          rev_id=rev_id, revisions=revisions) 
Example #11
Source File: alembic_wrapper.py    From build-relengapi with Mozilla Public License 2.0 5 votes vote down vote up
def make_parser(self, subparsers):
        parser = subparsers.add_parser('merge', help=self.merge.__doc__)
        parser.add_argument('--rev-id', dest='rev_id', default=None,
                            help=('Specify a hardcoded revision id instead of '
                                  'generating one'))
        parser.add_argument('--branch-label', dest='branch_label', default=None,
                            help=('Specify a branch label to apply to the new '
                                  'revision'))
        parser.add_argument('-m', '--message', dest='message', default=None)
        parser.add_argument('revisions',
                            help='one or more revisions, or "heads" for all heads')
        parser.add_argument('-d', '--directory', dest='directory', default=None,
                            help=("migration script directory (default is "
                                  "'migrations')"))
        return parser 
Example #12
Source File: alembic_wrapper.py    From build-relengapi with Mozilla Public License 2.0 5 votes vote down vote up
def run(self, parser, args):
        self.merge(**vars(args)) 
Example #13
Source File: alembic_wrapper.py    From build-relengapi with Mozilla Public License 2.0 5 votes vote down vote up
def merge(self, directory=None, revisions='', message=None, branch_label=None,
              rev_id=None, **kwargs):  # pragma: no cover
        """Merge two revisions together.  Creates a new migration file"""
        config = _get_config(directory)
        command.merge(config, revisions, message=message,
                      branch_label=branch_label, rev_id=rev_id)