Skip to content

Commit

Permalink
Change migrations to be timestamped instead of in sequential order.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctide committed Sep 14, 2011
1 parent 8fd55f3 commit 36f7c98
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 31 deletions.
18 changes: 9 additions & 9 deletions Readme.md
Expand Up @@ -43,7 +43,7 @@ For example:
$ migrate create add-pets
$ migrate create add-owners

The first call creates `./migrations/000-add-pets.js`, which we can populate:
The first call creates `./migrations/{timestamp in milliseconds}-add-pets.js`, which we can populate:

var db = require('./db');

Expand All @@ -58,7 +58,7 @@ The first call creates `./migrations/000-add-pets.js`, which we can populate:
db.rpop('pets', next);
};

The second creates `./migrations/001-add-owners.js`, which we can populate:
The second creates `./migrations/{timestamp in milliseconds}-add-owners.js`, which we can populate:

var db = require('./db');

Expand All @@ -77,10 +77,10 @@ The second creates `./migrations/001-add-owners.js`, which we can populate:
When first running the migrations, all will be executed in sequence.

$ migrate
up : migrations/000-add-pets.js
up : migrations/001-add-jane.js
up : migrations/002-add-owners.js
up : migrations/003-coolest-pet.js
up : migrations/1316027432511-add-pets.js
up : migrations/1316027432512-add-jane.js
up : migrations/1316027432575-add-owners.js
up : migrations/1316027433425-coolest-pet.js
migration : complete

Subsequent attempts will simply output "complete", as they have already been executed in this machine. `node-migrate` knows this because it stores the current state in `./migrations/.migrate` which is typically a file that SCMs like GIT should ignore.
Expand All @@ -91,9 +91,9 @@ Subsequent attempts will simply output "complete", as they have already been exe
If we were to create another migration using `migrate create`, and then execute migrations again, we would execute only those not previously executed:

$ migrate
up : migrates/004-coolest-owner.js
up : migrates/1316027433455-coolest-owner.js

## License
## License

(The MIT License)

Expand All @@ -116,4 +116,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 changes: 2 additions & 21 deletions bin/migrate
Expand Up @@ -162,32 +162,13 @@ var commands = {
*/

create: function(){
var migrations = fs.readdirSync('migrations').filter(function(file){
return file.match(/^\d+/);
}).map(function(file){
return parseInt(file.match(/^(\d+)/)[1], 10);
}).sort(function(a, b){
return a - b;
});

var curr = pad((migrations.pop() || 0) + 1)
var curr = Date.now()
, title = slugify([].slice.call(arguments).join(' '));
title = title ? curr + '-' + title : curr;
title = title ? curr + '-' + title : curr;
create(title);
}
};

/**
* 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`.
*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/set.js
Expand Up @@ -119,7 +119,7 @@ Set.prototype.migrate = function(direction, fn){

/**
* Perform migration.
*
*
* @api private
*/

Expand Down

0 comments on commit 36f7c98

Please sign in to comment.