-
Notifications
You must be signed in to change notification settings - Fork 2
/
seed.js
55 lines (50 loc) · 1.92 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
var Db = require('./lib/db.js')();
var db = Db.db;
var faker = require('faker');
var Promise = require('bluebird');
// sync with force=true will drop tables and then rebuild the db from our models
// db.sync({force: true}).then(function() {
Db.reset().then(function() {
var fakeUsers = [];
fakeUsers.push({username: 'e', email: '[email protected]', password: 'e', avatar_image_url: '/images/avatars/blavatars-06.png'})
// composes array of fake data objects
for (var i = 0; i < 0; i++){
fakeUsers.push({
username: faker.name.findName(),
email: faker.internet.email(),
password: faker.internet.password()
});
}
// feeds fake user data into the db
Promise.map(fakeUsers, function(e){
return Db.digestPassword(e.password).then(function(password_digest) {
return db.none("INSERT INTO users (username,email,password,avatar_image_url) VALUES ($1,$2,$3,$4)",[e.username,e.email,password_digest,e.avatar_image_url]);
});
}).then(function(){
console.log('added users');
// fake posts
// var fakePosts = [];
//
// // randomly create the data
// for (var i = 0; i < 0; i++){
// fakePosts.push([
// /*user_id*/ Math.floor(Math.random() * 98 + 1),
// /*lat*/ Math.random() * 0.3 + 40.553,
// /*lng*/ Math.random() * 0.15 - 73.999,
// /*message*/ faker.lorem.sentence(),
// /*emotion*/ (Math.floor(Math.random() * 2) === 0)? 'rant' : 'rave',
// /*timestamp*/ new Date(new Date() - Math.floor(Math.random() * 1000*60*60*6))
// ]);
// }
// // and feed into the database
// return Promise.map(fakePosts, function(e){
// return db.none("INSERT INTO posts (user_id,lat,lng,message,emotion,timestamp) VALUES ($1,$2,$3,$4,$5,$6)",e);
// })
// }).then(function() {
// console.log("added posts");
// return db.many("SELECT * FROM posts");
// }).then(function(rows) {
// console.log(rows);
process.exit();
});
});