-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Using migrate with Go 1.24 "go tool" command #1232
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
Comments
It would be nice to be able to manage all my tool dependencies using the same method. I guess the problem is that |
fwiw, when you use |
I'm not sure this is true... I have it added to my go.mod:
However:
|
With the following makefile commands: migrate-up: ## Run database migrations up (loads .env if present)
@set -o allexport; \
if [ -f .env ]; then source .env; fi; \
go run -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate \
-database "$$DATABASE_URL" \
-path ./internal/database/migrations \
up
migrate-down: ## Rollback the last migration (loads .env if present)
@set -o allexport; \
if [ -f .env ]; then source .env; fi; \
go run -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate \
-database "$$DATABASE_URL" \
-path ./internal/database/migrations \
down 1 Without migrate in my tools directive I get:
With migrate in my tools directive, I get:
I don't have a firm grasp on the nuances of the tool directive, so if this is working in some kind of unexpected way, maybe someone can clarify.
Example repo: https://github.com/bcomnes/go-todo |
@bcomnes I think what you describe is a side-effect. When you have no tools included, do you still have a reference to My guess here is the tool definition is creating it, but since you are explicitly running it based on the |
No, nothing else pulls it in when the tools directive is removed.
It's not quite the desired outcome (using |
I propose adding a new file //go:build !(aws_s3 || bitbucket || cassandra || clickhouse || cockroachdb || firebird || github || gitlab || go_bindata || godoc_vfs || google_cloud_storage || mongodb || mysql || neo4j || pgx || pgx5 || postgres || ql || redshift || rqlite || snowflake || spanner || sqlcipher || sqlite || sqlite3 || sqlserver || yugabytedb)
// +build !aws_s3,!bitbucket,!cassandra,!clickhouse,!cockroachdb,!firebird,!github,!gitlab,!go_bindata,!godoc_vfs,!google_cloud_storage,!mongodb,!mysql,!neo4j,!pgx,!pgx5,!postgres,!ql,!redshift,!rqlite,!snowflake,!spanner,!sqlcipher,!sqlite,!sqlite3,!sqlserver,!yugabytedb
package cli
import (
_ "github.com/ClickHouse/clickhouse-go"
_ "github.com/golang-migrate/migrate/v4/database/cassandra"
_ "github.com/golang-migrate/migrate/v4/database/clickhouse"
_ "github.com/golang-migrate/migrate/v4/database/cockroachdb"
_ "github.com/golang-migrate/migrate/v4/database/firebird"
_ "github.com/golang-migrate/migrate/v4/database/mongodb"
_ "github.com/golang-migrate/migrate/v4/database/mysql"
_ "github.com/golang-migrate/migrate/v4/database/neo4j"
_ "github.com/golang-migrate/migrate/v4/database/pgx"
_ "github.com/golang-migrate/migrate/v4/database/pgx/v5"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/database/ql"
_ "github.com/golang-migrate/migrate/v4/database/redshift"
_ "github.com/golang-migrate/migrate/v4/database/rqlite"
_ "github.com/golang-migrate/migrate/v4/database/snowflake"
_ "github.com/golang-migrate/migrate/v4/database/spanner"
_ "github.com/golang-migrate/migrate/v4/database/sqlcipher"
_ "github.com/golang-migrate/migrate/v4/database/sqlite"
_ "github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/golang-migrate/migrate/v4/database/sqlserver"
_ "github.com/golang-migrate/migrate/v4/database/yugabytedb"
_ "github.com/golang-migrate/migrate/v4/source/aws_s3"
_ "github.com/golang-migrate/migrate/v4/source/bitbucket"
_ "github.com/golang-migrate/migrate/v4/source/github_ee"
_ "github.com/golang-migrate/migrate/v4/source/gitlab"
_ "github.com/golang-migrate/migrate/v4/source/go_bindata"
_ "github.com/golang-migrate/migrate/v4/source/godoc_vfs"
_ "github.com/golang-migrate/migrate/v4/source/google_cloud_storage"
) This setup ensures that all database/source drivers are built by default when running go build without any
$ CGO_ENABLED=0 go run -tags='aws_s3' ./cmd/migrate/
Usage: migrate OPTIONS COMMAND [arg...]
migrate [ -version | -help ]
...
Source drivers: s3, file
Database drivers: stub
exit status 2
$ CGO_ENABLED=0 go run ./cmd/migrate/
Usage: migrate OPTIONS COMMAND [arg...]
migrate [ -version | -help ]
...
Source drivers: go-bindata, github-ee, gitlab, bitbucket, s3, gcs, file, github, godoc-vfs
Database drivers: cockroach, redshift, cockroachdb, yugabytedb, firebird, firebirdsql, mysql, cassandra, rqlite, spanner, mongodb, snowflake, stub, postgresql, yugabyte, clickhouse, sqlite, ysql, neo4j, sqlserver, mongodb+srv, ql, sqlcipher, sqlite3, pgx, postgres, pgx5, crdb-postgres, pgx4
exit status 2 Further validation needed. |
Thanks for the discussion! I'd rather wait for |
Hi @dhui , thx for the response! 🙏 The existing Go community issue golang/go#71503 hasn't seen progress yet 🐢. Hoping to provide a temporary workaround here so other projects can manage tool dependencies in |
I'm trying to use migrate in conjuction with the new
go tool
command (https://tip.golang.org/doc/go1.24#go-command), but not having much luck. I wondered if anyone knows knows a workaround or the right commands to run?I've tried:
But this fails with the following error.
I tried specifying the build tag
postgres
during thego get
, but get the same error.In contrast,
go run
with the build tagpostgres
works as expected:The text was updated successfully, but these errors were encountered: