-
Notifications
You must be signed in to change notification settings - Fork 30
feat: Add method to run migration script by name. #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| * @param {String} [record] Record the migration runtime to database. | ||
| * @param {Function} [cb] Callback function. | ||
| */ | ||
| Migration.migrateByName = function(name, record, cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line should be removed @rahulbile as I don't think it makes sense to default the name to an empty string.
lib/models/migration.js
Outdated
| * @param {Function} [cb] Callback function. | ||
| */ | ||
| Migration.migrateByName = function(name, record, cb) { | ||
| name = name || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think record should be an optional property - you need to add something like this just above this line:
if (typeof cb === 'undefined' && typeof record === 'function') {
cb = record
record = false
}
lib/models/migration.js
Outdated
| try { | ||
| require(scriptPath).up(Migration.app, function(err) { | ||
| if (err) { | ||
| Migration.log.error(name, 'error:'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest combining these 2 lines so that only one error message is logged if there is an error. Perhaps make the error message a little more descriptive too:
Migration.log.error(`Error running migration script ${name}:`, err);
| Migration.create({ | ||
| name: name, | ||
| runDtTm: new Date() | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing a call to cb() after a successful migration.
lib/models/migration.js
Outdated
| } | ||
| }); | ||
| } catch (err) { | ||
| Migration.log.error('Error running migration', name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets combine these 2 lines into a single log message too @rahulbile
| Migration.create({ | ||
| name: name, | ||
| runDtTm: new Date() | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to move to below this if block since we want to call it regardless of the value of record
No description provided.