Skip to content

Commit e428350

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

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
name: Create database cache
22

33
on:
4-
workflow_dispatch:
5-
schedule:
6-
- cron: 0 14 * * 0
4+
push:
75

86
jobs:
7+
check:
8+
runs-on: ubuntu-latest
9+
outputs:
10+
cache_hit: ${{ steps.db_cache.outputs.cache-hit }}
11+
steps:
12+
- uses: actions/checkout@v6
13+
- name: Restore database cache
14+
uses: actions/cache/restore@v5
15+
id: db_cache
16+
with:
17+
path: cache-dump.sql
18+
key: db-${{ runner.os }}-${{ hashFiles('fragdenstaat_de/**/migrations/*.py') }}
19+
920
dump:
1021
runs-on: ubuntu-latest
22+
needs: check
23+
if: needs.check.outputs.cache_hit != 'true' # don't use == 'false'!
1124
steps:
1225
- uses: actions/checkout@v6
1326
- name: Start database
@@ -24,9 +37,9 @@ jobs:
2437
- name: Run migrations
2538
run: python manage.py migrate --skip-checks # due to django-cms issue
2639
- name: Create database dump
27-
run: docker compose -f compose-dev.yaml exec db pg_dump -U fragdenstaat_de fragdenstaat_de | gzip > dump.gz
40+
run: docker compose -f compose-dev.yaml exec db pg_dump -U fragdenstaat_de fragdenstaat_de > cache-dump.sql
2841
- name: Save dump
2942
uses: actions/cache/save@v5
3043
with:
31-
path: dump.gz
32-
key: ${{ runner.os }}-${{ hashFiles('compose-dev.yaml') }}
44+
path: cache-dump.sql
45+
key: db-${{ runner.os }}-${{ hashFiles('fragdenstaat_de/**/migrations/*.py') }}

0 commit comments

Comments
 (0)