cli
cli copied to clipboard
--url flag errors running migration
Issue Creation Checklist
[X] I have read the contribution guidelines
Issue Description
I'm running the migration command as suggested in the documentation, it is an alternative to the ./config/config.js
file.
$ npx sequelize-cli db:migrate --url 'postgres://postgres:somepassword@some-playground-instance-cluster.some-hash.us-east-1.rds.amazonaws.com'
I'm expecting for the command to successfully execute the migration.
What was unclear/insufficient/not covered in the documentation
If the command is an alternative to the ./config/config.js
file, the command should succeed but rather it failing with
ERROR: Error reading "config/config.json". Error: Error: Error parsing url: postgres://postgres:somepassword@some-playground-instance-cluster.some-hash.us-east-1.rds.amazonaws.com
If possible: Provide some suggestion on how we can enhance the docs
- When running the command, do I still need the
./config/config.js
file? - If the
./config/config.js
still needed. Does it needs something special config when utilizing the--url
flag so it doesn't fail?
Additional context
Add any other context or screenshots about the issue here.
The CLI does not like the format of your url. It is being parsed in the config-helper and url.parse
can't find a pathname so it also is unable to replace it.
In the future we should improve the error being returned for this, but to fix this you should provide the name of the database at the end of your url.
https://github.com/sequelize/cli/blob/v6.4.1/src/helpers/config-helper.js#L171-L193
Thanks for your response. Indeed, the --url
flag needs the database name at the end of the string. I ran the command and it does run the migration. However, now I'm running the command to rollback the migration following docs here
$ npx sequelize-cli db:migrate:undo --url 'postgres://postgres:somepassword@some-playground-instance-cluster.some-hash.us-east-1.rds.amazonaws.com/dbname'
and I'm getting the following:
ERROR: Unable to find migration: timestamp-migration-file-name.js
The file does exists in the database and exists in my folder structure since was able to run the migration a minute ago.
UPDATE
Interestingly, I have a command in the package.json
that I want to call with a GitHub action. One version will fail and the other version will succeed.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"migrate": "node-pg-migrate",
"migrate:up": "npx sequelize-cli db:migrate ",
"migrate:undo": "npx sequelize-cli db:migrate:undo "
},
☝🏻 will fail with npm run migrate:up --url <url>
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"migrate": "node-pg-migrate",
"migrate:up": "npx sequelize-cli db:migrate --url ",
"migrate:undo": "npx sequelize-cli db:migrate:undo --url "
},
☝🏻 that will succeed with npm run migrate:up <url>
Any thoughts?
Does npm run migrate:up -- --url <url>
work for the first script?
Yes it does. Not including the flag in package.json
and modifying the command for npm run migrate:up -- --url <url>
does work
I'm creating a PR for updating docs. Against what branch should the PR go.
UPDATE PR create for more clear instructions https://github.com/sequelize/website/pull/186
Note that this is not an issue with sequelize, it's just how npm run
works https://docs.npmjs.com/cli/v8/commands/npm-run-script