Skip to content

Commit

Permalink
Improve how golang-migrate is installed and add migration command to …
Browse files Browse the repository at this point in the history
…makefile.
  • Loading branch information
bakar-io committed Mar 20, 2024
1 parent d89ec0b commit a3f429e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ jobs:
- name: Install dependencies
run: |
poetry install --with test
- name: Install go migrate
- name: Install golang-migrate
run: |
curl -s https://packagecloud.io/install/repositories/golang-migrate/migrate/script.deb.sh | sudo bash
sudo apt-get update && sudo apt-get install -y migrate
wget -O golang-migrate.deb https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.linux-amd64.deb
sudo dpkg -i golang-migrate.deb && rm golang-migrate.deb
- name: Run tests
env:
POSTGRES_HOST: localhost
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ RUN yarn build
FROM python:3.11

# Install system dependencies
RUN curl -s https://packagecloud.io/install/repositories/golang-migrate/migrate/script.deb.sh | bash
RUN apt-get update && apt-get install -y migrate libmagic1 && rm -rf /var/lib/apt/lists/*
RUN wget -O golang-migrate.deb https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.linux-amd64.deb \
&& dpkg -i golang-migrate.deb \
&& rm golang-migrate.deb

# Install Poetry
RUN pip install poetry
Expand Down
5 changes: 3 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
FROM python:3.11

# Install system dependencies
RUN curl -s https://packagecloud.io/install/repositories/golang-migrate/migrate/script.deb.sh | bash
RUN apt-get update && apt-get install -y migrate libmagic1 && rm -rf /var/lib/apt/lists/*
RUN wget -O golang-migrate.deb https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.linux-amd64.deb \
&& dpkg -i golang-migrate.deb \
&& rm golang-migrate.deb

# Install Poetry
RUN pip install poetry
Expand Down
3 changes: 3 additions & 0 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ TEST_FILE ?= tests/unit_tests/
start:
poetry run uvicorn app.server:app --reload --port 8100

migrate:
migrate -database postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST):$(POSTGRES_PORT)/$(POSTGRES_DB)?sslmode=disable -path ./migrations up

test:
# We need to update handling of env variables for tests
YDC_API_KEY=placeholder OPENAI_API_KEY=placeholder poetry run pytest $(TEST_FILE)
Expand Down
7 changes: 1 addition & 6 deletions backend/tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ async def _drop_test_db() -> None:


def _migrate_test_db() -> None:
dsn = (
f"postgres://{os.environ['POSTGRES_USER']}:{os.environ['POSTGRES_PASSWORD']}"
f"@{os.environ['POSTGRES_HOST']}:{os.environ['POSTGRES_PORT']}/{TEST_DB}?sslmode=disable"
)
cmd = ["migrate", "-path", "./migrations", "-database", dsn, "up"]
subprocess.run(cmd, check=True)
subprocess.run(["make", "migrate"], check=True)


@pytest.fixture(scope="session")
Expand Down

0 comments on commit a3f429e

Please sign in to comment.