Skip to content

Commit 17721fc

Browse files
author
Maksym Mykhailenko
committed
chore: import/export scripts improvements
recreated demo data with valid projects data and dummified prices in metadata
1 parent 22d97ca commit 17721fc

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Local setup should work good on **Linux** and **macOS**. But **Windows** is not
154154
4. ♻ Init DB, ES and demo data (it clears any existent data)
155155
156156
```bash
157-
npm run local:setup
157+
npm run local:init
158158
```
159159

160160
This command will do 3 things:
@@ -215,7 +215,7 @@ npm run data:import -- --file path/to-file.json
215215

216216
- As this commands calls topcoder services to get data like members details, so you have to provide environment variables `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE`, `AUTH0_PROXY_SERVER_URL`, they would automatically picked up from the `.env` file if provided.
217217

218-
- If you encounter conflicts errors during import, you may need to clear database using `NODE_ENV=development npm run sync:db`, and clear ES (Elasticsearch) indices using `NODE_ENV=development npm run sync:es`.
218+
- If you encounter conflicts errors during import, you may need to recreated database tables and Elasticssearch indexes by `npm run sync:all`.
219219

220220
- List of models that will be imported are defined in `scripts/data/dataModels.js`. You can add new models to this list, but make sure that new models are added to list such that each model comes after its dependencies.
221221

data/demo-data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"lint": "./node_modules/.bin/eslint .",
1111
"lint:fix": "./node_modules/.bin/eslint . --fix || true",
1212
"build": "babel src -d dist --presets es2015 --copy-files",
13+
"sync:all": "NODE_ENV=development npm run sync:db && NODE_ENV=development npm run sync:es",
1314
"sync:db": "./node_modules/.bin/babel-node migrations/sync.js",
1415
"sync:es": "./node_modules/.bin/babel-node migrations/elasticsearch_sync.js",
1516
"sync:es:metadata": "./node_modules/.bin/babel-node migrations/elasticsearch_sync.js --index-name metadata",
@@ -26,10 +27,10 @@
2627
"test:watch": "NODE_ENV=test ./node_modules/.bin/mocha -w --require babel-core/register $(find src -path '*spec.js*')",
2728
"demo-data": "babel-node local/seed",
2829
"es-db-compare": "babel-node scripts/es-db-compare",
29-
"data:export": "LOG_LEVEL=info node --require dotenv/config --require babel-core/register scripts/data/export | bunyan -o short",
30-
"data:import": "LOG_LEVEL=info node --require dotenv/config --require babel-core/register scripts/data/import | bunyan -o short",
30+
"data:export": "NODE_ENV=development LOG_LEVEL=info node --require dotenv/config --require babel-core/register scripts/data/export",
31+
"data:import": "NODE_ENV=development LOG_LEVEL=info node --require dotenv/config --require babel-core/register scripts/data/import",
3132
"local:run-docker": "docker-compose -f ./local/full/docker-compose.yml up -d",
32-
"local:setup": "NODE_ENV=development npm run sync:db && NODE_ENV=development npm run sync:es && npm run data:import"
33+
"local:init": "npm run sync:all && npm run data:import"
3334
},
3435
"repository": {
3536
"type": "git",

scripts/data/export/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function runExportData(filePath, logger) {
2222
});
2323
}
2424

25-
const logger = util.getAppLogger();
25+
const logger = util.getScriptsLogger();
2626
const filePath =
2727
process.argv[2] === '--file' && process.argv[3]
2828
? process.argv[3]

scripts/data/import/importData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ async function writeDataToDatabase(filePath, logger) {
6161
transaction,
6262
})
6363
)[0][0].setval;
64-
logger.info(
64+
logger.debug(
6565
`Updated autoIncrement for ${modelName}.${field} with max value = ${setValue}`,
6666
);
6767
}
6868
}
6969
} else {
70-
logger.info(`No records to save for model: ${modelName}`);
70+
logger.info(`No records to import for model: ${modelName}`);
7171
}
7272
}
7373
// commit transaction only if all things went ok

scripts/data/import/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs';
22
import util from '../../../src/util';
33
import { importData } from './importData';
44

5-
const logger = util.getAppLogger();
5+
const logger = util.getScriptsLogger();
66
const filePath = (process.argv[2] === '--file' && process.argv[3]) ? process.argv[3] : 'data/demo-data.json';
77
// check if file exists
88
if (!fs.existsSync(filePath)) {

src/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,8 @@ _.assignIn(util, {
13501350
return curDir;
13511351
}, initDir);
13521352
},
1353-
getAppLogger: () => {
1353+
1354+
getScriptsLogger: () => {
13541355
const appName = 'tc-projects-service';
13551356
return coreLib.logger({
13561357
name: appName,

0 commit comments

Comments
 (0)