def merge(revisions, message): """Create merge revision.""" if len(revisions) < 2: raise CommandError("Enter two or more revisions.") command.merge(alembic_cfg, revisions, message)
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 = _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")
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)
def merge(directory, message, branch_label, rev_id, revisions): """Merge two revisions together, creating a new revision file""" config = get_config(directory) command.merge(config, revisions, message=message, branch_label=branch_label, rev_id=rev_id)
def merge(self, message=None, revisions=None): if not message: raise AlembicCommandError('Please provide a message') revision_id = self.generate_revision_id() command.merge(self.config, message=message, revisions=revisions, rev_id=revision_id)
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 = _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')
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)
def merge(context, directory='migrations', revisions='', message=None, branch_label=None, rev_id=None): """Merge two revisions together. Creates a new migration file""" from app import create_app with create_app().app_context(): 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')
def merge(directory=None, revisions='', message=None, branch_label=None, rev_id=None): """Merge two revisions together. Creates a new migration file""" config = current_app.extensions['migrate'].migrate.get_config(directory) command.merge(config, revisions, message=message, branch_label=branch_label, rev_id=rev_id)
def merge(directory=None, revisions='', message=None, branch_label=None, rev_id=None): """Merge two revisions together. Creates a new migration file""" config = migrate_manager.migrate_config.migrate.get_config(directory) command.merge(config, revisions, message=message, branch_label=branch_label, rev_id=rev_id)
def test_create_rev_autogenerate_db_not_up_to_date_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.upgrade(self.cfg, "heads") command.merge(self.cfg, "heads") assert_raises_message(util.CommandError, "Target database is not up to date.", command.revision, self.cfg, autogenerate=True)
def test_create_rev_autogenerate_db_not_up_to_date_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.upgrade(self.cfg, "heads") command.merge(self.cfg, "heads") assert_raises_message( util.CommandError, "Target database is not up to date.", command.revision, self.cfg, autogenerate=True )
def cli_db_merge(revisions, message, branche_label, rev_id): """ Merge two (or more) revisions together. Creates a new migration file. """ alembic_cfg = AlembicConfig("alembic.ini") alembic_cfg.set_main_option("script_location", str(Path() / "db_migrations")) command.merge( config=alembic_cfg, revisions=revisions, message=message, branch_label=branche_label, rev_id=rev_id, )
def merge_revisions(revisions, revision_type, message): """Combines two revisions.""" from alembic import command as alembic_command from alembic.config import Config as AlembicConfig alembic_cfg = AlembicConfig(config.ALEMBIC_INI_PATH) if revision_type == "core": path = config.ALEMBIC_CORE_REVISION_PATH elif revision_type == "tenant": path = config.ALEMBIC_TENANT_REVISION_PATH alembic_cfg.set_main_option("script_location", path) alembic_command.merge(alembic_cfg, revisions, message=message)
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)
def merge(app, revisions: "one or more revisions, or 'heads' for all heads", *, message: "message string to use with 'revision'" = None, branch_label: 'specify a branch apply to the new revision' = None, rev_id: ('specify a hardcoded revision id instead of generating ' 'one') = None): """Merge two revisions together. Creates a new migration file.""" alembic.merge( _get_config(app), revisions=revisions, message=message, branch_label=branch_label, rev_id=rev_id, )
def merge(self): """ Perform merging of migrations if exists more then one head """ revision_heads = [head for head in self.heads] if len(revision_heads) < 2: util.msg('There are not migrations for merge') else: print('\n\n-------------------------------------------------') merge_choices = [ choice for choice in self.__merge_choices__(revision_heads) ] for choice in merge_choices: rev_1 = choice['migration1'] rev_2 = choice['migration2'] rev_1_branch = self.__branch_name__(rev_1) rev_2_branch = self.__branch_name__(rev_2) util.msg('{}) {}:{} -> {}:{}'.format(choice["inc"], rev_1_branch, rev_1, rev_2_branch, rev_2)) util.msg('-------------------------------------------------\n\n') choice = input('Choose migration:\n') try: choice = int(choice) if not (1 <= choice <= len(merge_choices)): util.msg('Input value must be between 1 and {}'.format( len(merge_choices))) exit(0) rev_1 = merge_choices[choice - 1]['migration1'] rev_2 = merge_choices[choice - 1]['migration2'] command.merge(self.init_config, revisions=[rev_2.revision, rev_1.revision], message='merge_{}({})_into_{}({})'.format( rev_1, rev_1.branch_labels, rev_2, rev_2.branch_labels)) except ValueError: util.msg('Your choice must be of int data type')
def run_alembic_cmd(self, opt): ''' Logic for running different Alembic commands. ''' from alembic import command as alembic_cmd config = self.get_config() # command consume any number of parameters but first is command name cmd = opt.command.pop(0) # init command needs to point to lux template, not alembic default if cmd == 'init': dirname = config.get_main_option('script_location') # line 63 will be executed in: # https://github.com/zzzeek/alembic/blob/master/alembic/command.py # since we do not use any *.ini file, we simply silence error # about referenced before assignment as it have no negative impact. try: alembic_cmd.init(config, dirname, template='lux') except UnboundLocalError: # pragma nocover pass # merge required two revision name elif cmd == 'merge': if len(opt.command) != 2: raise CommandError('Command %s required revisions id.' % cmd) alembic_cmd.merge(config, opt.command, message=opt.msg, branch_label=opt.branch) elif cmd == 'revision': alembic_cmd.revision(config, message=opt.msg, branch_label=opt.branch) # auto command is a shortcut for `revision --autogenerate` elif cmd == 'auto': alembic_cmd.revision(config, autogenerate=True, message=opt.msg, branch_label=opt.branch) # this commands required revision name, but do not take any message or # branch labels elif cmd in ('show', 'stamp', 'upgrade', 'downgrade'): if len(opt.command) != 1: raise CommandError('Command %s required revision id' % cmd) getattr(alembic_cmd, cmd)(config, *opt.command) else: # execute commands without any additional params getattr(alembic_cmd, cmd)(config)
def merge(app, revisions: "one or more revisions, or 'heads' for all heads", *, message: "message string to use with 'revision'" = None, branch_label: 'specify a branch apply to the new revision' = None, rev_id: ( 'specify a hardcoded revision id instead of generating ' 'one' ) = None): """Merge two revisions together. Creates a new migration file.""" alembic.merge( _get_config(app), revisions=revisions, message=message, branch_label=branch_label, rev_id=rev_id, )
def merge( context, directory="migrations", revisions="", message=None, branch_label=None, rev_id=None, ): """在两个迁移版本的基础上新建新的迁移版本""" 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")
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', 'models', '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)
def run_alembic_cmd(self, opt): ''' Logic for running different Alembic commands. ''' from alembic import command as alembic_cmd config = self.get_config() # command consume any number of parameters but first is command name cmd = opt.command.pop(0) # init command needs to point to lux template, not alembic default if cmd == 'init': dirname = config.get_main_option('script_location') # line 63 will be executed in: # https://github.com/zzzeek/alembic/blob/master/alembic/command.py # since we do not use any *.ini file, we simply silence error # about referenced before assignment as it have no negative impact. try: alembic_cmd.init(config, dirname, template='lux') except UnboundLocalError: # pragma nocover pass # merge required two revision name elif cmd == 'merge': if len(opt.command) != 2: raise CommandError('Command: %s required revisions id.' % cmd) alembic_cmd.merge(config, *opt.command, message=opt.msg, branch_label=opt.branch) elif cmd == 'revision': alembic_cmd.revision(config, message=opt.msg, branch_label=opt.branch) # auto command is a shortcut for `revision --autogenerate` elif cmd == 'auto': alembic_cmd.revision(config, autogenerate=True, message=opt.msg, branch_label=opt.branch) # this commands required revision name, but do not take any message or # branch labels elif cmd in ('show', 'stamp', 'upgrade', 'downgrade'): if len(opt.command) != 1: raise CommandError('Command: %s required revision id' % cmd) getattr(alembic_cmd, cmd)(config, *opt.command) else: # execute commands without any additional params getattr(alembic_cmd, cmd)(config)
def merge(self, revisions: str = '', message: t.Optional[str] = None, branch_label: t.Optional[str] = None, rev_id: t.Optional[str] = None) -> t.Any: config = self.configuration.to_alembic_config() return command.merge(config, revisions, message=message, branch_label=branch_label, rev_id=rev_id)
def merge( revisions: Optional[List[str]] = typer.Argument( None, help="Add the revision you would like to merge to this command."), message: str = typer.Option(None, "--message", "-m", help="The revision message"), ) -> None: """ Merge database revisions. Args: revisions: List of revisions to merge message: Optional message for the revision. Returns: None """ command.merge(alembic_cfg(), revisions, message=message)
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)
def merge_revisions(revisions, message): """Combines two revisions.""" alembic_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "alembic.ini") alembic_cfg = AlembicConfig(alembic_path) alembic_command.merge(alembic_cfg, revisions, message=message)
def merge(app, revisions='', message=None, branch_label=None, rev_id=None): """Merge to revisions together. Creates a new migration file""" command.merge(app.migrations_config, revisions, message=message, branch_label=branch_label, rev_id=rev_id)
def merge(opt, config): command.merge(config, opt["<revisions>"], message=opt["--message"], branch_label=opt["--branch-label"], rev_id=opt["--rev-id"])