forked from sarahzhao25/exp-seq-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.js
100 lines (96 loc) · 1.83 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const { db, MenuItem, Restaurant } = require('./models');
const restaurants = [{
name: 'Restaurant A',
cuisineType: 'CHINESE',
rating: 4.41
}, {
name: 'RESTAURANT B',
cuisineType: 'MEXICAN',
rating: 3.33
}, {
name: 'RESTAURANT C',
cuisineType: 'KOREAN',
rating: 3.26
}, {
name: 'RESTAURANT D',
cuisineType: 'INDIAN',
rating: 4.24
}, {
name: 'RESTAURANT E',
cuisineType: 'AMERICAN',
rating: 2.82
}, {
name: 'RESTAURANT F',
cuisineType: 'MEXICAN',
rating: 4.82
}, {
name: 'RESTAURANT G',
cuisineType: 'INDIAN',
rating: 3.75
}
];
const menuItems = [{
name: 'Item A',
calories: 1200,
isSpicy: true,
restaurantId: 1
}, {
name: 'Item B',
calories: 300,
isSpicy: false,
restaurantId: 2
}, {
name: 'Item C',
calories: 500,
isSpicy: true,
restaurantId: 3
}, {
name: 'Item D',
calories: 800,
isSpicy: false,
restaurantId: 4
}, {
name: 'Item E',
calories: 700,
isSpicy: true,
restaurantId: 5
}, {
name: 'Item F',
calories: 1800,
isSpicy: false,
restaurantId: 6
}, {
name: 'Item G',
calories: 2000,
isSpicy: true,
restaurantId: 1
}, {
name: 'Item H',
calories: 300,
isSpicy: false,
restaurantId: 2
}, {
name: 'Item I',
calories: 600,
isSpicy: true,
restaurantId: 3
}, {
name: 'Item J',
calories: 900,
isSpicy: false,
restaurantId: 4
}];
const seed = async () => {
try {
await db.sync({ force: true });
await Promise.all(restaurants.map(resy => Restaurant.create(resy)));
console.log(`${restaurants.length} restaurants have been built!`);
await Promise.all(menuItems.map(mI => MenuItem.create(mI)));
console.log(`${menuItems.length} menu items have been added!`);
console.log(`I am done seeding; let's get ready to ORDER!`);
await db.close();
} catch (e) {
console.log('Something went wrong in the seeding!', e);
}
}
seed();