def history(directory=None, rev_range=None, verbose=False): """List changeset scripts in chronological order.""" config = current_app.extensions['migrate'].migrate.get_config(directory) if alembic_version >= (0, 7, 0): command.history(config, rev_range, verbose=verbose) else: command.history(config, rev_range)
def history(directory=None, rev_range=None, verbose=False): """List changeset scripts in chronological order.""" config = _get_config(directory) if alembic_version >= (0, 7, 0): command.history(config, rev_range, verbose=verbose) else: command.history(config, rev_range)
def history(context, directory="migrations", rev_range=None, verbose=False): """显示历史""" config = _get_config(directory) if alembic_version >= (0, 7, 0): command.history(config, rev_range, verbose=verbose) else: command.history(config, rev_range)
def commands(): arguments = docopt(__doc__) alembic_config_path = os.path.join(BASEDIR, 'alembic.ini') alembic_config = Config(alembic_config_path) if arguments['db']: if arguments['migrate']: command.revision( config=alembic_config, message=arguments['COMMENT'], autogenerate=True, ) if arguments['drop'] or arguments['rebuild']: drop_tables() if arguments['upgrade'] or arguments['create'] or arguments['rebuild']: command.upgrade(config=alembic_config, revision='head') if arguments['--demo-data']: demo_data() if arguments['history']: command.history(config=alembic_config, )
def test_history_relative_to_num(self): self.cfg.stdout = buf = StringIO() command.history(self.cfg, "-2:%s" % (self.c)) self._eq_cmd_output(buf, [ '%(revb)s -> %(revc)s (head), Rev C', '%(reva)s -> %(revb)s, Rev B', ])
def test_history_current_to_head_as_b(self): command.stamp(self.cfg, self.b) self.cfg.stdout = buf = StringIO() command.history(self.cfg, "current:") self._eq_cmd_output(buf, [ '%(revb)s -> %(revc)s (head), Rev C', ])
def test_history_num_plus_relative(self): self.cfg.stdout = buf = StringIO() command.history(self.cfg, "%s:+2" % (self.a)) self._eq_cmd_output(buf, [ '%(revb)s -> %(revc)s (head), Rev C', '%(reva)s -> %(revb)s, Rev B', ])
def test_history_indicate_current(self): command.stamp(self.cfg, (self.b,)) self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, indicate_current=True, verbose=True) self._eq_cmd_output( buf, [self.c, self.b, self.a], currents=(self.b,), env_token=True )
def history(app, *, rev_range: ( 'specify a revision range; format is [start]:[end]') = None, verbose: 'use more verbose output' = False): """List changeset scripts in chronological order.""" alembic.history(_get_config(app), rev_range=rev_range, verbose=verbose)
def history(): from sanic_template.conf import settings from alembic.config import Config from alembic.command import history alembic_cfg = Config(settings.ALEMBIC_CONFIG_PATH) history(alembic_cfg)
def show_history(self) -> None: step = self.get_option("step") latest = self.get_option("latest") dir_exists = os.path.exists(f"{self.project_url}/{self.alembic_dir}") if self.config is None or not dir_exists: raise CraxMigrationsError( "You can not run show history command before migrations not created" ) for app in self.applications: if self.check_branch_exists(f"{self.db_name}/{app}"): os.environ["CRAX_ONLINE"] = "true" os.environ["CRAX_CURRENT"] = app top_formatter = ( f'{app} history. Database: {self.db_name} \n {"*" * 40} \n' ) bottom_formatter = f'\n {"*" * 40} \n' if step is not None: revision = self.get_revision(app, int(step)) elif latest is True: revision = self.get_revision(app, 0) else: revision = None history(self.config, f":{self.db_name}/{app}@head") if revision: sys.stdout.write(top_formatter) self.config.print_stdout(revision) sys.stdout.write(bottom_formatter)
def test_history_base_to_num(self): self.cfg.stdout = buf = StringIO() command.history(self.cfg, ":%s" % (self.b)) self._eq_cmd_output(buf, [ '%(reva)s -> %(revb)s, Rev B', 'None -> %(reva)s, Rev A' ])
def test_history_full(self): self.cfg.stdout = buf = StringIO() command.history(self.cfg) self._eq_cmd_output(buf, [ '%(revb)s -> %(revc)s (head), Rev C', '%(reva)s -> %(revb)s, Rev B', 'None -> %(reva)s, Rev A' ])
def test_history_current_to_head_as_base(self): command.stamp(self.cfg, "base") self.cfg.stdout = buf = StringIO() command.history(self.cfg, "current:") self._eq_cmd_output(buf, [ '%(revb)s -> %(revc)s (head), Rev C', '%(reva)s -> %(revb)s, Rev B', 'None -> %(reva)s, Rev A' ])
def history(self, directory=None, rev_range=None, verbose=False, **kwargs): # pragma: no cover """List changeset scripts in chronological order.""" config = _get_config(directory) command.history(config, rev_range, verbose=verbose)
def history(self, rev_range): """List changeset scripts in chronological order. Args: rev_range: Revision range in format [start]:[end] """ config = self.alembic_config() alembic_command.history(config, rev_range) return True
def history(): import os import settings from alembic.config import Config from alembic.command import history alembic_ini_path = os.path.join(settings.BASE_DIR, 'alembic.ini') alembic_cfg = Config(alembic_ini_path) history(alembic_cfg)
def history(context, directory='migrations', rev_range=None, verbose=False): """List changeset scripts in chronological order.""" from app import create_app with create_app().app_context(): config = _get_config(directory) if alembic_version >= (0, 7, 0): command.history(config, rev_range, verbose=verbose) else: command.history(config, rev_range)
def history(directory=None, rev_range=None, verbose=False, indicate_current=False): """List changeset scripts in chronological order.""" config = get_config(directory) command.history(config, rev_range, verbose=verbose, indicate_current=indicate_current)
def history(config, verbose: bool, rev_range: Optional[str]): """List changeset scripts in chronological order.""" 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.history(c, rev_range, verbose=verbose)
def history(directory=None, rev_range=None, verbose=False, indicate_current=False): """List changeset scripts in chronological order.""" config = migrate_manager.migrate_config.migrate.get_config(directory) if alembic_version >= (0, 9, 9): command.history(config, rev_range, verbose=verbose, indicate_current=indicate_current) else: command.history(config, rev_range, verbose=verbose)
def history(self, rev_range: t.Optional[str] = None, verbose: bool = False, indicate_current: bool = False) -> t.Any: config = self.configuration.to_alembic_config() if alembic_version >= (0, 9, 9): return command.history(config, rev_range, verbose=verbose, indicate_current=indicate_current) else: return command.history(config, rev_range, verbose=verbose)
def cli_db_history(rev_range, verbose, indicate_current): """ List changeset scripts in chronological order. """ alembic_cfg = AlembicConfig("alembic.ini") alembic_cfg.set_main_option("script_location", str(Path() / "db_migrations")) command.history( config=alembic_cfg, rev_range=rev_range, verbose=verbose, indicate_current=indicate_current, )
def history(ctx, range_): """ List changeset scripts in chronological order. Usage: history -r[start]:[end] history -rqw42se:qa234 Show information from start to end revisions. history -r-3: Show information from three revs ago up to head. history -r-2:current Show information from two revs ago up to current revision. """ from db.alembic import alembic_config command.history(alembic_config, rev_range=range_)
def history_database(revision_type): """Shows the history of the database.""" 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.history(alembic_cfg)
def alembic_process(self, config): from alembic.command import history from alembic.environment import EnvironmentContext from alembic.script import ScriptDirectory from cliche.web.app import app from cliche.web.db import get_database_engine with app.app_context(): engine = get_database_engine() script = ScriptDirectory.from_config(config) with EnvironmentContext(config, script, as_sql=False, destination_rev=None, tag=None) as context: context.configure(engine.contextual_connect(), engine.url) history(config)
def history(self, template=None, template_args=None): config = self.get_alembic_config() history(config) if self.default: template = 'manage.html' template_args = { "user": self.user, "role": self.role, "org_type": self.org_type, "namespace": self.namespace } return render_template(template, **template_args, output=config.format_stdout()) else: return config.format_stdout()
def _get_pending_plugins(): from alembic.command import history plugins = [ (plugin, state) for plugin, state in ((plugin, current_revision(plugin)) for plugin in config['ckan.plugins'].split()) if state and not state.endswith('(head)') ] pending = {} for plugin, current in plugins: with _repo_for_plugin(plugin) as repo: repo.setup_migration_version_control() history(repo.alembic_config) ahead = repo.take_alembic_output() if current != 'base': # The last revision in history describes step from void to the # first revision. If we not on the `base`, we've already run # this migration ahead = ahead[:-1] if ahead: pending[plugin] = len(ahead) return pending
def history( verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), indicate_current: bool = typer.Option(False, "--current", "-c", help="Indicate current revision"), ) -> None: """ List changeset scripts in chronological order. Args: verbose: Verbose output indicate_current: Indicate current revision Returns: None """ command.history(alembic_cfg(), verbose=verbose, indicate_current=indicate_current)
def history(directory=None, rev_range=None, verbose=False, indicate_current=False): """List changeset scripts in chronological order.""" app = current_app() config = app.extra['migrate'].migrate.get_config(directory) if alembic_version >= (0, 9, 9): command.history(config, rev_range, verbose=verbose, indicate_current=indicate_current) elif alembic_version >= (0, 7, 0): command.history(config, rev_range, verbose=verbose) else: command.history(config, rev_range)
def history(rev_range=None): """ List changes in chronological order. """ config = _get_config() return command.history(config, rev_range)
def test_history_base_to_num(self): self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, ":%s" % (self.b), verbose=True) self._eq_cmd_output(buf, [self.b, self.a])
def test_history_current_to_head_as_b(self): command.stamp(self.cfg, self.b) self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, "current:") self._eq_cmd_output(buf, [self.c])
def history(directory, rev_range): "List changeset scripts in chronological order." config = _get_config(directory) command.history(config)
def main(): parser = argparse.ArgumentParser() parser.add_argument('-d', "--direction", action="store", default=None, dest="direction", help='-d up (or down) default = up', required=False) # # db type # parser.add_argument('-n', "--number", action="store", dest="number", help='-n 1 (default = 1)', default="1", required=False) parser.add_argument('-r', "--revision", action="store", dest="revision", help='-r 6669c0b62b06 (take the unique part from a migration id)', default=None, required=False) parser.add_argument('-c', "--current", action="store_true", dest="current", help='Display the current revision for a database.', default=False, required=False) parser.add_argument('-l', "--list", action="store_true", dest="history", help='List changeset scripts in chronological order.', default=False, required=False) args = parser.parse_args() # # show some args # #print("all args: ", args) with warnings.catch_warnings(): warnings.simplefilter("ignore", category=sa_exc.SAWarning) alembic_cfg = Config(os.path.join(os.path.dirname(__file__), "alembic.ini")) # show the current version if args.current: print(50*"-") print("current version: ") print(50*"-") command.current(alembic_cfg, verbose=True) sys.exit() # show all changes if args.history: print(50*"-") print("revision history: ") print(50*"-") command.history(alembic_cfg, rev_range=None, verbose=False) sys.exit() # # really migrate # res = "NOTHING" if args.direction == "up": # upgrade res = migrate("up", args.revision, args.number) elif args.direction == "down": # downgrade res = migrate("down", args.revision, args.number) else: print("Error: ") print("You must at least give a direction info up / down to migrate:") print(50*"-") print(" Change history ") print(50*"-") command.history(alembic_cfg, rev_range=None, verbose=False) #print(" res type: " + str(type(res))) #print(str(res)) #print(" res dir: " + str(dir(res))) sys.exit()
def run(self, runtime): command.history(self.config)
def test_history_include_env(self): self.cfg.stdout = buf = self._buf_fixture() self.cfg.set_main_option("revision_environment", "true") command.history(self.cfg, verbose=True) self._eq_cmd_output(buf, [self.c, self.b, self.a], env_token=True)
def test_history_num_range(self): self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, "%s:%s" % (self.a, self.b)) self._eq_cmd_output(buf, [self.b])
def alembic_process(self, config): from alembic.command import history history(config)
def test_history_relative_to_num(self): self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, "-2:%s" % (self.c)) self._eq_cmd_output(buf, [self.c, self.b])
def history(verbose, sql_url=None): alembic_cfg = init_config(sql_url) alembic_command.history(alembic_cfg, verbose=verbose)
def test_history_current_to_head_as_base(self): command.stamp(self.cfg, "base") self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, "current:", verbose=True) self._eq_cmd_output(buf, [self.c, self.b, self.a])
def test_history_num_to_head(self): self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, "%s:" % (self.a)) self._eq_cmd_output(buf, [self.c, self.b])
def test_history_full(self): self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, verbose=True) self._eq_cmd_output(buf, [self.c, self.b, self.a])
def test_history_current_to_head_as_base(self): command.stamp(self.cfg, "base") self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, "current:", verbose=True) self._eq_cmd_output(buf, [self.c, self.b, self.a], env_token=True)
def test_history_num_plus_relative(self): self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, "%s:+2" % (self.a), verbose=True) self._eq_cmd_output(buf, [self.c, self.b, self.a])
def history(rev_range=None): "List changeset scripts in chronological order." config = _get_config() command.history(config, rev_range)
def test_history_too_large_relative_to_num(self): self.cfg.stdout = buf = self._buf_fixture() command.history(self.cfg, "-5:%s" % (self.c), verbose=True) self._eq_cmd_output(buf, [self.c, self.b, self.a])