Schema Load vs Migrate
yaml
1# Fast: Load schema directly
2- run: bundle exec rails db:schema:load
3
4# Safe: Run all migrations
5- run: bundle exec rails db:migrateBest Practice
Use schema:load for CI, migrate for production.
Migration Testing
yaml
1jobs:
2 test-migrations:
3 runs-on: ubuntu-latest
4 services:
5 postgres:
6 image: postgres:15
7 # ...
8
9 steps:
10 - uses: actions/checkout@v4
11 with:
12 fetch-depth: 0 # Full history
13
14 - name: Checkout main
15 run: git checkout main
16
17 - name: Setup database
18 run: |
19 bundle install
20 bundle exec rails db:create db:migrate
21
22 - name: Checkout PR branch
23 run: git checkout ${{ github.head_ref }}
24
25 - name: Run new migrations
26 run: |
27 bundle install
28 bundle exec rails db:migrateSeeding Test Data
yaml
1- name: Setup database
2 run: |
3 bundle exec rails db:schema:load
4 bundle exec rails db:seedDatabase Caching
yaml
1- name: Cache database
2 uses: actions/cache@v3
3 with:
4 path: db/test.sqlite3
5 key: db-${{ hashFiles('db/schema.rb') }}