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

fix example of install by go toolchain at README #257

Closed

Conversation

stobita
Copy link

@stobita stobita commented Aug 4, 2019

Currently, result of install by go toolchain as follows

> go get -tags 'postgres' -u github.com/golang-migrate/migrate/cmd/migrate
go: finding github.com/golang-migrate/migrate/cmd/migrate latest
go: finding github.com/golang-migrate/migrate/cmd latest
go get github.com/golang-migrate/migrate/cmd/migrate: no matching versions for query "latest"

So, I fixed Installation->With Go toolchain.

@stobita stobita changed the title fix cmd/migrate README go toolchain fix example of install by go toolchain at README Aug 4, 2019
Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to specify the version in the path when installing.

$ docker run -it --rm golang:1.12-alpine
/go # apk add -q git
/go # echo $GOPATH
/go
/go # cd /
/ # go get -tags 'postgres' -u github.com/golang-migrate/migrate/cmd/migrate
/ # migrate
Usage: migrate OPTIONS COMMAND [arg...]
       migrate [ -version | -help ]

Options:
  -source          Location of the migrations (driver://url)
  -path            Shorthand for -source=file://path
  -database        Run migrations against this database (driver://url)
  -prefetch N      Number of migrations to load in advance before executing (default 10)
  -lock-timeout N  Allow N seconds to acquire database lock (default 15)
  -verbose         Print verbose logging
  -version         Print version
  -help            Print usage

Commands:
  create [-ext E] [-dir D] [-seq] [-digits N] [-format] NAME
			   Create a set of timestamped up/down migrations titled NAME, in directory D with extension E.
			   Use -seq option to generate sequential up/down migrations with N digits.
			   Use -format option to specify a Go time format string.
  goto V       Migrate to version V
  up [N]       Apply all or N up migrations
  down [N]     Apply all or N down migrations
  drop         Drop everything inside database
  force V      Set version V but don't run migration (ignores dirty state)
  version      Print current migration version

Source drivers: file
Database drivers: postgresql, stub, postgres
/ #
$

What version of go are you using?

@stobita
Copy link
Author

stobita commented Aug 5, 2019

Thank you for your reply and confirmation.
The version of Golang I am using is 1.12.7.

~ > go version
go version go1.12.7 darwin/amd64
~ > go get -tags 'postgres' -u github.com/golang-migrate/migrate/cmd/migrate
go: finding github.com/golang-migrate/migrate/cmd/migrate latest
go: finding github.com/golang-migrate/migrate/cmd latest
go get github.com/golang-migrate/migrate/cmd/migrate: no matching versions for query "latest"

@dhui
Copy link
Member

dhui commented Aug 7, 2019

Are you running go get in your $GOPATH?

@stobita
Copy link
Author

stobita commented Aug 8, 2019

No. I'm running outside $GOPATH.

@dhui
Copy link
Member

dhui commented Aug 9, 2019

Try running go clean -modcache and then go get -tags 'postgres' -u github.com/golang-migrate/migrate/cmd/migrate

@stobita
Copy link
Author

stobita commented Aug 10, 2019

I ran as you said. But the result was the same.

~ > go clean -modcache
~ > go get -tags 'postgres' -u github.com/golang-migrate/migrate/cmd/migrate
go: finding github.com/golang-migrate/migrate/cmd/migrate latest
go: finding github.com/golang-migrate/migrate/cmd latest
go: finding github.com/golang-migrate/migrate v3.5.4+incompatible
go: downloading github.com/golang-migrate/migrate v3.5.4+incompatible
go: extracting github.com/golang-migrate/migrate v3.5.4+incompatible
go get github.com/golang-migrate/migrate/cmd/migrate: no matching versions for query "latest"

@dhui
Copy link
Member

dhui commented Aug 10, 2019

Weird, based on your the output, it looks like you're pulling migrate v3 instead of migrate v4. I don't think modules are enabled. Try setting GO111MODULE=on.

https://github.com/golang/go/wiki/Modules#how-to-use-modules

@stobita
Copy link
Author

stobita commented Aug 11, 2019

Already GO111MODULE=on was.

~ > echo $GO111MODULE
on
~ > go clean -modcache
~ > go get -tags 'postgres' -u github.com/golang-migrate/migrate/cmd/migrate
go: finding github.com/golang-migrate/migrate/cmd/migrate latest
go: finding github.com/golang-migrate/migrate/cmd latest
go: finding github.com/golang-migrate/migrate v3.5.4+incompatible
go: downloading github.com/golang-migrate/migrate v3.5.4+incompatible
go: extracting github.com/golang-migrate/migrate v3.5.4+incompatible
go get github.com/golang-migrate/migrate/cmd/migrate: no matching versions for query "latest"

@incazteca
Copy link

Can confirm same issue in go 1.12.9. Specifying v4 works

@dhui
Copy link
Member

dhui commented Aug 30, 2019

@incazteca @stobita Can you reproduce the issue in a docker container? That way we're isolating environment differences.

@incazteca
Copy link

@dhui Not really familiar with Dockerfile writing but I think I found a way to reproduce this, will provide a dockerfile later when I have the time. For now I noticed that the issue happens when a go.mod file is present. I've also noticed that when the command does work it downloads the latest version 3

@denisdubovitskiy
Copy link

I've encountered with the same problem.

Here is the workaround:
go get -tags 'postgres' -u github.com/golang-migrate/migrate/v4/cmd/migrate/

Can anyone please update the documentation?

@coveralls
Copy link

Pull Request Test Coverage Report for Build 534

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 51.459%

Totals Coverage Status
Change from base Build 533: 0.0%
Covered Lines: 2346
Relevant Lines: 4559

💛 - Coveralls

1 similar comment
@coveralls
Copy link

Pull Request Test Coverage Report for Build 534

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 51.459%

Totals Coverage Status
Change from base Build 533: 0.0%
Covered Lines: 2346
Relevant Lines: 4559

💛 - Coveralls

@Houndie
Copy link

Houndie commented May 20, 2020

Confirming this is still an issue with go1.14.2

I suggest that, even if we don't want to merge this PR as is because reasons, it would be useful to add the fix in the PR to the documentation as an alternative. Even if we don't understand why this bug is occurring, at this point it's been an issue for a while, and having to dig through issues and pull requests to try and find a solution to a known instillation issue is a bad user experience.

@Matt3o12
Copy link

@dhui If you're still trying to troubleshoot this issue, I created a dockerfile that represents my environment close enough to also cause this failure. Be warned that the docker image it with the dependencies is kind of big (between 500MB-1GB I think).

FROM fedora:32

RUN dnf update -y && dnf install golang git -y

RUN mkdir /golang && mkdir /develop && cd /develop && git clone https://github.com/moul/golang-repo-template.git myrepo

ENV GOPATH=/golang
WORKDIR /develop/myrepo


RUN go build . && ./golang-repo-template
RUN go get -tags 'postgres' -u github.com/golang-migrate/migrate/cmd/migrate

@dhui
Copy link
Member

dhui commented Oct 7, 2020

Thanks for the reproducible Dockerfile @Matt3o12 !

I think I've figured out the issue. It looks like there are issues installing migratefrom within a module. e.g. a project with a go.mod file

This failure might be an issue specific to migrate since we opted into modules without a major version change in v3.5.2 and later opted out in v3.5.3

To work around this issue, you can either:

  1. Change your working directory before running go get so you're not installing within a Go module. e.g. WORKDIR /
  2. Or disable modules before running go get. e.g. ENV GO111MODULE=off
  3. Install using RUN go get -tags 'postgres' -u github.com/golang-migrate/migrate/v4/cmd/migrate

I'll update the README to warn about installing from an existing module.

@dhui dhui closed this Oct 7, 2020
dhui added a commit that referenced this pull request Oct 7, 2020
@dhui
Copy link
Member

dhui commented Feb 19, 2021

Note: in Go 1.16, it seems like go install github.com/golang-migrate/migrate/v4/cmd/migrate@latest is the way to go.

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

Successfully merging this pull request may close these issues.

None yet

7 participants