Vue storefront uses ElasticSearch as a primary data store. We're using Redis as cache layer and Kue for queue processing. Although all of these data stores are basicaly schema-free some mappings and meta data should be used for setting ES indices and so forth.
Vue storefront uses data migration mechanism based on https://github.com/tj/node-migrate.
We're using node-migrate wich is pre-configured with npm. So we're using the following alias:
npm run migrate
which runs the migrations against migrations
folder.
You can add new migration adding file to migrations
directory - which is not recommended OR using cmdline tool:
npm run migrate create name-of-my-migration
the tool automaticaly generates the file under migrations
folder.
The example migrations shows how to manipulate on products and mappings. Let's take a look at the mapping modification:
// Migration scripts use: https://github.com/tj/node-migrate
'use strict'
let config = require('config')
let common = require('./.common')
module.exports.up = function (next) {
// example of adding a field to the schema
// other examples: https://stackoverflow.com/questions/22325708/elasticsearch-create-index-with-mappings-using-javascript,
common.db.indices.putMapping({
index: config.elasticsearch.indices[0],
type: "product",
body: {
properties: {
slug: { type: "string" }, // add slug field
suggest: {
type: "completion",
analyzer: "simple",
search_analyzer: "simple"
}
}
}
}).then((res) => {
console.dir(res, {depth: null, colors: true})
next()
})
}
module.exports.down = function (next) {
next()
}
... and that's all :)