I've just installed the nodejs package db-migrate into an existing nodejs project. Everything seems to be configured correctly in regards to the connection to the DB.
Database.json:
{
"development": "postgres://blabla",
"production": "postgres://blabla"
}
Migration:
var dbm = global.dbm || require('db-migrate');
var type = dbm.dataType;
exports.up = function(db, callback) {
db.createTable('users', {
id: { type: 'int', primaryKey: true, autoIncrement: true },
username: { type: 'string', unique: true }
}, callback);
};
exports.down = function(db, callback) {
db.dropTable('users', callback);
};
Whenever I try to run db-migrate up
(with any variation of parameters like specifying the database file, the migration, the number of migrations, etc), the command raises an error every time:
[ERROR] TypeError: Cannot read property '1' of null
at Class.extend.parseName (C:\Users\test\Projects\nodejs\cirio-crm\node_modules\db-migrate\lib\skeleton.js:162:17)
at Class.Skeleton.extend.init (C:\Users\test\Projects\nodejs\cirio-crm\node_modules\db-migrate\lib\migration.js:35:24)
at Class.prototype.(anonymous function) [as init] (C:\Users\test\Projects\nodejs\cirio-crm\node_modules\db-migrate\lib\class.js:36:24)
at new Class (C:\Users\test\Projects\nodejs\cirio-crm\node_modules\db-migrate\lib\class.js:49:17)
at C:\Users\test\Projects\nodejs\cirio-crm\node_modules\db-migrate\lib\migration.js:312:14
at Array.map (native)
at C:\Users\test\Projects\nodejs\cirio-crm\node_modules\db-migrate\lib\migration.js:311:35
at FSReqWrap.oncomplete (fs.js:95:15)
I've tried renaming the table, changing the fields, messing with the CRLF line endings, installing different versions of nodejs and db-migrate, etc.
Any ideas?
After about an hour of running in circles I realized the migration was named incorrectly. Its first part only specified the date and not the time. The correct file name format to be used would be yyyyMMddhhmmss-<some text>
.
Before (Bad): 20160101-testmigration
After (Good): 20160101000000-testmigration
The error could have been more explicit though...
EDIT:
As pointed out by @2Toad, one has to be careful about what is stored on the folder where migrations are supposed to be found. If you have any *.js
file that doesn't follow the naming format, like a helper JS file, the same error will occur.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With