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

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

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文件中定义了数据库和迁移:

version: '3.9'

services:
  postgres:
    container_name: postgres
    image: postgres:alpine
    restart: always
    networks:
      - local
    ports:
      - "${POSTGRES_PORT}:${POSTGRES_PORT}"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d ${POSTGRES_DB} -U ${POSTGRES_USER}"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 30s
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}

  migrate:
    container_name: migrate
    image: migrate/migrate
    networks:
      - local
    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"
    links:
      - postgres
    depends_on:
      postgres:
        condition: service_healthy

networks:
  local:
    name: local
    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:

version: '3.9'

services:
  postgres:
    container_name: postgres
    image: postgres:alpine
    restart: always
    networks:
      - local
    ports:
      - "${POSTGRES_PORT}:${POSTGRES_PORT}"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d ${POSTGRES_DB} -U ${POSTGRES_USER}"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 30s
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}

  migrate:
    container_name: migrate
    image: migrate/migrate
    networks:
      - local
    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"
    links:
      - postgres
    depends_on:
      postgres:
        condition: service_healthy


networks:
  local:
    name: local
    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:

确定