-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
39 lines (36 loc) · 1.2 KB
/
seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { green, red } = require('chalk');
const { db, Project, Robot } = require('./server/db');
const project_seed = require('./project_seed');
const robot_seed = require('./robot_seed');
const projects_robots_like = require('./projects_robots_like');
const seed = async () => {
try {
await db.sync({ force: true });
await Project.bulkCreate(project_seed);
await Robot.bulkCreate(robot_seed);
const robot = await Robot.findByPk(1);
const project = await Project.findByPk(1);
const _robot = await Robot.findByPk(2);
const _project = await Project.findByPk(2);
await robot.addProject(project);
await _robot.addProject(_project);
} catch (err) {
console.log(red(err));
}
};
module.exports = seed;
// If this module is being required from another module, then we just export the
// function, to be used as necessary. But it will run right away if the module
// is executed directly (e.g. `node seed.js` or `npm run seed`)
if (require.main === module) {
seed()
.then(() => {
console.log(green('Seeding success!'));
db.close();
})
.catch((err) => {
console.error(red('Oh noes! Something went wrong!'));
console.error(err);
db.close();
});
}