Open
Description
I'm submitting a...
- Bug reportFeature requestQuestion
Current behavior
Command line parameters override createDatabase
parameters in Programable API.
$ DATABASE_URL=postgres://localhost/postgres node index.js
[INFO] Created database "expected"
$ DATABASE_URL=postgres://localhost/postgres node index.js unexpected
[INFO] Created database "unexpected"
Expected behavior
I would expect parameters provided to createDatabase
always override possible command line arguments.
$ DATABASE_URL=postgres://localhost/postgres node index.js
[INFO] Created database "expected"
$ DATABASE_URL=postgres://localhost/postgres node index.js unexpected
[INFO] Created database "expected"
Minimal reproduction of the problem with instructions
$ cat index.js
var dbmigrate = require('db-migrate');
var dbm = dbmigrate.getInstance(true);
dbm.createDatabase('expected')
.then(function() {
process.exit(0);
});
What is the motivation / use case for changing the behavior?
Using createDatabase
through Programable API in an program that has command line args is not possible at the moment.
Environment
db-migrate version: 0.11.1
db-migrate-pg version: 0.4.0
Additional information:
- Node version: v10.6.0
- Platform: Mac
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Activity
stale commentedon Aug 23, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
KingRial commentedon Sep 17, 2018
I am problably missing something but, shouldn't you just pass the desired configuration ?
This should be the way to handle db-migrate programmatically:
Otherwise it correctly looks for configuration used by command line.
tjokimie commentedon Sep 17, 2018
@KingRial Did you try running your example with
node index.js
andnode index.js unexpected
? I get the same problem if I pass the configuration directly togetInstance
. Command line parameters override parameters provided forcreateDatabase
.For example with the following script:
Running
node index.js
will create databaseexpected
but runningnode index.js unexpected
will create databaseunexpected
.KingRial commentedon Sep 17, 2018
Now I understand what happens :) My bad!
I can confirm the problem (it doesn't matter what driver you use; even on mongo and MySQL it occurs)
stale commentedon Oct 17, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
wzrdtales commentedon Oct 18, 2018
I will check this, probably conflicting with the general config hirarchy.
trubachev commentedon Jul 12, 2019
Faced this bug right now. Found the exact line where it happening
node-db-migrate/lib/commands/db.js
Line 10 in 3c4bd77
dnjstrom commentedon Jul 12, 2019
Quick note: This bug is affecting both
createDatabase
anddropDatabase
since both rely on theexecuteDB
function, as mentioned by @trubachev.AlexGilleran commentedon Dec 27, 2019
You can work around it by manually reaching into internals:
ajw725 commentedon Dec 22, 2020
just ran into the same problem. in my case, it came up when trying to run jest tests. i have a package script like this:
and then i have a jest setup script like this:
it works fine if i just run
yarn test
, but if i try to run a specific test likeyarn test src/some_test.ts
, then the script tries to create a database called "src/some_test.ts." i don't think we should assume argv is empty.ajw725 commentedon Dec 22, 2020
i don't know if this would be acceptable, but you could do something like:
and then
seems to work ok when i monkey-patch it locally that way, but i haven't tested extensively to know if it might somehow break something else.