使用 .env 文件中的凭据进行 Golang goose 迁移命令

问题描述 投票:0回答:1

我正在使用

Goose
来管理我的
Go
项目迁移。如何从
connection-string
文件中获取
.env

goose -dir <migration-directory> mysql "<user>:<password>@tcp(<host>:<port>)/<database-name>" up
go environment-variables migration
1个回答
0
投票

在我的 .env 文件中,我设置了以下变量:

  • GOOSE_DRIVER
  • GOOSE_DBSTRING

然后我使用以下 shell 脚本:

#! /bin/sh

set -a
. .env
set +a

goose -dir <path to migrations> "$@"

然后我运行它而不是 goose 命令,这样我就不必包含任何配置,例如:

./goose.sh up
© www.soinside.com 2019 - 2024. All rights reserved.