Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/migration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Database migration tests
on:
push:
paths:
- 'db/migrate/**'
pull_request:
paths:
- 'db/migrate/**'

jobs:
migrate:
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
PREV_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}

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: env.PREV_SHA != '0000000000000000000000000000000000000000'
run: |
git fetch origin ${{ env.PREV_SHA }}
git checkout ${{ env.PREV_SHA }} -- db/schema.rb
mv db/migrate db/migrate.bkp
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: env.PREV_SHA != '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
5 changes: 5 additions & 0 deletions db/migrate/20260325133804_good_migration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class GoodMigration < ActiveRecord::Migration[7.2]
def change
add_column :materials, :a_good_field, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20260325133939_bad_migration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class BadMigration < ActiveRecord::Migration[7.2]
def change
raise ':('
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2026_03_10_163512) do
ActiveRecord::Schema[7.2].define(version: 2026_03_25_133939) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -388,6 +388,7 @@
t.string "fields", default: [], array: true
t.boolean "visible", default: true
t.bigint "space_id"
t.string "a_good_field"
t.index ["content_provider_id"], name: "index_materials_on_content_provider_id"
t.index ["slug"], name: "index_materials_on_slug", unique: true
t.index ["space_id"], name: "index_materials_on_space_id"
Expand Down
Loading