Skip to content

Commit b97ba40

Browse files
authored
Merge pull request #1267 from ElixirTeSS/migration-test
Migration test
2 parents 8eb6eca + c5980a1 commit b97ba40

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Database migration tests
2+
on:
3+
push:
4+
paths:
5+
- 'db/migrate/**'
6+
pull_request:
7+
paths:
8+
- 'db/migrate/**'
9+
10+
jobs:
11+
migrate:
12+
runs-on: ubuntu-latest
13+
env:
14+
DB_HOST: localhost
15+
DB_NAME: tess
16+
DB_USER: tess
17+
DB_PASSWORD: password
18+
SECRET_BASE_KEY: test_key
19+
RAILS_ENV: test
20+
REDIS_TEST_URL: redis://localhost:6379/0
21+
PREV_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
22+
23+
services:
24+
postgres:
25+
image: postgres
26+
env:
27+
POSTGRES_DB: ${{ env.DB_NAME }}
28+
POSTGRES_USER: ${{ env.DB_USER }}
29+
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
30+
ports:
31+
- 5432:5432
32+
options: >-
33+
--health-cmd "pg_isready"
34+
--health-interval 10s
35+
--health-timeout 5s
36+
--health-retries 5
37+
redis:
38+
image: redis
39+
options: >-
40+
--health-cmd "redis-cli ping"
41+
--health-interval 10s
42+
--health-timeout 5s
43+
--health-retries 5
44+
ports:
45+
- 6379:6379
46+
steps:
47+
- name: Install system dependencies
48+
run: |
49+
sudo apt-get update
50+
sudo apt-get install imagemagick
51+
- name: Check out code
52+
uses: actions/checkout@v4
53+
- name: Install Ruby & gems
54+
uses: ruby/setup-ruby@v1
55+
with:
56+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
57+
- name: Configure
58+
run: |
59+
cp test/config/test_tess.yml config/tess.yml
60+
cp config/secrets.github.yml config/secrets.yml
61+
cp config/ingestion.example.yml config/ingestion.yml
62+
- name: Checkout previous schema
63+
# Checks out previous schema.rb and temporarily renames migrations
64+
if: env.PREV_SHA != '0000000000000000000000000000000000000000'
65+
run: |
66+
git fetch origin ${{ env.PREV_SHA }}
67+
git checkout ${{ env.PREV_SHA }} -- db/schema.rb
68+
mv db/migrate db/migrate.bkp
69+
git checkout ${{ env.PREV_SHA }} -- db/migrate
70+
- name: Load previous database schema
71+
run: bundle exec rake db:test:prepare
72+
- name: Restore migrations
73+
# Restore the renamed migrations
74+
if: env.PREV_SHA != '0000000000000000000000000000000000000000'
75+
run: |
76+
rm -rf db/migrate
77+
mv db/migrate.bkp db/migrate
78+
- name: Set up Node
79+
uses: actions/setup-node@v4
80+
with:
81+
node-version: '20.x'
82+
cache: 'yarn'
83+
- name: Install JS dependencies
84+
run: yarn install --frozen-lockfile --non-interactive
85+
- name: Run migrations
86+
run: bundle exec rails db:migrate

0 commit comments

Comments
 (0)