作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我为数据库迁移构建自动化脚本时,我遇到了一个非常奇怪的问题。我按照官方文档:
Pre/Post Compile Hooks
If the file bin/go-pre-compile or bin/go-post-compile exists and is executable then it will be executed either before compilation (go-pre-compile) of the repo, or after compilation (go-post-compile).
Because the buildpack installs compiled executables to bin, the go-post-compile hook can be written in go if it's installed by the specified (see above).
go-post-compile
下面的脚本:
var (
appURI := os.Getenv("APP_URI")
databaseURL := os.Getenv("DATABASE_URL")
)
func main() {
fmt.Printf("app_uri: %s\n", appURI)
fmt.Printf("database_url: %s\n", databaseURL)
sourcePath := fmt.Sprintf("file://%s/db/migrations", appURI)
m, err := migrate.New(sourcePath, databaseURL)
if err != nil {
logger.Error("Failed to establish the connection of the migration.", err)
}
err = m.Up()
if err != nil && err.Error() == "no change" {
fmt.Println(" > NOTE: There is no change related to the operation of the migration.")
return
} else if err != nil {
logger.Error("Failed to establish the connection of the migration.", err)
}
fmt.Println(" > Done.")
}
当我将代码推送到heroku时,出现以下错误:
remote: -----> Running bin/go-post-compile hook
remote: app_uri:
remote: database_url: ?sslmode=require
remote: panic: runtime error: invalid memory address or nil pointer dereference
remote: [signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x503b06]
remote:
似乎进程在运行
go-post-compile
时无法获取环境变量脚本。
最佳答案
经过一番研究,我找到了运行数据库迁移自动化的解决方案。开发者应该在 release phase
中运行这些类型的命令。在赫罗库。可以查看官方文档:https://devcenter.heroku.com/articles/release-phase
关于database - 如何在 Heroku 中获取 golang-buildpack 的钩子(Hook)脚本中的环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62587937/
我是一名优秀的程序员,十分优秀!