當我為數據庫遷移構建自動化腳本時,我遇到了一個非常奇怪的問題。我按照官方文檔:預/后編譯鉤子如果文件 bin/go-pre-compile 或 bin/go-post-compile 存在并且可執行,那么它將在 repo 編譯之前(go-pre-compile)或編譯之后(go-post-compile)執行)。因為 buildpack 將編譯后的可執行文件安裝到 bin 中,所以 go-post-compile 鉤子可以在 go 中編寫,如果它是由指定的(見上文)安裝的。然后我制作了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 hookremote: app_uri: remote: database_url: ?sslmode=requireremote: panic: runtime error: invalid memory address or nil pointer dereferenceremote: [signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x503b06]remote: go-post-compile似乎該進程在運行腳本時無法獲取環境變量。在 buildpack 編譯應用程序后,該過程與 config vars 配合得很好。那么你有什么想法嗎?
1 回答

慕碼人2483693
TA貢獻1860條經驗 獲得超9個贊
經過一番研究,我找到了運行數據庫遷移自動化的解決方案。release phase
開發人員應該在 Heroku中運行這些類型的命令。可以查看官方文檔:https ://devcenter.heroku.com/articles/release-phase
- 1 回答
- 0 關注
- 170 瀏覽
添加回答
舉報
0/150
提交
取消