Skip to content

Commit 85161c0

Browse files
committed
👷 use migration files as cache key for database cache
1 parent c2013dd commit 85161c0

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@ on:
44
workflow_dispatch:
55
schedule:
66
- cron: 0 14 * * 0
7+
push:
78

89
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
cache_hit: ${{ steps.db_cache.outputs.cache-hit }}
14+
steps:
15+
- uses: actions/checkout@v6
16+
- name: Restore database cache
17+
uses: actions/cache/restore@v5
18+
id: db_cache
19+
with:
20+
path: cache-dump.sql
21+
key: db-${{ runner.os }}-${{ hashFiles('**/migrations/*.py') }}
22+
923
dump:
1024
runs-on: ubuntu-latest
25+
needs: check
26+
if: needs.check.outputs.cache_hit == 'false'
1127
steps:
1228
- uses: actions/checkout@v6
1329
- name: Start database
@@ -24,9 +40,9 @@ jobs:
2440
- name: Run migrations
2541
run: python manage.py migrate --skip-checks # due to django-cms issue
2642
- name: Create database dump
27-
run: docker compose -f compose-dev.yaml exec db pg_dump -U fragdenstaat_de fragdenstaat_de | gzip > dump.gz
43+
run: docker compose -f compose-dev.yaml exec db pg_dump -U fragdenstaat_de fragdenstaat_de > cache-dump.sql
2844
- name: Save dump
2945
uses: actions/cache/save@v5
3046
with:
31-
path: dump.gz
32-
key: ${{ runner.os }}-${{ hashFiles('compose-dev.yaml') }}
47+
path: cache-dump.sql
48+
key: db-${{ runner.os }}-${{ hashFiles('**/migrations/*.py') }}

0 commit comments

Comments
 (0)