db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

[ERROR] TypeError: Cannot read property 'split' of undefined #443

Closed SeanJOBrien closed 7 years ago

SeanJOBrien commented 7 years ago

Hi There,

Not sure if this is a bug or an issue but for the moment lets make it a question, ive got a set up thats working with db-migrate installed locally running in a docker container that is picking up environment variables within the config which is great thank you for that. Once i move from there to trying to insert the module in an application im getting the error "[ERROR] TypeError: Cannot read property 'split' of undefined" My layout is bellow.

Main.js

var DBMigrate = require('db-migrate');
var assert = require('assert');

function logginCallback(migrator, originalError) {
  migrator.driver.close(function(err) {
    assert.ifError(originalErr);
    assert.ifError(err);
    log.info('Done');
  });
}

var dbmigrate = DBMigrate.getInstance(true, {config: 'config/database.json'},logginCallback);

dbmigrate.run();`

config/database.json

{
  "defaultEnv": {"ENV": "ENVIRONMENT_TYPE"},
  "dev": {
    "driver": "pg",
    "user": "user",
    "password": "password",
    "host": {"ENV": "POSTGRESQL_ADDR"},
    "port":  {"ENV": "POSTGRESQL_PORT"},
    "database": "dbname",
    "schema": "public"
  }
}

the Line it portrays to app.js 1150 within db-migrate

function run(internals, config) {
  var action = internals.argv._.shift(),
    folder = action.split(':');
  action = folder[0]; 

Basically Id say ive done something incorrect but the error persists no matter what i try so help would be great.

wzrdtales commented 7 years ago

Can you please post the full stack trace? And use the code blocks next time to make your snippet better readable, just edited it for you ;)

wzrdtales commented 7 years ago

And why do you run dbmigrate.run(); instead of usin the programable API methods?

wzrdtales commented 7 years ago

Maybe this already helps you:

Here are example of how to use the programable API:

Promise Style

https://github.com/db-migrate/api-examples/blob/master/promise.js

Callback Style

https://github.com/db-migrate/api-examples/blob/master/index.js

SeanJOBrien commented 7 years ago

Updated it all to code blocks sorry about that ill give that a go in the morning (dont have the machine on me currently) see if it sorts me i was following the example here

https://db-migrate.readthedocs.io/en/latest/API/programable/

Just need it to run a migration so i can log the errors to file so not doing anything crazy with it for the moment.

wzrdtales commented 7 years ago

@SeanJOBrien Yes, this is referring to calling the default behavior meaning the cli. Maybe I should adjust also the comment of that example //get an instance and call the standard runtime behavior as it seems to be confusing.

Anyway the docs for te programable API will improve, I hope I get some time this evening to write the last few lines and examples and push them out.

SeanJOBrien commented 7 years ago

Running up seems to have solved my original problem but caused another ill see if i can self resolve this and get back to you the run() still wasn't working for me but in this case i don't need it i can work away now thank you for your time.

wzrdtales commented 7 years ago

you also don't want run;). This starts the cli mode