Migrate: `migrate` CLI reports `error: no scheme` despite having supplied connection string.

Created on 9 Mar 2018  路  5Comments  路  Source: golang-migrate/migrate

Hi all,

I wasn't sure whether this should go into https://github.com/mattes/migrate or here, but my best guess after seeing https://github.com/mattes/migrate/issues/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:[email protected]: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 https://github.com/golang-migrate/migrate/blob/22f249514de9aa3f8a720a7cabbdd45d294f83a1/util.go#L55 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.

Most helpful comment

@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:[email protected]:5432/redacted?sslmode=disable" -path "./migrations/" up 1 

All 5 comments

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

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

@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:[email protected]: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
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

@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:[email protected]:5432/redacted?sslmode=disable" -path "./migrations/" up 1 
Was this page helpful?
0 / 5 - 0 ratings