/
clearDb.js
61 lines (53 loc) · 1.46 KB
/
clearDb.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
'use strict';
const chalk = require( 'chalk' );
const db = require( './server/db' );
const User = db.model('user');
const Team = db.model('team');
const Promise = require('sequelize').Promise;
const seedUsers = function() {
const users = [{
username: 'jancodes',
name: 'Jansen Li',
github_id: 16806234,
photo: 'https://avatars.githubusercontent.com/u/16806234?v=3'
}, {
username: 'jdhang',
name: 'Jason Hang',
github_id: 5394681,
photo: "https://avatars.githubusercontent.com/u/5394681?v=3"
}, {
username: 'jes708',
name: 'Jonathan Schwarz',
github_id: 16601510,
photo: 'https://avatars.githubusercontent.com/u/16601510?v=3'
}, {
username: 'thejohnbackes',
name: 'thejohnbackes',
github_id: 13596692,
photo: 'https://avatars.githubusercontent.com/u/13596692?v=3'
}];
const creatingUsers = users.map(function(userObj) {
return User.create(userObj);
});
return Promise.all(creatingUsers);
};
const seedTeams = function () {
return Team.create({
name: 'The Dev Team',
github_team_id: 2059661
}).catch(error => console.log('createJJJJError', error) )
}
db.sync( {
force: true,
logging: false
} )
.then( () => seedUsers() )
.then( () => seedTeams() )
.then( function () {
console.log( chalk.green( 'Seed successful!' ) );
process.exit( 0 );
} )
.catch( function ( err ) {
console.error( err );
console.log( chalk.white('done with errors'));
} );