oeCloud.io Example Version Control

oeCloud.io example version control is a way to understand version control feature supported by oeCloud.

What you’ll build

A oeCloud based app to demonstrate its version control feature, in order to do that we will use a Product model and perform different CURD operation on the Product model, and we will observe different success and faliure cases.

Scenario which will be coverd are :

  1. Create new record.
  2. Update a record with version.
  3. Update a record with wrong version.
  4. Update a record without version.
  5. Delete a record with version.
  6. Delete a record with wrong version.

What you’ll need:

  • You should have nodejs and oecloud.io based application running.
  • Know about model
  • Able to access Swagger Explorer

How to complete this guide

Download and install application from here

After login into application, you can use explorer running at http://localhost:3000/explorer

Using Version Control app

Once you have started the server, open a browser link: http://localhost:3000/explorer/. You should create Product model if it is not available. Please refer to ‘how to create model guide’ here. You should able to see model as below.

Schema of Product Model:

{
    "name": "Product",
    "base": "BaseEntity",
    "strict": false,
    "plural": "Products",
    "idInjection": true,
    "options": {
        "validateUpsert": true
    },
    "properties": {
        "code": {
            "type": "string"
        },
        "name": {
            "type": "string"
        },
        "category": {
            "type": "string"
        },
        "price": {
            "type": "number"
        },
        "offeredSince": {
            "type": "date"
        },
        "active": {
            "type": "boolean"
        },
        "description": {
            "type": "string"
        }
    }
}

Getting started:

Create a record in Product Model

To create a record, use api - POST /Products

    {
        "code": "HC1001",
        "name": "Caffe Latte",
        "description": "Strong Blend Espresso filled up with...",
        "category": "",
        "price": 1.23,
        "offeredSince": "01-01-2012",
        "flavourable": true,
        "flavours": []
    }
**Observation:** The response data will have an additional field called `_version`, this is the current version of that record in data base.

Update the previously created record with version number.

To update a record, use api - [PUT /Products/{id}](http://localhost:3000/explorer/#!/Product/Product_prototype_updateAttributes "To update data")

> **Note:** payload must have `_version` populated with the value of `_version in response of create`. 
{
        "category": "Latte",
        "price": 100.23,
        "_version": "<_version number in response of create>"
}

Observation: The record should be updated, and _version should be new value.

Update a record with wrong version number.

To update a record, use api - PUT /Products/{id}

Note: payload must have _version populated with wrong value of _version.

Sample data:

{
    "category": "Mocha",
    "price": 50.23,
    "_version": "WrongValue"
}

Output:

{
    "error": {
        "name": "Error",
        "status": 500,
        "message": "no record found with this version number",
        "stack": "Error: no record found with this version number...."
    }
}

Update a record with out version number.

To update a record, use api - PUT /Products/{id}

Note: payload must not have ‘_version’ field.

Sample data:

{
    "category": "Mocha",
    "price": 50.23
}

Output:

{
    "error": {
        "name": "Error",
        "status": 500,
        "message": "update requires the _version argument",
        "stack": "Error: update requires the _version argument\n..."
    }
}

Delete a record with version number.

To Delete a record, use api - Delete /Products/{id}/{version}

Output:

{
    "count" : 1
}

Delete a record with wrong version number.

To Delete a record, use api - Delete /Products/{id}/{version}

Output:

{
    "error": {
        "name": "Error",
        "status": 500,
        "message": "No record found",
        "stack": "Error: No record found\n  ..."
    }
}

Observation made:

Sr.No Scenario Observation
1 Create new record new record should be created with a unique version
2 Update a record with right version number record should be updated with new data, and a new unique version number for that record is genrated
3 Update a record with wrong version number record should not be updated, instead a error is returned, error message “No record Found”
4 Update a record with out version number record should not be updated, instead a error is returned, error message “update requires the _version argument”
5 Delete a record with right version number record should be deleted
6 Delete a record with wrong version number record should not be deleted, instead a error is returned, error message “No record Found”

Summary

Congratulations! You have successfully create a simple app based on oeCloud, which demonstrate version control feature of oeCloud. We have covered all the scenario for version control provided by oeCloud.