Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Add update-post-counters npm task
Browse files Browse the repository at this point in the history
  • Loading branch information
voidxnull committed May 15, 2016
1 parent d240b0b commit 4088c4f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
22 changes: 22 additions & 0 deletions bin/postCounters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import bookshelf from './utils/bookshelf';


async function updatePostCounters() {
process.stdout.write("=== RECALCULATING POST COUNTERS ===\n");

const models = ['Hashtag', 'School', 'Geotag'];

for (const modelName of models) {
await bookshelf.model(modelName).updatePostCounters();
}
}

updatePostCounters()
.then(() => {
process.stdout.write("=== DONE ===\n");
process.exit();
})
.catch(e => {
process.stderr.write(e.stack);
process.exit(1);
});
6 changes: 6 additions & 0 deletions bin/utils/bookshelf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { initBookshelfFromKnex } from '../../src/api/db';
import knex from './knex';

const bookshelf = initBookshelfFromKnex(knex);

export default bookshelf;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"webpack:build:dev": "webpack --config webpack.dev.config.js",
"webpack:build:prod": "NODE_ENV=production webpack --config webpack.prod.config.js",
"db:migrate": "knex migrate:latest",
"db:rollback": "knex migrate:rollback"
"db:rollback": "knex migrate:rollback",
"update-post-counters": "babel-node bin/postCounters.js"
},
"author": {
"name": "Loki Education (Social Enterprise)",
Expand Down

0 comments on commit 4088c4f

Please sign in to comment.