diff --git a/cmd/goose/main.go b/cmd/goose/main.go index 1ec5c0430..6f08df112 100644 --- a/cmd/goose/main.go +++ b/cmd/goose/main.go @@ -16,6 +16,7 @@ import ( "text/tabwriter" "text/template" + "github.com/joho/godotenv" "github.com/pressly/goose/v3" "github.com/pressly/goose/v3/internal/cfg" "github.com/pressly/goose/v3/internal/migrationstats" @@ -36,6 +37,7 @@ var ( sslkey = flags.String("ssl-key", "", "file path to SSL key in pem format (only support on mysql)") noVersioning = flags.Bool("no-versioning", false, "apply migration commands with no versioning, in file order, from directory pointed to") noColor = flags.Bool("no-color", false, "disable color output (NO_COLOR env variable supported)") + envFile = flags.String("env-file", ".env", "file path to a file of environment variables") ) var version string @@ -75,6 +77,9 @@ func main() { os.Exit(1) } + // read the `.env` or whichever file is pointed, skipping any error + godotenv.Load(*envFile) + // The -dir option has not been set, check whether the env variable is set // before defaulting to ".". if *dir == cfg.DefaultMigrationDir && cfg.GOOSEMIGRATIONDIR != "" { diff --git a/go.mod b/go.mod index 931d9a985..b62f76005 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/ClickHouse/clickhouse-go/v2 v2.14.2 github.com/go-sql-driver/mysql v1.7.1 github.com/jackc/pgx/v5 v5.4.3 + github.com/joho/godotenv v1.5.1 github.com/microsoft/go-mssqldb v1.6.0 github.com/ory/dockertest/v3 v3.10.0 github.com/vertica/vertica-sql-go v1.3.3 diff --git a/go.sum b/go.sum index 0c34e9ce7..12247ad13 100644 --- a/go.sum +++ b/go.sum @@ -75,6 +75,8 @@ github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSlj github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=