Skip to content

Commit

Permalink
Fix seeder:undo:all issue (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
sushantdhiman authored Mar 8, 2017
1 parent 85b8446 commit 24a7ba9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/tasks/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ module.exports = {

task: function () {
return getMigrator('seeder').then(function (migrator) {
return migrator.pending()
return (
helpers.umzug.getStorage('seeder') === 'none' ? migrator.pending() : migrator.executed()
)
.then(function (seeders) {
if (seeders.length === 0) {
console.log('No seeders found.');
Expand Down
32 changes: 30 additions & 2 deletions test/db/seed/undo/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ var expect = require('expect.js');
var Support = require(__dirname + '/../../../support');
var helpers = require(__dirname + '/../../../support/helpers');
var gulp = require('gulp');
var _ = require('lodash');

([
'db:seed:undo:all'
]).forEach(function (flag) {
var prepare = function (callback, options) {
var _flag = options.flag || flag;
var _flag = options.flag || flag;
var config = _.assign({}, helpers.getTestConfig(), options.config || {});

var pipeline = gulp
.src(Support.resolveSupportPath('tmp'))
Expand All @@ -22,7 +24,7 @@ var gulp = require('gulp');
.pipe(helpers.copySeeder('seedPerson2.js'));
}

pipeline.pipe(helpers.overwriteFile(JSON.stringify(helpers.getTestConfig()),
pipeline.pipe(helpers.overwriteFile(JSON.stringify(config),
'config/config.json'))
.pipe(helpers.runCli('db:migrate'))
.pipe(helpers.runCli(_flag, { pipeStdout: true }))
Expand Down Expand Up @@ -59,5 +61,31 @@ var gulp = require('gulp');
});
}, {flag: 'db:seed:all', copySeeds: true});
});

it('is correctly undoing all seeders when storage is none', function (done) {
var self = this;

prepare(function () {
helpers.countTable(self.sequelize, 'Person', function (res) {
expect(res).to.have.length(1);
expect(res[0].count).to.eql(2);

gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.runCli(flag, { pipeStdout: true }))
.pipe(helpers.teardown(function () {
helpers.countTable(self.sequelize, 'Person', function (res) {
expect(res).to.have.length(1);
expect(res[0].count).to.eql(0);
done();
});
}));
});
}, {
flag: 'db:seed:all',
copySeeds: true,
config: { seederStorage: 'none' }
});
});
});
});

0 comments on commit 24a7ba9

Please sign in to comment.