如何在 golang migrate 中执行迁移,当 SQL 文件位于 GitHub 文件夹中?

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

How to perform migrations in golang migrate when the sql files are located in a github folder?

问题

我正在使用migrate/migrate来执行我的本地Postgres数据库的迁移。

我曾经在本地文件夹中使用迁移文件,并且迁移按预期运行,但我将迁移文件夹移动到GitHub的不同存储库中。

我的GitHub存储库中包含迁移的位置:
https://github.com/guimassoqueto/db-migrations

我在本地的compose.yml文件中定义了数据库和迁移:

  1. version: '3.9'
  2. services:
  3. postgres:
  4. container_name: postgres
  5. image: postgres:alpine
  6. restart: always
  7. networks:
  8. - local
  9. ports:
  10. - "${POSTGRES_PORT}:${POSTGRES_PORT}"
  11. healthcheck:
  12. test: ["CMD-SHELL", "pg_isready -d ${POSTGRES_DB} -U ${POSTGRES_USER}"]
  13. interval: 15s
  14. timeout: 5s
  15. retries: 5
  16. start_period: 30s
  17. environment:
  18. POSTGRES_DB: ${POSTGRES_DB}
  19. POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
  20. POSTGRES_USER: ${POSTGRES_USER}
  21. migrate:
  22. container_name: migrate
  23. image: migrate/migrate
  24. networks:
  25. - local
  26. command: "-source https://github.com/guimassoqueto/db-migrations/blob/main/migrations -database postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable -verbose up"
  27. links:
  28. - postgres
  29. depends_on:
  30. postgres:
  31. condition: service_healthy
  32. networks:
  33. local:
  34. name: local
  35. driver: bridge

我认为我在compose文件中的command键上可能犯了一些错误,但我不确定具体哪里出错了。

英文:

I am using the migrate/migrate to perform migrations of my postgres local database.
I was using the migrations files inside a local folder and the migrations were running as expected, but I moved the migrations folder to a different repository in github.

Github repository where my migrations are located:
https://github.com/guimassoqueto/db-migrations

My local compose.yml file in which I define database and migrations:

  1. version: '3.9'
  2. services:
  3. postgres:
  4. container_name: postgres
  5. image: postgres:alpine
  6. restart: always
  7. networks:
  8. - local
  9. ports:
  10. - "${POSTGRES_PORT}:${POSTGRES_PORT}"
  11. healthcheck:
  12. test: ["CMD-SHELL", "pg_isready -d ${POSTGRES_DB} -U ${POSTGRES_USER}"]
  13. interval: 15s
  14. timeout: 5s
  15. retries: 5
  16. start_period: 30s
  17. environment:
  18. POSTGRES_DB: ${POSTGRES_DB}
  19. POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
  20. POSTGRES_USER: ${POSTGRES_USER}
  21. migrate:
  22. container_name: migrate
  23. image: migrate/migrate
  24. networks:
  25. - local
  26. command: "-source https://github.com/guimassoqueto/db-migrations/blob/main/migrations -database postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable -verbose up"
  27. links:
  28. - postgres
  29. depends_on:
  30. postgres:
  31. condition: service_healthy
  32. networks:
  33. local:
  34. name: local
  35. driver: bridge

I think I am making some mistake at the command key in the compose file, but I have no idea precisely what I am doing wrong.

答案1

得分: 1

答案在文档中,我没有注意:

https://github.com/golang-migrate/migrate/tree/master/source/github

英文:

The answer is in the docs, I didn't pay attention:

https://github.com/golang-migrate/migrate/tree/master/source/github

huangapple
  • 本文由 发表于 2023年7月20日 20:44:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730030.html
匿名

发表评论

匿名网友

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

确定