Skip to content

Commit eeaf407

Browse files
committed
chore: add seed script
1 parent 5c0e0be commit eeaf407

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"sinon": "12.0.1"
1717
},
1818
"scripts": {
19+
"seed": "env NODE_ENV=development node ./seed",
1920
"start": "env NODE_ENV=development func start",
2021
"deploy": "rm -rf ./node_modules && npm install --production && func azure functionapp publish mongoosejs",
2122
"test": "env NODE_ENV=test mocha test/*.test.js",

seed/index.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const config = require('../.config');
5+
const connect = require('../src/db');
6+
7+
assert.ok(config.uri.includes('localhost'), 'Can only seed localhost!');
8+
9+
run().catch(err => {
10+
console.log(err);
11+
process.exit(-1);
12+
});
13+
14+
async function run() {
15+
const conn = await connect();
16+
17+
await conn.dropDatabase();
18+
19+
const { Subscriber } = conn.models;
20+
21+
await Subscriber.create([
22+
{
23+
githubUsername: 'vkarpov15',
24+
githubUserId: '1620265'
25+
},
26+
{
27+
githubUsername: 'IslandRhythms',
28+
githubUserId: '39510674'
29+
}
30+
]);
31+
32+
console.log('Done');
33+
process.exit(0);
34+
}

0 commit comments

Comments
 (0)