Skip to content

Commit

Permalink
fix(environment): store seed data. Fixes MEMB-854 (#21)
Browse files Browse the repository at this point in the history
* fix(environment): store seed data. Fixes MEMB-854

* chore: forgot to commit gitignore here

* chore: small fixes
  • Loading branch information
serge1peshcoff authored Jun 15, 2020
1 parent a935b13 commit 8fac626
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.git
node_modules/
state/
3 changes: 3 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
volumes:
- oms-core-js-media:/usr/app/media
- shared:/usr/app/shared:ro
- oms-core-js-state:/usr/app/src/state:rw
depends_on:
- postgres-oms-core-js
expose:
Expand Down Expand Up @@ -49,6 +50,8 @@ volumes:
driver: local
shared:
driver: local
oms-core-js-state:
driver: local

networks:
default:
Expand Down
1 change: 1 addition & 0 deletions docker/oms-core-js/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN apt-get install netcat -y
COPY ./docker/oms-core-js/bootstrap.sh /usr/app/scripts/bootstrap.sh
COPY ./docker/oms-core-js/wait.sh /usr/app/scripts/wait.sh
COPY . /usr/app/src
RUN mkdir /usr/app/src/state

RUN chown -R node:node /usr/app

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"lint:fix": "node_modules/.bin/eslint --fix .",
"lint-staged": "lint-staged",
"db:create": "sequelize db:create",
"db:setup": "sequelize db:drop; sequelize db:create; sequelize db:migrate; rm -f .seed-executed",
"db:setup": "sequelize db:drop; sequelize db:create; sequelize db:migrate; rm -f state/.seed-executed-$NODE_ENV",
"db:migrate": "sequelize db:migrate",
"db:seed": "LOGLEVEL=info node --experimental-repl-await scripts/seed.js && touch .seed-executed",
"db:clear": "LOGLEVEL=info node --experimental-repl-await scripts/clear.js; rm -f .seed-executed",
"db:seed": "LOGLEVEL=info node --experimental-repl-await scripts/seed.js && touch state/.seed-executed-$NODE_ENV",
"db:clear": "LOGLEVEL=info node --experimental-repl-await scripts/clear.js; rm -f state/.seed-executed-$NODE_ENV",
"cli": "node --experimental-repl-await -r ./cli.js",
"open-coverage": "open-cli coverage/lcov-report/index.html"
},
Expand Down
4 changes: 3 additions & 1 deletion scripts/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const {
PasswordReset
} = require('../models');

const seedStatePath = path.resolve(__dirname, '../state/.seed-executed-' + (process.env.NODE_ENV || 'development'));

const data = {};

async function createAdmin() {
Expand Down Expand Up @@ -936,7 +938,7 @@ async function createCampaign() {
});
}

if (fs.existsSync(path.resolve(__dirname, '../.seed-executed'))) {
if (fs.existsSync(seedStatePath)) {
logger.info('[seeds ]: Seed was executed already, no need to run it again.');
process.exit(0);
}
Expand Down
1 change: 1 addition & 0 deletions state/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.seed-executed*

0 comments on commit 8fac626

Please sign in to comment.