Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed: pad migration numbers

  • Loading branch information...
commit cb16f883fbdc9f78c2467b4a86cd7f99f1b66e06 1 parent 7d2d16b
@tj authored
View
19 bin/migrate
@@ -165,10 +165,12 @@ var commands = {
var migrations = fs.readdirSync('migrations').filter(function(file){
return file.match(/^\d+/);
}).map(function(file){
- return parseInt(file.match(/^(\d+)/)[1]);
- }).sort();
+ return parseInt(file.match(/^(\d+)/)[1], 10);
+ }).sort(function(a, b){
+ return a - b;
+ });
- var curr = migrations.pop() + 1
+ var curr = pad(migrations.pop() + 1)
, title = slugify([].slice.call(arguments).join(' '));
title = title ? curr + '-' + title : curr;
create(title);
@@ -176,6 +178,17 @@ var commands = {
};
/**
+ * Pad the given number.
+ *
+ * @param {Number} n
+ * @return {String}
+ */
+
+function pad(n) {
+ return Array(4 - n.toString().length).join('0') + n;
+}
+
+/**
* Create a migration with the given `name`.
*
* @param {String} name
View
0  examples/cli/migrations/0-add-pets.js → examples/cli/migrations/000-add-pets.js
File renamed without changes
View
0  examples/cli/migrations/1-add-jane.js → examples/cli/migrations/001-add-jane.js
File renamed without changes
View
0  examples/cli/migrations/2-add-owners.js → examples/cli/migrations/002-add-owners.js
File renamed without changes
View
0  examples/cli/migrations/3-coolest-pet.js → examples/cli/migrations/003-coolest-pet.js
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.