不要怂,就是干,撸起袖子干!

Commit 76a14ab4 by Grzegorz Niewisiewicz

Fix #162

- a migration timestamp can be separated with a dash or an underscore
  from its name
- match exactly 14 digits; previous regex matched greedily so in
  00000000000000-foo-bar.js it would take 00000000000000-foo as an ID
1 parent be00bda0
Showing with 13 additions and 13 deletions
...@@ -10,8 +10,11 @@ module.exports = (function() { ...@@ -10,8 +10,11 @@ module.exports = (function() {
this.migrator = migrator this.migrator = migrator
this.path = path this.path = path
this.filename = Utils._.last(this.path.split('/')) this.filename = Utils._.last(this.path.split('/'))
this.migrationId = parseInt(this.filename.match(/(.*)-.*/)[1])
this.date = Migration.stringToDate(this.filename) var parsed = Migration.parseFilename(this.filename)
this.migrationId = parsed.id
this.date = parsed.date;
this.queryInterface = this.migrator.queryInterface this.queryInterface = this.migrator.queryInterface
this.undoneMethods = 0 this.undoneMethods = 0
} }
...@@ -20,20 +23,17 @@ module.exports = (function() { ...@@ -20,20 +23,17 @@ module.exports = (function() {
// static ///// // static /////
/////////////// ///////////////
Migration.getFormattedDateString = function(s) { Migration.parseFilename = function(s) {
var result = null var matches = s.match(/^((\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}))[-_].+/)
try { if(matches === null) {
result = s.match(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/).slice(1, 6).join('-') throw new Error(s + ' is not a valid migration name! Use YYYYMMDDHHmmss-migration-name format.')
} catch(e) {
throw new Error(s + ' is no valid migration timestamp format! Use YYYYMMDDHHmmss!')
} }
return result return {
} id: parseInt(matches[1]),
date: moment(matches.slice(2, 8).join('-'), 'YYYYMMDDHHmmss')
Migration.stringToDate = function(s) { }
return moment(Migration.getFormattedDateString(s), "YYYYMMDDHHmmss")
} }
Migration.migrationHasInterfaceCalls = function(func) { Migration.migrationHasInterfaceCalls = function(func) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!