Skip to content

Commit a7e3013

Browse files
committed
Add test for down migrations in schema validation workflow
1 parent f6016ee commit a7e3013

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

.github/workflows/schema-validation.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
DATABASE_URL: postgres://postgres:password@localhost:5432/test_db?sslmode=disable
1616
DBMATE_MIGRATIONS_DIR: ./migrations
1717
DBMATE_SCHEMA_FILE: ./database.sql
18-
18+
1919
services:
2020
postgres:
2121
image: postgres:15
@@ -45,7 +45,7 @@ jobs:
4545
run: |
4646
# Apply migrations, dumps schema
4747
dbmate up
48-
48+
4949
# Check if the schema file has changed
5050
if git diff --exit-code database.sql; then
5151
echo "✅ Schema validation passed - database.sql is in sync with migrations"
@@ -62,3 +62,22 @@ jobs:
6262
echo " git add database.sql && git commit -m 'Update schema'"
6363
exit 1
6464
fi
65+
66+
- name: Test that down migrations work
67+
run: |
68+
# Drop db from previous test
69+
dbmate drop
70+
# Apply migrations
71+
dbmate up
72+
73+
for i in ./migrations/*
74+
do
75+
if test -f "$i"
76+
then
77+
# The command will fail if something is wrong
78+
dbmate down
79+
fi
80+
done;
81+
82+
# Check if migrations can be run again
83+
dbmate up

0 commit comments

Comments
 (0)