From 32318359348c2cb9b2ccb564dc69029c3e9c5757 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Wed, 25 Mar 2026 13:37:31 +0000 Subject: [PATCH 1/3] Action to test database migrations --- .github/workflows/migration-test.yml | 84 ++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 .github/workflows/migration-test.yml diff --git a/.github/workflows/migration-test.yml b/.github/workflows/migration-test.yml new file mode 100644 index 000000000..d08885a60 --- /dev/null +++ b/.github/workflows/migration-test.yml @@ -0,0 +1,84 @@ +name: Database migration tests +on: + push: + paths: + - 'db/migrate/**' + pull_request: + paths: + - 'db/migrate/**' + +jobs: + test: + runs-on: ubuntu-latest + env: + DB_HOST: localhost + DB_NAME: tess + DB_USER: tess + DB_PASSWORD: password + SECRET_BASE_KEY: test_key + RAILS_ENV: test + REDIS_TEST_URL: redis://localhost:6379/0 + services: + postgres: + image: postgres + env: + POSTGRES_DB: ${{ env.DB_NAME }} + POSTGRES_USER: ${{ env.DB_USER }} + POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }} + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 6379:6379 + steps: + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install imagemagick + - name: Check out code + uses: actions/checkout@v4 + - name: Install Ruby & gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Configure + run: | + cp test/config/test_tess.yml config/tess.yml + cp config/secrets.github.yml config/secrets.yml + cp config/ingestion.example.yml config/ingestion.yml + - name: Checkout previous schema + # Checks out previous schema.rb and temporarily renames migrations + if: github.event.before != '0000000000000000000000000000000000000000' + run: | + git fetch origin ${{ github.event.before }} + git checkout ${{ github.event.before }} -- db/schema.rb + mv db/migrate db/migrate.bkp + git checkout ${{ github.event.before }} -- db/migrate + - name: Load previous database schema + run: bundle exec rake db:test:prepare + - name: Restore migrations + # Restore the renamed migrations + if: github.event.before != '0000000000000000000000000000000000000000' + run: | + rm -rf db/migrate + mv db/migrate.bkp db/migrate + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: '20.x' + cache: 'yarn' + - name: Install JS dependencies + run: yarn install --frozen-lockfile --non-interactive + - name: Run migrations + run: bundle exec rails db:migrate From 0a8c24fb524858ec90e60430c4e5ddcff2751d16 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Wed, 25 Mar 2026 13:58:55 +0000 Subject: [PATCH 2/3] Rename --- .github/workflows/migration-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/migration-test.yml b/.github/workflows/migration-test.yml index d08885a60..b3ae67dfb 100644 --- a/.github/workflows/migration-test.yml +++ b/.github/workflows/migration-test.yml @@ -8,7 +8,7 @@ on: - 'db/migrate/**' jobs: - test: + migrate: runs-on: ubuntu-latest env: DB_HOST: localhost From c5980a1f25196650be26113c4caed28df3d7e38a Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Wed, 25 Mar 2026 14:52:42 +0000 Subject: [PATCH 3/3] For PRs, get SHA from `base` --- .github/workflows/migration-test.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/migration-test.yml b/.github/workflows/migration-test.yml index b3ae67dfb..b16fec19a 100644 --- a/.github/workflows/migration-test.yml +++ b/.github/workflows/migration-test.yml @@ -18,6 +18,8 @@ jobs: SECRET_BASE_KEY: test_key RAILS_ENV: test REDIS_TEST_URL: redis://localhost:6379/0 + PREV_SHA: ${{ github.event.pull_request.base.sha || github.event.before }} + services: postgres: image: postgres @@ -59,17 +61,17 @@ jobs: cp config/ingestion.example.yml config/ingestion.yml - name: Checkout previous schema # Checks out previous schema.rb and temporarily renames migrations - if: github.event.before != '0000000000000000000000000000000000000000' + if: env.PREV_SHA != '0000000000000000000000000000000000000000' run: | - git fetch origin ${{ github.event.before }} - git checkout ${{ github.event.before }} -- db/schema.rb + git fetch origin ${{ env.PREV_SHA }} + git checkout ${{ env.PREV_SHA }} -- db/schema.rb mv db/migrate db/migrate.bkp - git checkout ${{ github.event.before }} -- db/migrate + git checkout ${{ env.PREV_SHA }} -- db/migrate - name: Load previous database schema run: bundle exec rake db:test:prepare - name: Restore migrations # Restore the renamed migrations - if: github.event.before != '0000000000000000000000000000000000000000' + if: env.PREV_SHA != '0000000000000000000000000000000000000000' run: | rm -rf db/migrate mv db/migrate.bkp db/migrate