def run_migrations_offline(): """Run migrations in 'offline' mode. This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don't even need a DBAPI to be available. Calls to context.execute() here emit the given string to the script output. """ project_path = get_project_path() project_config = get_project_config(project_path) backend = get_backend(project_path, project_config, initialize_db=False) url = str(backend.engine.url) with backend.transaction(): context.configure(connection=backend.connection, url=url, target_metadata=backend.metadata, literal_binds=True) with context.begin_transaction(): context.run_migrations()
def main(): load_plugins() project_path = get_project_path() settings = Settings() settings.update(settings.load(project_path=project_path)) settings.load_plugins() if project_path: project_config = get_project_config(project_path) backend = get_backend(project_path, project_config, settings) project = get_project(project_path, project_config, settings, backend) else: project = None backend = None CommandClass, command_chain = load_command_class(settings) if CommandClass.requires_valid_project and project is None: sys.stderr.write( "Cannot find a checkmate project in the current directory tree, aborting.\n" ) exit(-1) command = CommandClass(project, settings, backend=backend, prog=sys.argv[0] + " " + " ".join(command_chain), args=sys.argv[1 + len(command_chain):]) try: if 'help' in command.opts and command.opts['help']: print command.help_message() exit(0) result = command.run() if hasattr(command, 'serialize'): result_str = command.serialize(result, 'text') print result_str except KeyboardInterrupt: print "[CTRL-C pressed, aborting]" exit(-1)
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ print "Running migrations online" project_path = get_project_path() project_config = get_project_config(project_path) backend = get_backend(project_path, project_config, initialize_db=False) context.configure( connection=backend.connection, target_metadata=backend.metadata, ) with context.begin_transaction(): context.run_migrations()