Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate CLI reports error: no scheme despite having supplied connection string. #9

Closed
mingp opened this issue Mar 8, 2018 · 8 comments

Comments

@mingp
Copy link

mingp commented Mar 8, 2018

Hi all,

I wasn't sure whether this should go into https://github.com/mattes/migrate or here, but my best guess after seeing mattes/migrate#311 this issue was to put it here.

I am experiencing an unexpected error from the migrate CLI while following the documentation.

I built and installed the migrate CLI according to the instructions https://github.com/golang-migrate/migrate/tree/master/cli#with-go-toolchain here. Specifically, I ran the following. (I changed the install directory to ~/bin, but I don't expect that to make a difference.)

go get -u -d github.com/mattes/migrate/cli github.com/lib/pq
go build -tags 'postgres' -o ~/bin/migrate github.com/mattes/migrate/cli

I can successfully run migrate -version. Its output is reproduced below.

$ migrate -version
dev

When I try to run the migrate CLI as below. (Certain values have been redacted for privacy, but the general structure has not changed.)

migrate -database "postgresql://redacted:redacted@127.0.0.1:5432/redacted" version

I get the following error message.

error: no scheme

Just to make sure that I didn't make a syntax error somewhere, I ran an example from the doc verbatim, as below. I got the same error message.

migrate -database postgres://localhost:5432/database up 2

Digging briefly into the source code, it appears from

if len(u.Scheme) == 0 {
here that error: no scheme is errScheme, which is returned when the parsed URL does not contain a proper scheme. This is unexpected to me. I would expect the scheme to be parsed as postgres.

Does anyone here have any ideas as to why this is happening? I am willing to help debug further, if anyone has recommendations as to what to try. I hope someone can provide some insight here.

Thank you all in advance.

@pavel-kalmykov
Copy link

I got this error solved by providing the -path argument pointing to the directory where all the SQL scripts were stored

@pavel-kalmykov
Copy link

Anyway it could be an improvement to have more specific messages about what is missing in order to make a migration

@mingp
Copy link
Author

mingp commented Mar 9, 2018

@paveltrufi

Thank you for the quick response.

I tried your suggestion, to include a -path argument. The command I am now running is as follows. This no longer encounters the error: no scheme error.

migrate -database postgres://redacted:redacted@127.0.0.1:5432/redacted -path ./migrations up 1

In retrospect, that error message was confusing. I will try to look deeper into why it reports that error message for a different underlying error.

Actually, I am still encountering an error, albeit a different one now. The error message is as follows, included here just for completeness. Although, this time, I'm inclined to believe the error message is legitimate, and the underlying issue is that the default Postgres install using Homebrew has no SSL certificate.

error: pq: SSL is not enabled on the server

I am closing this, as I believe it to be resolved. Thank you again for your help.

@mingp mingp closed this as completed Mar 9, 2018
@dhui
Copy link
Member

dhui commented Mar 9, 2018

@mingp
If you install the migrate CLI via the Go toolchain, the version will be "dev". This is because versions are managed using git tags. See: our Makefile
We could start tracking version numbers in the code as well, but that allows for inconsistencies.

If you want the migrate binary to report the correct SemVer, you'll need to download the binaries from the release page or from package cloud

For the ssl issue, try specifying sslmode=disable in your connection string. For more info about the connection string, checkout the pq docs

@mingp
Copy link
Author

mingp commented Mar 9, 2018

@dhui

Thank you for the information. I tried your suggestion, and it worked.

For future reference, in case anyone else comes across this with the same issue, the command I used was as follows.

migrate -database "postgres://redacted:redacted@127.0.0.1:5432/redacted?sslmode=disable" -path "./migrations/" up 1 

@glebarez
Copy link

glebarez commented Feb 2, 2022

Anyway it could be an improvement to have more specific messages about what is missing in order to make a migration

agreed, terrible error strings for such a popular product, I will take my start back

@arkhamvm
Copy link

arkhamvm commented Jul 6, 2022

Just spend over 2 hours with this error, it MUST be more specific

@praneetloke
Copy link

In my case, it was because I was accidentally encoding the entire DB URL instead of just the password as per https://github.com/golang-migrate/migrate#database-urls. 🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants