Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit b37f111

Browse files
author
tkostuch
committed
Merge remote-tracking branch 'github/develop'
2 parents a608ec5 + eab5130 commit b37f111

33 files changed

+13417
-10115
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Update to `storefront-query-builder` version `1.0.0` - @cewald (#429)
2020
- Add `composeError` in './magento2/o2m.js' - @flancer64 (#422)
2121
- Explicit data extraction from 'Error' objects - @flancer64 (#424)
22+
- Merge scripts: db7 => db, elastic7=>elastic and add support for es7 in yarn mage2vs import - @gibkigonzo (#436)
2223

2324
### Fixed
2425
- add es7 support for map url module and fixed default index for es config - @gibkigonzo
2526
- Add correct paths for production build - @cewald (#407)
2627
- Fix MSI default stock id value
2728
- Add outputFormatter to response from cache - @gibkigonzo (#428)
2829
- disable showing stack for invalid requests - @gibkigonzo (#431)
29-
30+
- Improve `_outputFormatter` on cache catalog-response to prevent exception - @cewald (#432)
3031

3132
## [1.11.1] - 2020.03.17
3233

README.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,7 @@ Starting from [Elasitc 6 and 7](https://www.elastic.co/guide/en/elasticsearch/re
111111

112112
From now on, we're using the separate indexes per each entity type. The convention is: `${indexName}_${entityType}`. If your' **logical index name** is `vue_storefront_catalog` then it will be mapped to the **physical indexes** of: `vue_storefront_catalog_product`, `vue_storefront_catalog_category` ...
113113

114-
To take the advantage of this new logical->physical index distinction we've provided new Elastic tools: `db7`, `migrate7`, `dump7`, `restore7` tools. They can be used exactly the same way [like the old tools](https://docs.vuestorefront.io/guide/data/database-tool.html) were. The only distinction is that they work on separate indexes.
115-
116-
**Create new index**
117-
118-
Before restoreing or importing data you might want to create a new Elastic index with the proper data types/schema applied. You can run just the `yarn db7 new` command in order to do that.
119-
120-
**Restore the data**
121-
122-
After you ran the docker file and have Elastic7 up and running you might want to:
123-
124-
a) restore the demo data by running `yarn restore7` and `yarn restore7_it; yarn restore7_de` for default multistores. The data is restored from `var/catalog_product.json`, `var/catalog_category.json` and so on...
125-
126-
b) import the data from Magento to proper physical indexes. To do so, currently you can do this only with [mage2vuestorefront](https://github.com/DivanteLtd/mage2vuestorefront/pull/96).
127-
128-
**Note:** After 1.11 stable release (around November, 2019) we'll **replace** the standard tools: `db`, `migrate`, `dump`, `restore` with the Elastic 7 equivalents and it will become the default.
129-
114+
[Tools](https://docs.vuestorefront.io/guide/data/database-tool.html) are adjusted to ES7. You can use `yarn db new`, `yarn restore`, `yarn mage2vs import`. Just make sure that you have set up `config.elasticsearch.apiVersion` to `7.1`.
130115

131116
## API access
132117
Catalog API calls are compliant with ElasticSearch (it works like a filtering proxy to ES). More on ES queries: [ElasticSearch queries tutorial](http://okfnlabs.org/blog/2013/07/01/elasticsearch-query-tutorial.html)

config/elastic.schema.product.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@
7676
"tax_class_id": {"type": "integer"},
7777
"gender": {"type": "integer"},
7878
"material": {"type": "integer"},
79-
"category_gear": {"type": "integer"}
79+
"category_gear": {"type": "integer"},
80+
"attributes_metadata": {
81+
"properties": {
82+
"id": {"type": "integer"},
83+
"attribute_id": {"type": "integer"},
84+
"default_frontend_label": {"type": "text"},
85+
"is_visible_on_front": {"type": "text"},
86+
"is_visible" : {"type": "boolean"},
87+
"frontend_input": {"type": "text"},
88+
"is_user_defined": {"type": "boolean"},
89+
"is_comparable": {"type": "text"},
90+
"attribute_code": {"type": "text"},
91+
"options": {
92+
"properties": {
93+
"value": {"type": "text"},
94+
"label": {"type": "text"}
95+
}
96+
}
97+
}
98+
}
8099
}
81100
}

package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,15 @@
1616
"build:copy:schema": "cpx 'src/**/*.schema*.json' dist/src",
1717
"start": "pm2 start ecosystem.json $PM2_ARGS",
1818
"db": "node scripts/db.js",
19-
"db7": "node scripts/db7.js",
2019
"cache": "node ./scripts/cache",
2120
"mage2vs": "node scripts/mage2vs.js",
2221
"restore": "node scripts/elastic.js restore && npm run db rebuild",
23-
"restore7": "node scripts/elastic7.js restore --output-index=vue_storefront_catalog && npm run db7 rebuild --indexName=vue_storefront_catalog",
24-
"restore7_it": "npm run restore7 -- --input-file=var/catalog_it.json --output-index=vue_storefront_catalog_it && npm run db7 rebuild -- --indexName=vue_storefront_catalog_it",
25-
"restore7_de": "npm run restore7 -- --input-file=var/catalog_de.json --output-index=vue_storefront_catalog_de && npm run db7 rebuild -- --indexName=vue_storefront_catalog_de",
2622
"restore_it": "npm run restore -- --input-file=var/catalog_it.json --output-index=vue_storefront_catalog_it && npm run db rebuild -- --indexName=vue_storefront_catalog_it",
2723
"restore_de": "npm run restore -- --input-file=var/catalog_de.json --output-index=vue_storefront_catalog_de && npm run db rebuild -- --indexName=vue_storefront_catalog_de",
2824
"restore2main": "npm run restore -- --output-index=vue_storefront_catalog",
2925
"dump": "node scripts/elastic.js dump",
30-
"dump_it": "npm run dump -- --input-index=vue_storefront_catalog_it --output-file=var/catalog_it.json",
31-
"dump_de": "npm run dump -- --input-index=vue_storefront_catalog_de --output-file=var/catalog_de.json",
32-
"dump7": "node scripts/elastic7.js dump",
33-
"dump7_it": "npm run dump7 -- --input-index=vue_storefront_catalog_it --output-file=var/catalog_it.json",
34-
"dump7_de": "npm run dump7 -- --input-index=vue_storefront_catalog_de --output-file=var/catalog_de.json",
26+
"dump_it": "npm run dump -- --input-index=vue_storefront_catalog --output-file=var/catalog_it.json",
27+
"dump_de": "npm run dump -- --input-index=vue_storefront_catalog --output-file=var/catalog_de.json",
3528
"kue": "node scripts/kue.js",
3629
"kue-dashboard": "npm run kue dashboard -- --port=3050",
3730
"o2m": "node src/worker/order_to_magento2.js start",

scripts/db.js

Lines changed: 141 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,176 @@ const config = require('config')
33
const common = require('../migrations/.common')
44
const es = require('../src/lib/elastic')
55

6-
program
7-
.command('rebuild')
8-
.option('-i|--indexName <indexName>', 'name of the Elasticsearch index', config.elasticsearch.indices[0])
9-
.action((cmd) => { // TODO: add parallel processing
10-
if (!cmd.indexName) {
11-
console.error('error: indexName must be specified');
12-
process.exit(1);
13-
}
6+
/**
7+
* REBUILD DB
8+
*/
9+
const es7RebuildCommand = (cmd) => { // TODO: add parallel processing
10+
if (!cmd.indexName) {
11+
console.error('error: indexName must be specified');
12+
process.exit(1);
13+
}
1414

15+
let waitingCounter = 0
16+
for (var indexTypeIterator in config.elasticsearch.indexTypes) {
17+
var collectionName = config.elasticsearch.indexTypes[indexTypeIterator]
18+
console.log(config.elasticsearch.indexTypes);
1519
console.log('** Hello! I am going to rebuild EXISTING ES index to fix the schema')
16-
const originalIndex = cmd.indexName
20+
const originalIndex = cmd.indexName + '_' + collectionName;
1721
const tempIndex = originalIndex + '_' + Math.round(+new Date() / 1000)
1822

1923
console.log(`** Creating temporary index ${tempIndex}`)
20-
es.createIndex(common.db, tempIndex, '', (err) => {
24+
es.createIndex(common.db, tempIndex, collectionName, (err) => {
2125
if (err) {
2226
console.log(err)
2327
}
2428

25-
console.log(`** Putting the mappings on top of ${tempIndex}`)
26-
es.putMappings(common.db, tempIndex, (err) => {
29+
console.log(`** We will reindex ${originalIndex} with the current schema`)
30+
es.reIndex(common.db, originalIndex, tempIndex, (err) => {
2731
if (err) {
28-
console.error(err.meta ? err.meta : err)
32+
console.log(err)
2933
}
3034

31-
console.log(`** We will reindex ${originalIndex} with the current schema`)
32-
es.reIndex(common.db, originalIndex, tempIndex, (err) => {
35+
console.log('** Removing the original index')
36+
es.deleteIndex(common.db, originalIndex, (err) => {
3337
if (err) {
3438
console.log(err)
3539
}
3640

37-
console.log('** Removing the original index')
38-
es.deleteIndex(common.db, originalIndex, (err) => {
39-
if (err) {
40-
console.log(err)
41-
}
42-
43-
console.log('** Creating alias')
44-
es.putAlias(common.db, tempIndex, originalIndex, (err) => {
45-
console.log('Done! Bye!')
46-
process.exit(0)
47-
})
41+
console.log('** Creating alias')
42+
es.putAlias(common.db, tempIndex, originalIndex, (err) => {
43+
waitingCounter++
4844
})
4945
})
5046
})
5147
})
52-
})
48+
}
49+
setInterval(() => {
50+
if (waitingCounter === config.elasticsearch.indexTypes.length) process.exit(0)
51+
}, 1000)
52+
}
5353

54-
program
55-
.command('new')
56-
.option('-i|--indexName <indexName>', 'name of the Elasticsearch index', config.elasticsearch.indices[0])
57-
.action((cmd) => { // TODO: add parallel processing
58-
if (!cmd.indexName) {
59-
console.error('error: indexName must be specified');
60-
process.exit(1);
54+
const es5RebuildCommand = (cmd) => { // TODO: add parallel processing
55+
console.warn(`es5 is deprecated and will be removed in 1.13`)
56+
if (!cmd.indexName) {
57+
console.error('error: indexName must be specified');
58+
process.exit(1);
59+
}
60+
61+
console.log('** Hello! I am going to rebuild EXISTING ES index to fix the schema')
62+
const originalIndex = cmd.indexName
63+
const tempIndex = originalIndex + '_' + Math.round(+new Date() / 1000)
64+
65+
console.log(`** Creating temporary index ${tempIndex}`)
66+
es.createIndex(common.db, tempIndex, '', (err) => {
67+
if (err) {
68+
console.log(err)
6169
}
6270

63-
console.log('** Hello! I am going to create NEW ES index')
64-
const indexName = cmd.indexName
65-
es.createIndex(common.db, indexName, '', (err) => {
71+
console.log(`** Putting the mappings on top of ${tempIndex}`)
72+
es.putMappings(common.db, tempIndex, (err) => {
6673
if (err) {
67-
console.log(err)
74+
console.error(err.meta ? err.meta : err)
6875
}
6976

70-
console.log('Done! Bye!')
71-
process.exit(0)
77+
console.log(`** We will reindex ${originalIndex} with the current schema`)
78+
es.reIndex(common.db, originalIndex, tempIndex, (err) => {
79+
if (err) {
80+
console.log(err)
81+
}
82+
83+
console.log('** Removing the original index')
84+
es.deleteIndex(common.db, originalIndex, (err) => {
85+
if (err) {
86+
console.log(err)
87+
}
88+
89+
console.log('** Creating alias')
90+
es.putAlias(common.db, tempIndex, originalIndex, (err) => {
91+
console.log('Done! Bye!')
92+
process.exit(0)
93+
})
94+
})
95+
})
7296
})
7397
})
98+
}
99+
100+
program
101+
.command('rebuild')
102+
.option('-i|--indexName <indexName>', 'name of the Elasticsearch index', config.elasticsearch.indices[0])
103+
.action((cmd) => {
104+
if (parseInt(config.elasticsearch.apiVersion) < 6) {
105+
return es5RebuildCommand(cmd)
106+
} else {
107+
return es7RebuildCommand(cmd)
108+
}
109+
})
110+
111+
/**
112+
* CREATE INDEX
113+
*/
114+
const asyncCreateIndex = (es, common, indexName, collectionName) => new Promise((resolve, reject) => {
115+
es.createIndex(common.db, indexName + '_' + collectionName, collectionName, (err) => {
116+
if (err) {
117+
reject(err)
118+
} else {
119+
resolve()
120+
}
121+
})
122+
})
123+
124+
const es7NewCommand = async (cmd) => { // TODO: add parallel processing
125+
if (!cmd.indexName) {
126+
console.error('error: indexName must be specified');
127+
process.exit(1);
128+
}
129+
130+
console.log('** Hello! I am going to create NEW ES index')
131+
const indexName = cmd.indexName
132+
133+
for (let collectionName of config.elasticsearch.indexTypes) {
134+
try {
135+
await asyncCreateIndex(es, common, indexName, collectionName)
136+
} catch (err) {
137+
console.log(JSON.stringify(err, null, 2))
138+
}
139+
}
140+
process.exit(0)
141+
}
142+
143+
const es5NewCommand = (cmd) => { // TODO: add parallel processing
144+
console.warn(`es5 is deprecated and will be removed in 1.13`)
145+
if (!cmd.indexName) {
146+
console.error('error: indexName must be specified');
147+
process.exit(1);
148+
}
149+
150+
console.log('** Hello! I am going to create NEW ES index')
151+
const indexName = cmd.indexName
152+
es.createIndex(common.db, indexName, '', (err) => {
153+
if (err) {
154+
console.log(err)
155+
}
156+
157+
console.log('Done! Bye!')
158+
process.exit(0)
159+
})
160+
}
161+
162+
program
163+
.command('new')
164+
.option('-i|--indexName <indexName>', 'name of the Elasticsearch index', config.elasticsearch.indices[0])
165+
.action((cmd) => {
166+
if (parseInt(config.elasticsearch.apiVersion) < 6) {
167+
return es5NewCommand(cmd)
168+
} else {
169+
return es7NewCommand(cmd)
170+
}
171+
})
74172

173+
/**
174+
* OTHERS COMMANDS
175+
*/
75176
program
76177
.on('command:*', () => {
77178
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));

0 commit comments

Comments
 (0)