Tayeb Chlyah edited this page Nov 12, 2017 · 3 revisions

Getting started

Add Couchmove dependency

With Maven


With Gradle

compile 'com.github.differentway:couchmove:1.0.1'


All you need to do is to instantiate a Couchmove Object with some configuration. Iy you use Spring, you can instantiate it as a bean. Don't forget to run migrate() method to start migration process.

public Couchmove couchmove(Bucket bucket) {
    log.debug("Configuring Couchmove");
    Couchmove couchmove = new Couchmove(bucket, "couchmove/changelog");
    return couchmove;

Creating change logs

Couchmove is widely inspired from the simplicity of Flyway, the only difference is that you can import documents, design documents, or execute n1ql requests, depending on the change log format (file or folder) and extension (.n1ql, .json).


In order to be picked by the class path scanner, the migrations must follow a naming pattern :

  • prefix : For now, only Vfor versioned migrations are supported.
  • version : Each versioned migration must have a unique version, composed by one or more numeric parts, separated by a dot . or an underscore _
  • separator : two underscores __
  • description : Underscore _ or spaces separate the words. Underscores are replaced by spaces at runtime
  • suffix : .n1ql and .json for files, or none for folders

Examples :


Change log types

1. n1ql scripts :

Format : Files with .n1qlextension

Syntax :

  • Single or multi-line statements
  • Placeholder replacement : it looks for Ant-style placeholders like ${placeholder}. For now, it only support injecting bucket name in n1ql scripts with ${bucket} placeholder
  • Single --, or Multi-line /* */ comments spanning complete lines

Example : V1__Create_Index.n1ql

/* Single line comment */
CREATE INDEX type ON default(`_class`)
    WITH { "defer_build" : true };


-- Placeholder
        "type": "admin",
        "username": "Administrator",
        "birthday": "01/09/1998"

2. Design Documents :

Format : Files with .jsonextension

Syntax : Use JSON Format. The format of the design document should include all the views defined in the design document, incorporating both the map and reduce functions for each named view.

Description is used as a design document name.

Example : V2__location.json

   "views" : {
      "byloc" : {
         "map" : "function (doc, meta) {\n  if (meta.type == \"json\") {\n    emit(doc.city, doc.sales);\n  } else {\n    emit([\"blob\"]);\n  }\n}"

3. Documents

Folder containing JSON Files with .json extension. Couchmove import all documents to Couchbase bucket, using file names (without .json extension) as document keys.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.