Skip to content

Commit 6144472

Browse files
committed
chore: return array of files correctly on check
Signed-off-by: Tobias Gurtzick <[email protected]>
1 parent dd0e507 commit 6144472

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

lib/walker.js

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,40 @@ Walker.prototype = {
107107
up: function (options, callback) {
108108
const partialName = options.destination;
109109
const count = options.count;
110-
return Promise.all([
110+
const files = Promise.all([
111111
File.loadFromFileystem(this.directory, this.prefix, this.internals),
112112
File.loadFromDatabase(
113113
this.directory,
114114
this.prefix,
115115
this._driver,
116116
this.internals
117117
)
118-
])
119-
.spread((allFiles, completedFiles) => {
120-
const toRun = dbmUtil.filterUp(
121-
allFiles,
122-
completedFiles,
123-
partialName,
124-
count
125-
);
118+
]).spread((allFiles, completedFiles) => {
119+
const toRun = dbmUtil.filterUp(
120+
allFiles,
121+
completedFiles,
122+
partialName,
123+
count
124+
);
125+
126+
if (toRun.length === 0) {
127+
log.info(this.title + 'Nothing to run');
128+
}
126129

127-
if (toRun.length === 0) {
128-
log.info(this.title + 'Nothing to run');
129-
}
130+
if (this.internals.check) {
131+
const toRunNames = toRun.map(migration => migration.name);
132+
log.info(this.title + 'run:', toRunNames);
133+
return toRunNames;
134+
}
130135

131-
if (this.internals.check) {
132-
const toRunNames = toRun.map(migration => migration.name);
133-
log.info(this.title + 'run:', toRunNames);
134-
return [];
135-
}
136+
return toRun;
137+
});
136138

137-
return toRun;
138-
})
139+
if (this.internals.check) {
140+
return files.nodeify(callback);
141+
}
142+
143+
return files
139144
.each(file => {
140145
log.verbose(this.title + 'preparing to run up:', file.name);
141146
const _meta = file.get()._meta || {};
@@ -153,27 +158,32 @@ Walker.prototype = {
153158
const partialName = options.destination;
154159
const count = options.count;
155160

156-
return File.loadFromDatabase(
161+
const files = File.loadFromDatabase(
157162
this.directory,
158163
this.prefix,
159164
this._driver,
160165
this.internals
161-
)
162-
.then(completedFiles => {
163-
const toRun = dbmUtil.filterDown(completedFiles, partialName, count);
166+
).then(completedFiles => {
167+
const toRun = dbmUtil.filterDown(completedFiles, partialName, count);
164168

165-
if (toRun.length === 0) {
166-
log.info(this.title + 'Nothing to run');
167-
}
169+
if (toRun.length === 0) {
170+
log.info(this.title + 'Nothing to run');
171+
}
168172

169-
if (this.internals.check) {
170-
const toRunNames = toRun.map(migration => migration.name);
171-
log.info(this.title + 'To run:', toRunNames);
172-
return [];
173-
}
173+
if (this.internals.check) {
174+
const toRunNames = toRun.map(migration => migration.name);
175+
log.info(this.title + 'run:', toRunNames);
176+
return toRunNames;
177+
}
174178

175-
return toRun;
176-
})
179+
return toRun;
180+
});
181+
182+
if (this.internals.check) {
183+
return files.nodeify(callback);
184+
}
185+
186+
return files
177187
.each(file => {
178188
log.verbose(this.title + 'preparing to run down:', file.name);
179189
const _meta = file.get()._meta || {};

0 commit comments

Comments
 (0)