Skip to content

Commit 0963c20

Browse files
committedNov 14, 2019
feat: npm command for resetting DB
Usage: "npm run reset:db"
1 parent 7b86e27 commit 0963c20

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed
 

‎README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tc-notifications (as a standard nodejs app) provides generic framework around no
2020
5. Either add deployment for this new notification consumer/processor in existing deployment script (if you want to host the processor as separate service in the same ECS cluster) or write a new script if you want to keep the deployment separate.
2121

2222
## Dependencies
23-
- nodejs https://nodejs.org/en/ (v6+, if newer version of node is used, e.g. v10, then it needs to install extra lib `npm i natives@1.1.6` to support the gulp build)
23+
- nodejs https://nodejs.org/en/ (v6+, if newer version of node is used, e.g. v10, then it needs to install extra lib `npm i natives@1.1.6` to support the gulp build)
2424
- Heroku Toolbelt https://toolbelt.heroku.com
2525
- git
2626
- PostgreSQL 9.5
@@ -50,8 +50,8 @@ The following parameters can be set in config files or in env variables:
5050
if not provided, then SSL connection is not used, direct insecure connection is used;
5151
if provided, it can be either path to private key file or private key content
5252
- **Topcoder API**
53-
- `TC_API_V3_BASE_URL`: the TopCoder API V3 base URL
54-
- `TC_API_V4_BASE_URL`: the TopCoder API V4 base URL
53+
- `TC_API_V3_BASE_URL`: the TopCoder API V3 base URL
54+
- `TC_API_V4_BASE_URL`: the TopCoder API V4 base URL
5555
- `TC_API_V5_BASE_URL`: the TopCoder API V5 base URL
5656
- **Notifications API**
5757
- `API_CONTEXT_PATH`: path to serve API on
@@ -61,16 +61,16 @@ The following parameters can be set in config files or in env variables:
6161
- `TOKEN_CACHE_TIME`: time period of the cached token
6262
- `AUTH0_CLIENT_ID`: auth0 client id
6363
- `AUTH0_CLIENT_SECRET`: auth0 client secret
64-
- `AUTH0_PROXY_SERVER_URL`: auth0 proxy server URL
65-
- **Consumer handlers**
66-
- `KAFKA_CONSUMER_HANDLERS`: mapping from consumer topic to handlers
67-
- **Email notification**
68-
- `ENV`: used to construct email category
69-
- `ENABLE_EMAILS`: whether to enable email notifications
70-
- `ENABLE_DEV_MODE`: whether to enable dev mode
71-
- `DEV_MODE_EMAIL`: recipient email used in dev mode
72-
- `DEFAULT_REPLY_EMAIL`: default reply email
73-
64+
- `AUTH0_PROXY_SERVER_URL`: auth0 proxy server URL
65+
- **Consumer handlers**
66+
- `KAFKA_CONSUMER_HANDLERS`: mapping from consumer topic to handlers
67+
- **Email notification**
68+
- `ENV`: used to construct email category
69+
- `ENABLE_EMAILS`: whether to enable email notifications
70+
- `ENABLE_DEV_MODE`: whether to enable dev mode
71+
- `DEV_MODE_EMAIL`: recipient email used in dev mode
72+
- `DEFAULT_REPLY_EMAIL`: default reply email
73+
7474

7575
### Connect notification server
7676
Configuration for the connect notification server is at `connect/config.js`.
@@ -137,6 +137,7 @@ You may reuse it during review.
137137
- start local PostgreSQL db, create an empty database, update the config/default.js DATABASE_URL param to point to the db
138138
- install dependencies `npm i`
139139
- run code lint check `npm run lint`
140+
- init DB `npm run reset:db`
140141
- start connect notification server `npm start`
141142
- the app is running at `http://localhost:4000`, it also starts Kafka consumer to listen for events and save unroll-ed notifications to db
142143

‎package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint:fix": "eslint *.js --fix src config test connect",
1212
"postinstall": "npm run build",
1313
"build": "gulp build",
14-
"watch": "gulp watch"
14+
"watch": "gulp watch",
15+
"reset:db": "node tools/resetDb.js"
1516
},
1617
"author": "TCSCODER",
1718
"license": "none",

‎tools/resetDb.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Script for initializing/resetting DB.
3+
*
4+
* WARNING
5+
* It recreates DB schema causing removing existent data if any.
6+
*/
7+
const notificationServer = require('../index');
8+
9+
console.info('Initializing db...');
10+
11+
notificationServer
12+
.initDatabase()
13+
.then(() => {
14+
console.info('Database was successfully initialized.');
15+
process.exit();
16+
})
17+
.catch((err) => {
18+
console.error('Error initializing DB', err);
19+
process.exit(1);
20+
});

0 commit comments

Comments
 (0)
Please sign in to comment.