10

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?

1 Answer 1

20

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Can you please clarify what did you changed exactly. I did run into same issue. But I don't have any migration named that way
@UmakantPatil All I did was naming the migration with the following format: yyyyMMddhhmmss-<some text>
Might want to check for temp/backup/system files created by IDE/OS in the migrations folder. In my case, I had added a helper lib to the migrations folder, thinking db-migrate would only pull in files that matched the db-migrate naming convention: YYYYMMDDHHmmss-{NAME}.js. Apparently, that's not the case. db-migrate will attempt to parse all *.js files in the migrations folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.