Skip to content

Commit e7eb73b

Browse files
committed
🚧 restore db from cache
1 parent 3890052 commit e7eb73b

3 files changed

Lines changed: 28 additions & 12 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ jobs:
2424
python-version: ['3.12', '3.13', '3.14']
2525
steps:
2626
- uses: actions/checkout@v4
27-
- name: Start Elasticsearch
28-
run: docker compose -f compose-dev.yaml up --wait elasticsearch
27+
- name: Start services
28+
run: docker compose -f compose-dev.yaml up --wait
29+
- uses: actions/cache/restore@v5
30+
id: db_cache
31+
with:
32+
path: dump.gz
33+
key: ${{ runner.os }}-${{ hashFiles('compose-dev.yaml') }}
2934
- name: Setup uv
3035
uses: astral-sh/setup-uv@v6
3136
with:
@@ -49,16 +54,10 @@ jobs:
4954
- name: Compile translations
5055
run: |
5156
python manage.py compilemessages -i node_modules -l de
57+
- name: Restore database
58+
if: steps.db_cache.outputs.cache-hit == 'true'
59+
run: ./scripts/restore_cached_db.sh
5260
- name: Run tests
5361
run: |
5462
pytest --durations 0 -v -n auto --cov --cov-report= fragdenstaat_de/
5563
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
56-
services:
57-
postgres:
58-
image: postgis/postgis:16-3.4
59-
env:
60-
POSTGRES_USER: fragdenstaat_de
61-
POSTGRES_PASSWORD: fragdenstaat_de
62-
POSTGRES_DB: fragdenstaat_de
63-
ports:
64-
- 5432:5432

‎.github/workflows/database-cache.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
workflow_dispatch:
55
schedule:
66
- cron: 0 14 * * 0
7-
push:
87

98
jobs:
109
dump:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
CPUS=$(nproc --all)
6+
RESTORE="fds_restore"
7+
DB_USER="fragdenstaat_de"
8+
9+
gunzip dump.gz
10+
11+
docker compose -f compose-dev.yaml exec db createdb -U $DB_USER -O $DB_USER "$RESTORE"
12+
docker compose -f compose-dev.yaml exec -T db psql -U $DB_USER -X "$RESTORE" < dump
13+
14+
for i in $(seq 0 $(($CPUS - 1))); do
15+
DB_NAME="test_${DB_USER}_gw${i}"
16+
echo $DB_NAME
17+
docker compose -f compose-dev.yaml exec db psql -U $DB_USER -c "CREATE DATABASE $DB_NAME WITH TEMPLATE $RESTORE OWNER $DB_USER;"
18+
done

0 commit comments

Comments
 (0)