-
Notifications
You must be signed in to change notification settings - Fork 15
/
seed.js
85 lines (71 loc) · 2.02 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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const db = require("./server/db");
const User = require("./server/db/models/user")
const user = [{
"email": "catlady@gmail.com",
"password": "catscatscats",
"salt": "",
"googleId":"",
"animalPreferences": ["cat"],
"hasYoungChildren": false,
"otherPetTypes": ["smallfurry"],
"zipCode": 11372,
"phoneNumber": "3472441139",
"petHistory": "I am a human on the outside but a cat on the inside. Recently, one of my cats died and I'm in need of another companion"
}, {
"email": "animals4ever@gmail.com",
"password": "doggydog",
"salt": "",
"googleId":"",
"animalPreferences": ["dog", "cat"],
"hasYoungChildren": true,
"otherPetTypes":["barnyard"],
"zipCode": 10003,
"phoneNumber": "7185034444",
"petHistory": "I've had the luxury of having chickens in my backyard. I love animals and would like to have an indoor animal to add to my collection."
}, {
"email": "humansRevil@gmail.com",
"password":"misanthrope",
"salt":"",
"googleId":"",
"animalPreferences":["dog", "cat", "bird"],
"hasYoungChildren": false,
"otherPetTypes":["reptile"],
"zipCode": 11369,
"phoneNumber":8001234567,
"petHistory": "I'm in need for some furry companionship. I'd like more animal friends."
}, {
"email": "birdsarelife@gmail.com",
"password": "imlikeabird",
"salt": "",
"googleId": "",
"animalPreferences": ["bird"],
"hasYoungChildren": true,
"otherPetTypes":["bird"],
"zipCode": 11377,
"phoneNumber": 9176666666,
"petHistory": "I already own 2 parrots, I'd like more!"
}]
const seed = () =>
Promise.all(user.map(user =>
User.create(user))
)
.catch(err => {
console.log("Error in Promise");
console.log(err.stack);
})
const main = () => {
console.log("Syncing db...");
db.sync({ force: true })
.then(() => {
console.log("Seeding database...");
return seed();
})
.catch(err => {
console.log("Error while seeding");
console.log(err.stack);
})
.then(() => {
db.close();
});
};
main();