-
Notifications
You must be signed in to change notification settings - Fork 91
42 lines (34 loc) · 1.24 KB
/
rails_schema_check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Rails Schema Check
on:
push:
branches: [main]
paths:
- 'db/migrate/**'
- 'db/schema.rb'
pull_request:
branches: [main]
paths:
- 'db/migrate/**'
- 'db/schema.rb'
jobs:
check-migration-and-schema:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2 # Fetch the last 2 commits to be able to compare with the base branch
- name: Check for migration and schema.rb changes
run: |
#!/bin/bash
set -e
latest_migration_file=$(ls -v db/migrate/*.rb | tail -n 1)
latest_migration_version=$(basename $latest_migration_file | grep -oE '^[0-9]+')
# Get the schema version, without underscores
schema_version=$(grep -oE 'define.version: [0-9_]+' db/schema.rb | cut -d ' ' -f 2 | tr -d _)
if [ "$latest_migration_version" != "$schema_version" ]; then
echo "schema.rb version does not match the latest migration version. Have you forgotten to update the schema.rb?"
echo " SCHEMA VERSION = $schema_version (config/schema.rb)"
echo " LATEST MIGRATION VERSION = $latest_migration_version ($latest_migration_file)"
exit 1
fi