golang-migrate在初始迁移时出现无更改错误。

huangapple go评论79阅读模式
英文:

golang-migrate no change error on initial migration

问题

我正在使用golang-migrate来管理迁移,当在github actions CI上运行测试时,一切似乎都正常工作,但是当在Docker镜像上运行时,我无法使其工作。我一直收到一个no change错误。与数据库的连接已经建立,并且.sql迁移也正常工作。有什么建议可以帮助我调试实际发生了什么?

英文:

I'm using golang-migrate for managing migrations everything seems to work correctly when running tests on github actions CI, but I can't make it work when running on docker image. I just keep getting a no change error. Connection to database is established and .sql migrations work as well. Any suggestions on how could I debug what's actually going on?

func runMigrations(databaseUrl string) {
	m, err := migrate.New(
		"file://migrations/",
		databaseUrl,
	)

	if err != nil {
		log.Fatalf("Error loading migrations: %v", err)
	}

	if err := m.Up(); err != nil {
		log.Printf("Error migrating Up: %v", err)
	}
}

答案1

得分: 4

你可能需要在你的代码中添加一个检查err != migrate.ErrNoChange。在这种情况下,"migrate"是包的名称。

https://github.com/golang-migrate/migrate/issues/100

英文:

Probably you need to add a check err != migrate.ErrNoChange to your code. In this case, "migrate" is the name of the package

https://github.com/golang-migrate/migrate/issues/100

huangapple
  • 本文由 发表于 2021年6月10日 03:28:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/67910574.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定