Exemplo n.º 1
0
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()
Exemplo n.º 2
0
def get_project_and_backend(path):
    try:
        project_config = get_project_config(path+"/.checkmate")
    except (IOError,):
        sys.stderr.write("No project configuration found!\n")
        exit(-1)

    backend_config = project_config['backend']
    project_class = project_config.get('project_class','DiskProject')
    if not project_class in settings.models:
        sys.stderr.write("Invalid project type: %s. Maybe the plugin is missing?" % project_class)
        exit(-1)
    ProjectClass = settings.models[project_class]
    if backend_config['driver'] == 'mongo':
        if not pymongo_support:
            sys.stderr.write("Encountered pymongo backend, but pymongo is not installed!")
            exit(-1)
        pymongo_db = pymongo.MongoClient()[backend_config['db']]
        backend = MongoBackend(pymongo_db,autoload_embedded = False,allow_documents_in_query = False)
    elif backend_config['driver'] == 'file':
        backend = FileBackend(path+"/.checkmate",autoload_embedded = False)
    else:
        sys.stdout.write("Unknown backend driver: %s" % backend_config['driver'])
    try:
        project = backend.get(ProjectClass,{'pk' : project_config['project_id']})
    except ProjectClass.DoesNotExist:
        project = ProjectClass({'pk' : project_config['project_id']})
        backend.save(project)
    project.path = path
    backend.save(project)
    backend.commit()
    return project,backend
Exemplo n.º 3
0
def get_project_and_backend(path):
    try:
        project_config = get_project_config(path + "/.checkmate")
    except (IOError,):
        sys.stderr.write("No project configuration found!\n")
        exit(-1)

    backend_config = project_config["backend"]
    project_class = project_config.get("project_class", "DiskProject")
    if not project_class in settings.models:
        sys.stderr.write("Invalid project type: %s. Maybe the plugin is missing?" % project_class)
        exit(-1)
    ProjectClass = settings.models[project_class]
    if backend_config["driver"] == "mongo":
        if not pymongo_support:
            sys.stderr.write("Encountered pymongo backend, but pymongo is not installed!")
            exit(-1)
        pymongo_db = pymongo.MongoClient()[backend_config["db"]]
        backend = MongoBackend(pymongo_db, autoload_embedded=False, allow_documents_in_query=False)
    elif backend_config["driver"] == "file":
        backend = FileBackend(path + "/.checkmate", autoload_embedded=False)
    else:
        sys.stdout.write("Unknown backend driver: %s" % backend_config["driver"])
    try:
        project = backend.get(ProjectClass, {"pk": project_config["project_id"]})
    except ProjectClass.DoesNotExist:
        project = ProjectClass({"pk": project_config["project_id"]})
        backend.save(project)
    project.path = path
    backend.save(project)
    backend.commit()
    return project, backend
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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()