|
1 | 1 | name: Database |
| 2 | +# These workflows are intended to check that various actions related to the database |
| 3 | +# (such as building, exporting, and importing) work as expected. |
2 | 4 |
|
3 | 5 | on: |
4 | 6 | pull_request: |
@@ -52,27 +54,50 @@ jobs: |
52 | 54 | run: curl -Ss http://localhost:8000/api/v2/pokemon/1/ | grep -q 'bulbasaur' |
53 | 55 | postgres: |
54 | 56 | runs-on: ubuntu-latest |
| 57 | + services: |
| 58 | + postgres: |
| 59 | + image: postgres:16 |
| 60 | + env: |
| 61 | + POSTGRES_USER: pokeapi |
| 62 | + POSTGRES_PASSWORD: pokeapi |
| 63 | + POSTGRES_DB: pokeapi |
| 64 | + options: >- |
| 65 | + --health-cmd pg_isready |
| 66 | + --health-interval 10s |
| 67 | + --health-timeout 5s |
| 68 | + --health-retries 5 |
| 69 | + ports: |
| 70 | + - 5432:5432 |
55 | 71 | steps: |
56 | 72 | - name: Checkout |
57 | 73 | uses: actions/checkout@v5 |
58 | 74 | with: |
59 | 75 | submodules: recursive |
60 | | - - name: Build |
61 | | - run: | |
62 | | - docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d |
63 | | - make docker-migrate |
64 | | - make docker-build-db |
| 76 | + - name: Install uv |
| 77 | + uses: astral-sh/setup-uv@v7 |
| 78 | + - name: Install dependencies |
| 79 | + run: make install |
| 80 | + - name: Run migrations |
| 81 | + run: uv run manage.py migrate --settings=config.local |
| 82 | + - name: Build database |
| 83 | + run: uv run manage.py shell --settings=config.local -c "from data.v2.build import build_all; build_all(); exit()" |
65 | 84 | - name: Dump DB |
66 | | - run: docker compose exec -T -u postgres db sh -c "cd /tmp && pg_dump -h localhost -Fc -U ash -N 'hdb_*' pokeapi > pokeapi.dump" |
67 | | - - name: Copy dump |
68 | | - run: docker compose cp db:/tmp/pokeapi.dump ./ |
69 | | - - name: Down services |
70 | | - run: docker compose -f docker-compose.yml -f docker-compose-dev.yml down -v |
71 | | - - name: Start services |
72 | | - run: docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d |
| 85 | + run: pg_dump -h localhost -U pokeapi -Fc -N 'hdb_*' pokeapi > pokeapi.dump |
| 86 | + env: |
| 87 | + PGPASSWORD: pokeapi |
| 88 | + - name: Drop and recreate database |
| 89 | + run: | |
| 90 | + psql -h localhost -U pokeapi -d postgres -c "DROP DATABASE pokeapi;" |
| 91 | + psql -h localhost -U pokeapi -d postgres -c "CREATE DATABASE pokeapi;" |
| 92 | + env: |
| 93 | + PGPASSWORD: pokeapi |
73 | 94 | - name: Import database |
| 95 | + run: pg_restore -h localhost -U pokeapi -d pokeapi pokeapi.dump |
| 96 | + env: |
| 97 | + PGPASSWORD: pokeapi |
| 98 | + - name: Start server |
74 | 99 | run: | |
75 | | - docker compose cp ./pokeapi.dump db:/tmp/ |
76 | | - docker compose exec -T -u postgres db sh -c "cd /tmp && pg_restore -h localhost -U ash -d pokeapi pokeapi.dump" |
| 100 | + nohup uv run manage.py runserver 0.0.0.0:8000 --settings=config.local & |
| 101 | + sleep 5 |
77 | 102 | - name: Test data |
78 | | - run: curl -Ss http://localhost/api/v2/pokemon/1/ | grep -q 'bulbasaur' |
| 103 | + run: curl -Ss http://localhost:8000/api/v2/pokemon/1/ | grep -q 'bulbasaur' |
0 commit comments