forked from EmilyCMcCarthy/graceshopper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharSeed.js
68 lines (58 loc) · 1.75 KB
/
CharSeed.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var Promise = require('bluebird');
var db = require('./server/db');
var Character = require('./server/db/models/character');
var Bluebird = require('bluebird')
// EI: don't forget to update character price levels
var characters = [
{
name: "Albus Dumbledore",
price: 1000,
imageUrl: "/characters/albus.jpg",
description: "Be Dumbledore. Live in the magical world of Harry Potter... Be the headmaster at Hogwarts",
inventory: 10
},
{
name: "Wonder Woman",
price: 2000,
imageUrl: "/characters/ww.jpg",
description: "Be Wonder Woman. Super Awesome",
inventory: 3
},
{
name: "Frodo Baggins",
price: 400,
imageUrl: "/characters/frodo.jpg",
description: "Live in the houses with the circle doors. Protect the world. Take the One ring to be destroyed?",
inventory: 14
},
{
name: "Hermione Granger",
price: 6000,
imageUrl: "/characters/hermione.jpg",
description: "The brightest witch of her Time. Enjoy the friendship of Ron and Harry",
inventory: 17
},
{
name: "Luke Skywalker",
price: 3000,
imageUrl: "/characters/luke_sky.jpg",
description: "The force will be with you if you choose Luke Skywalker",
inventory: 7
}
]
db.sync({ force: true })
.then(() => {
return Bluebird.map(characters, character => {
return Character.create(character)
})
})
.then(() => {
console.log('The database hase been seeded');
})
.catch(err => {
console.log('There has been an error', err);
})
.finally(() => {
db.close();
console.log('connection to the database closed!')
})