Skip to content

If database.json includes {"ENV": "DATABASE_URL"} then migrations require the environment variable to contain a valid value #391

@erezny

Description

@erezny

I defined a dev environment that uses sqlite3 and defined staging and prod environment which use heroku postgres. When I run a migration in the dev environment node-db-migrate complains about the environment variables in staging and prod. I do not want to include the flat values in my database.json because I do not want these secret values in my code base.

database.json:

{
  "defaultEnv": "dev",
  "dev": {
    "driver": "sqlite3",
    "filename": "dev.db"
  },

  "test": {
    "driver": "sqlite3",
    "filename": ":memory:"
  },

  "staging": { "ENV": "DATABASE_URL" },
  "prod": { "ENV": "DATABASE_URL" }
}
$ node node_modules/db-migrate/bin/db-migrate up -e dev --config "./database.json" -v
[INFO] Detected and using the projects local version of db-migrate. '/.../node_modules/db-migrate/index.js'
[ERROR] TypeError: Parameter "url" must be a string, not undefined
    at Url.parse (url.js:87:11)
    at Object.urlParse [as parse] (url.js:81:5)
    at module.exports (/.../node_modules/parse-database-url/lib/parse-database-url.js:16:23)
    at Object.exports.loadObject (/.../node_modules/db-migrate/lib/config.js:67:18)
    at Object.exports.loadFile (/.../node_modules/db-migrate/lib/config.js:59:18)
    at loadConfig (/.../node_modules/db-migrate/api.js:555:18)
    at Object.dbmigrate (/.../node_modules/db-migrate/api.js:67:17)
    at Object.module.exports.getInstance (/.../node_modules/db-migrate/index.js:56:10)
    at /.../node_modules/db-migrate/bin/db-migrate:34:23
    at /.../node_modules/resolve/lib/async.js:44:21
    at ondir (/.../node_modules/resolve/lib/async.js:187:31)
    at onex (/.../node_modules/resolve/lib/async.js:93:22)
    at /.../node_modules/resolve/lib/async.js:24:18
    at FSReqWrap.oncomplete (fs.js:123:15)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions