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

Getting started

Add Couchmove dependency

With Maven

<dependency>
    <groupId>com.github.differentway</groupId>
    <artifactId>couchmove</artifactId>
    <version>1.0.1</version>
</dependency>

With Gradle

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

Usage

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.

@Bean
public Couchmove couchmove(Bucket bucket) {
    log.debug("Configuring Couchmove");
    Couchmove couchmove = new Couchmove(bucket, "couchmove/changelog");
    couchmove.migrate();
    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).

Naming

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 :

V1__Create_index.n1ql
V1.1__insert_clients
V2_1__all.json

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 };

/*
Multi-line
comment
*/

-- Placeholder
INSERT INTO ${bucket} (KEY, VALUE)
  VALUES
    ("user::Administrator",
      {
        "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.