Skip to content

Commit 93c87f0

Browse files
author
joeltaylor
committed
Add database seeding to gulpfile
1 parent 674b21c commit 93c87f0

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

gulpfile.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ var svgmin = require('gulp-svgmin');
2121
var svgstore = require('gulp-svgstore');
2222
var _ = require('lodash');
2323
var run = require('run-sequence');
24+
var Chance = require('chance');
25+
var db = require('./services/db');
2426

2527
// -------------------------------------
2628
// Variables
@@ -226,3 +228,55 @@ gulp.task('icons', function() {
226228
.pipe(svgstore({ inlineSvg: true }))
227229
.pipe(gulp.dest(options.icons.destDir));
228230
});
231+
232+
// -------------------------------------
233+
// Task: Seeds
234+
// -------------------------------------
235+
gulp.task('seeds', function() {
236+
var chance = new Chance();
237+
for(i = 0; i < 50; i++) {
238+
var title = chance.sentence({words: 5});
239+
var slug = title.toLowerCase().replace(/[^a-zA-Z0-9\s]/g,"").replace(/\s/g,'-');
240+
var body = chance.paragraph();
241+
var url = chance.url();
242+
var published_at = chance.date({year: 2014});
243+
db.query('INSERT INTO articles (title, slug, body, url, published_at, news, approved) VALUES ($1, $2, $3, $4, $5, true, true);',
244+
[title, slug, body, url, published_at],
245+
function(){}
246+
);
247+
}
248+
for (i = 0; i < 7; i++) {
249+
var githubId = chance.integer({min: 1, max: 6000});
250+
var email = chance.email();
251+
var name = chance.name();
252+
var avatarUrl = 'https://avatars.githubusercontent.com/u/' + chance.pick([6965062,3412,10722,6797535,2618,30208]) + '?v=3';
253+
db.query('INSERT INTO users (github_id, email, name, avatar_url) VALUES ($1, $2, $3, $4);',
254+
[githubId, email, name, avatarUrl],
255+
function(){}
256+
);
257+
}
258+
259+
for(i = 0; i < 50; i++) {
260+
var title = chance.sentence({words: 5});
261+
var slug = title.toLowerCase().replace(/[^a-zA-Z0-9\s]/g,"").replace(/\s/g,'-');
262+
var body = chance.paragraph();
263+
var url = chance.url();
264+
var published_at = chance.date({year: 2014});
265+
var userId = chance.d6();
266+
db.query('INSERT INTO articles (user_id, title, slug, body, url, published_at, news, approved) VALUES ($1, $2, $3, $4, $5, $6, false, true);',
267+
[userId, title, slug, body, url, published_at],
268+
function(){}
269+
);
270+
}
271+
272+
for(i = 0; i < 50; i++) {
273+
var userId = chance.d6();
274+
var body = chance.paragraph();
275+
var articleId = chance.integer({min: 51, max: 100});
276+
db.query('INSERT INTO comments (user_id, approved, body, article_id) VALUES ($1, true, $2, $3);',
277+
[userId, body, articleId],
278+
function(){}
279+
);
280+
}
281+
282+
});

0 commit comments

Comments
 (0)