Skip to content

Commit f0cb021

Browse files
nganclaude
andcommitted
Add Postgres + MySQL CI matrix
Adds a test_db job covering rails_8.1 against postgresql and mysql2 with service containers, plus the infrastructure to make the dummy app's adapter configurable via FIXTURE_KIT_DB. - Bundler groups for pg and mysql2; appraisal lockfiles regenerated - spec/dummy/config/database.yml is ENV-driven (FIXTURE_KIT_DB and friends), defaults stay sqlite - ensure_test_databases_exist! creates the PG/MySQL databases on first run via a separate connection class so the main ActiveRecord::Base connection is established cleanly later - drop_table calls use force: :cascade to handle PG's FK dependencies - spec/dummy gets its own bundle install in CI with BUNDLE_GEMFILE unset (the parent matrix's gemfile path doesn't resolve from inside spec/dummy) - ActiveRecordCoder coverage tests the upsert_all path via a helper that omits :unique_by on MySQL/Trilogy (those adapters reject it) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 31a423a commit f0cb021

12 files changed

Lines changed: 284 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,68 @@ jobs:
3434
- name: Run tests
3535
run: bundle exec rspec
3636

37+
test_db:
38+
runs-on: ubuntu-latest
39+
name: test (${{ matrix.appraisal }}, ${{ matrix.database }})
40+
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
ruby: ["4.0"]
45+
appraisal: ["rails_8.1"]
46+
database: ["postgresql", "mysql2"]
47+
48+
services:
49+
postgres:
50+
image: postgres:16
51+
env:
52+
POSTGRES_USER: postgres
53+
POSTGRES_PASSWORD: postgres
54+
ports:
55+
- 5432:5432
56+
options: >-
57+
--health-cmd pg_isready
58+
--health-interval 10s
59+
--health-timeout 5s
60+
--health-retries 5
61+
mysql:
62+
image: mysql:8
63+
env:
64+
MYSQL_ROOT_PASSWORD: root
65+
ports:
66+
- 3306:3306
67+
options: >-
68+
--health-cmd "mysqladmin ping -h localhost"
69+
--health-interval 10s
70+
--health-timeout 5s
71+
--health-retries 5
72+
73+
env:
74+
BUNDLE_GEMFILE: gemfiles/${{ matrix.appraisal }}.gemfile
75+
FIXTURE_KIT_INTEGRATION_FRAMEWORK: rspec
76+
FIXTURE_KIT_DB: ${{ matrix.database }}
77+
FIXTURE_KIT_DB_HOST: ${{ matrix.database == 'mysql2' && '127.0.0.1' || 'localhost' }}
78+
FIXTURE_KIT_DB_USERNAME: ${{ matrix.database == 'mysql2' && 'root' || 'postgres' }}
79+
FIXTURE_KIT_DB_PASSWORD: ${{ matrix.database == 'mysql2' && 'root' || 'postgres' }}
80+
81+
steps:
82+
- uses: actions/checkout@v4
83+
84+
- name: Set up Ruby ${{ matrix.ruby }}
85+
uses: ruby/setup-ruby@v1
86+
with:
87+
ruby-version: ${{ matrix.ruby }}
88+
bundler-cache: true
89+
90+
- name: Install dummy app dependencies
91+
working-directory: spec/dummy
92+
env:
93+
BUNDLE_GEMFILE: ""
94+
run: bundle install
95+
96+
- name: Run tests
97+
run: bundle exec rspec
98+
3799
lint:
38100
runs-on: ubuntu-latest
39101

Appraisals

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@ appraise "rails-8.0" do
22
gem "activesupport", "~> 8.0.0"
33
gem "activerecord", "~> 8.0.0"
44
gem "railties", "~> 8.0.0"
5+
6+
group :postgres do
7+
gem "pg"
8+
end
9+
10+
group :mysql do
11+
gem "mysql2"
12+
end
513
end
614

715
appraise "rails-8.1" do
816
gem "activesupport", "~> 8.1.0"
917
gem "activerecord", "~> 8.1.0"
1018
gem "railties", "~> 8.1.0"
19+
20+
group :postgres do
21+
gem "pg"
22+
end
23+
24+
group :mysql do
25+
gem "mysql2"
26+
end
1127
end

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
source "https://rubygems.org"
44

55
gemspec
6+
7+
group :postgres do
8+
gem "pg"
9+
end
10+
11+
group :mysql do
12+
gem "mysql2"
13+
end

gemfiles/rails_8.0.gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ gem "activesupport", "~> 8.0.0"
66
gem "activerecord", "~> 8.0.0"
77
gem "railties", "~> 8.0.0"
88

9+
group :postgres do
10+
gem "pg"
11+
end
12+
13+
group :mysql do
14+
gem "mysql2"
15+
end
16+
917
gemspec path: "../"

gemfiles/rails_8.0.gemfile.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ GEM
7474
nokogiri (>= 1.12.0)
7575
minitest (6.0.1)
7676
prism (~> 1.5)
77+
mysql2 (0.5.7)
78+
bigdecimal
7779
nokogiri (1.19.1-aarch64-linux-gnu)
7880
racc (~> 1.4)
7981
nokogiri (1.19.1-aarch64-linux-musl)
@@ -90,6 +92,13 @@ GEM
9092
racc (~> 1.4)
9193
nokogiri (1.19.1-x86_64-linux-musl)
9294
racc (~> 1.4)
95+
pg (1.6.3)
96+
pg (1.6.3-aarch64-linux)
97+
pg (1.6.3-aarch64-linux-musl)
98+
pg (1.6.3-arm64-darwin)
99+
pg (1.6.3-x86_64-darwin)
100+
pg (1.6.3-x86_64-linux)
101+
pg (1.6.3-x86_64-linux-musl)
93102
pp (0.6.3)
94103
prettyprint
95104
prettyprint (0.2.0)
@@ -181,6 +190,8 @@ DEPENDENCIES
181190
appraisal
182191
fixture_kit!
183192
irb
193+
mysql2
194+
pg
184195
railties (~> 8.0.0)
185196
rake
186197
rspec-rails
@@ -212,6 +223,7 @@ CHECKSUMS
212223
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
213224
loofah (2.25.0) sha256=df5ed7ac3bac6a4ec802df3877ee5cc86d027299f8952e6243b3dac446b060e6
214225
minitest (6.0.1) sha256=7854c74f48e2e975969062833adc4013f249a4b212f5e7b9d5c040bf838d54bb
226+
mysql2 (0.5.7) sha256=ba09ede515a0ae8a7192040a1b778c0fb0f025fa5877e9be895cd325fa5e9d7b
215227
nokogiri (1.19.1-aarch64-linux-gnu) sha256=cfdb0eafd9a554a88f12ebcc688d2b9005f9fce42b00b970e3dc199587b27f32
216228
nokogiri (1.19.1-aarch64-linux-musl) sha256=1e2150ab43c3b373aba76cd1190af7b9e92103564063e48c474f7600923620b5
217229
nokogiri (1.19.1-arm-linux-gnu) sha256=0a39ed59abe3bf279fab9dd4c6db6fe8af01af0608f6e1f08b8ffa4e5d407fa3
@@ -220,6 +232,13 @@ CHECKSUMS
220232
nokogiri (1.19.1-x86_64-darwin) sha256=7093896778cc03efb74b85f915a775862730e887f2e58d6921e3fa3d981e68bf
221233
nokogiri (1.19.1-x86_64-linux-gnu) sha256=1a4902842a186b4f901078e692d12257678e6133858d0566152fe29cdb98456a
222234
nokogiri (1.19.1-x86_64-linux-musl) sha256=4267f38ad4fc7e52a2e7ee28ed494e8f9d8eb4f4b3320901d55981c7b995fc23
235+
pg (1.6.3) sha256=1388d0563e13d2758c1089e35e973a3249e955c659592d10e5b77c468f628a99
236+
pg (1.6.3-aarch64-linux) sha256=0698ad563e02383c27510b76bf7d4cd2de19cd1d16a5013f375dd473e4be72ea
237+
pg (1.6.3-aarch64-linux-musl) sha256=06a75f4ea04b05140146f2a10550b8e0d9f006a79cdaf8b5b130cde40e3ecc2c
238+
pg (1.6.3-arm64-darwin) sha256=7240330b572e6355d7c75a7de535edb5dfcbd6295d9c7777df4d9dddfb8c0e5f
239+
pg (1.6.3-x86_64-darwin) sha256=ee2e04a17c0627225054ffeb43e31a95be9d7e93abda2737ea3ce4a62f2729d6
240+
pg (1.6.3-x86_64-linux) sha256=5d9e188c8f7a0295d162b7b88a768d8452a899977d44f3274d1946d67920ae8d
241+
pg (1.6.3-x86_64-linux-musl) sha256=9c9c90d98c72f78eb04c0f55e9618fe55d1512128e411035fe229ff427864009
223242
pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
224243
prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
225244
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85

gemfiles/rails_8.1.gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ gem "activesupport", "~> 8.1.0"
66
gem "activerecord", "~> 8.1.0"
77
gem "railties", "~> 8.1.0"
88

9+
group :postgres do
10+
gem "pg"
11+
end
12+
13+
group :mysql do
14+
gem "mysql2"
15+
end
16+
917
gemspec path: "../"

gemfiles/rails_8.1.gemfile.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ GEM
7575
nokogiri (>= 1.12.0)
7676
minitest (6.0.1)
7777
prism (~> 1.5)
78+
mysql2 (0.5.7)
79+
bigdecimal
7880
nokogiri (1.19.1-aarch64-linux-gnu)
7981
racc (~> 1.4)
8082
nokogiri (1.19.1-aarch64-linux-musl)
@@ -91,6 +93,13 @@ GEM
9193
racc (~> 1.4)
9294
nokogiri (1.19.1-x86_64-linux-musl)
9395
racc (~> 1.4)
96+
pg (1.6.3)
97+
pg (1.6.3-aarch64-linux)
98+
pg (1.6.3-aarch64-linux-musl)
99+
pg (1.6.3-arm64-darwin)
100+
pg (1.6.3-x86_64-darwin)
101+
pg (1.6.3-x86_64-linux)
102+
pg (1.6.3-x86_64-linux-musl)
94103
pp (0.6.3)
95104
prettyprint
96105
prettyprint (0.2.0)
@@ -182,6 +191,8 @@ DEPENDENCIES
182191
appraisal
183192
fixture_kit!
184193
irb
194+
mysql2
195+
pg
185196
railties (~> 8.1.0)
186197
rake
187198
rspec-rails
@@ -214,6 +225,7 @@ CHECKSUMS
214225
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
215226
loofah (2.25.0) sha256=df5ed7ac3bac6a4ec802df3877ee5cc86d027299f8952e6243b3dac446b060e6
216227
minitest (6.0.1) sha256=7854c74f48e2e975969062833adc4013f249a4b212f5e7b9d5c040bf838d54bb
228+
mysql2 (0.5.7) sha256=ba09ede515a0ae8a7192040a1b778c0fb0f025fa5877e9be895cd325fa5e9d7b
217229
nokogiri (1.19.1-aarch64-linux-gnu) sha256=cfdb0eafd9a554a88f12ebcc688d2b9005f9fce42b00b970e3dc199587b27f32
218230
nokogiri (1.19.1-aarch64-linux-musl) sha256=1e2150ab43c3b373aba76cd1190af7b9e92103564063e48c474f7600923620b5
219231
nokogiri (1.19.1-arm-linux-gnu) sha256=0a39ed59abe3bf279fab9dd4c6db6fe8af01af0608f6e1f08b8ffa4e5d407fa3
@@ -222,6 +234,13 @@ CHECKSUMS
222234
nokogiri (1.19.1-x86_64-darwin) sha256=7093896778cc03efb74b85f915a775862730e887f2e58d6921e3fa3d981e68bf
223235
nokogiri (1.19.1-x86_64-linux-gnu) sha256=1a4902842a186b4f901078e692d12257678e6133858d0566152fe29cdb98456a
224236
nokogiri (1.19.1-x86_64-linux-musl) sha256=4267f38ad4fc7e52a2e7ee28ed494e8f9d8eb4f4b3320901d55981c7b995fc23
237+
pg (1.6.3) sha256=1388d0563e13d2758c1089e35e973a3249e955c659592d10e5b77c468f628a99
238+
pg (1.6.3-aarch64-linux) sha256=0698ad563e02383c27510b76bf7d4cd2de19cd1d16a5013f375dd473e4be72ea
239+
pg (1.6.3-aarch64-linux-musl) sha256=06a75f4ea04b05140146f2a10550b8e0d9f006a79cdaf8b5b130cde40e3ecc2c
240+
pg (1.6.3-arm64-darwin) sha256=7240330b572e6355d7c75a7de535edb5dfcbd6295d9c7777df4d9dddfb8c0e5f
241+
pg (1.6.3-x86_64-darwin) sha256=ee2e04a17c0627225054ffeb43e31a95be9d7e93abda2737ea3ce4a62f2729d6
242+
pg (1.6.3-x86_64-linux) sha256=5d9e188c8f7a0295d162b7b88a768d8452a899977d44f3274d1946d67920ae8d
243+
pg (1.6.3-x86_64-linux-musl) sha256=9c9c90d98c72f78eb04c0f55e9618fe55d1512128e411035fe229ff427864009
225244
pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
226245
prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
227246
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85

spec/dummy/Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
source "https://rubygems.org"
44

55
gemspec path: "../.."
6+
7+
group :postgres do
8+
gem "pg"
9+
end
10+
11+
group :mysql do
12+
gem "mysql2"
13+
end

spec/dummy/Gemfile.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ GEM
7676
minitest (6.0.2)
7777
drb (~> 2.0)
7878
prism (~> 1.5)
79+
mysql2 (0.5.7)
80+
bigdecimal
7981
nokogiri (1.19.2-aarch64-linux-gnu)
8082
racc (~> 1.4)
8183
nokogiri (1.19.2-aarch64-linux-musl)
@@ -92,6 +94,13 @@ GEM
9294
racc (~> 1.4)
9395
nokogiri (1.19.2-x86_64-linux-musl)
9496
racc (~> 1.4)
97+
pg (1.6.3)
98+
pg (1.6.3-aarch64-linux)
99+
pg (1.6.3-aarch64-linux-musl)
100+
pg (1.6.3-arm64-darwin)
101+
pg (1.6.3-x86_64-darwin)
102+
pg (1.6.3-x86_64-linux)
103+
pg (1.6.3-x86_64-linux-musl)
95104
pp (0.6.3)
96105
prettyprint
97106
prettyprint (0.2.0)
@@ -181,6 +190,8 @@ DEPENDENCIES
181190
appraisal
182191
fixture_kit!
183192
irb
193+
mysql2
194+
pg
184195
railties
185196
rake
186197
rspec-rails
@@ -213,6 +224,7 @@ CHECKSUMS
213224
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
214225
loofah (2.25.1) sha256=d436c73dbd0c1147b16c4a41db097942d217303e1f7728704b37e4df9f6d2e04
215226
minitest (6.0.2) sha256=db6e57956f6ecc6134683b4c87467d6dd792323c7f0eea7b93f66bd284adbc3d
227+
mysql2 (0.5.7) sha256=ba09ede515a0ae8a7192040a1b778c0fb0f025fa5877e9be895cd325fa5e9d7b
216228
nokogiri (1.19.2-aarch64-linux-gnu) sha256=c34d5c8208025587554608e98fd88ab125b29c80f9352b821964e9a5d5cfbd19
217229
nokogiri (1.19.2-aarch64-linux-musl) sha256=7f6b4b0202d507326841a4f790294bf75098aef50c7173443812e3ac5cb06515
218230
nokogiri (1.19.2-arm-linux-gnu) sha256=b7fa1139016f3dc850bda1260988f0d749934a939d04ef2da13bec060d7d5081
@@ -221,6 +233,13 @@ CHECKSUMS
221233
nokogiri (1.19.2-x86_64-darwin) sha256=7d9af11fda72dfaa2961d8c4d5380ca0b51bc389dc5f8d4b859b9644f195e7a4
222234
nokogiri (1.19.2-x86_64-linux-gnu) sha256=fa8feca882b73e871a9845f3817a72e9734c8e974bdc4fbad6e4bc6e8076b94f
223235
nokogiri (1.19.2-x86_64-linux-musl) sha256=93128448e61a9383a30baef041bf1f5817e22f297a1d400521e90294445069a8
236+
pg (1.6.3) sha256=1388d0563e13d2758c1089e35e973a3249e955c659592d10e5b77c468f628a99
237+
pg (1.6.3-aarch64-linux) sha256=0698ad563e02383c27510b76bf7d4cd2de19cd1d16a5013f375dd473e4be72ea
238+
pg (1.6.3-aarch64-linux-musl) sha256=06a75f4ea04b05140146f2a10550b8e0d9f006a79cdaf8b5b130cde40e3ecc2c
239+
pg (1.6.3-arm64-darwin) sha256=7240330b572e6355d7c75a7de535edb5dfcbd6295d9c7777df4d9dddfb8c0e5f
240+
pg (1.6.3-x86_64-darwin) sha256=ee2e04a17c0627225054ffeb43e31a95be9d7e93abda2737ea3ce4a62f2729d6
241+
pg (1.6.3-x86_64-linux) sha256=5d9e188c8f7a0295d162b7b88a768d8452a899977d44f3274d1946d67920ae8d
242+
pg (1.6.3-x86_64-linux-musl) sha256=9c9c90d98c72f78eb04c0f55e9618fe55d1512128e411035fe229ff427864009
224243
pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
225244
prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
226245
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85

spec/dummy/config/database.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,61 @@
1+
<%
2+
adapter = ENV.fetch("FIXTURE_KIT_DB", "sqlite3")
3+
host = ENV.fetch("FIXTURE_KIT_DB_HOST") { adapter == "mysql2" ? "127.0.0.1" : "localhost" }
4+
username = ENV.fetch("FIXTURE_KIT_DB_USERNAME") do
5+
case adapter
6+
when "postgresql" then ENV.fetch("USER", "postgres")
7+
when "mysql2" then "root"
8+
end
9+
end
10+
password = ENV["FIXTURE_KIT_DB_PASSWORD"]
11+
%>
12+
113
test:
214
primary:
15+
<% case adapter
16+
when "postgresql" %>
17+
adapter: postgresql
18+
database: fixture_kit_test_primary
19+
host: <%= host %>
20+
username: <%= username %>
21+
password: <%= password %>
22+
encoding: unicode
23+
pool: 5
24+
<% when "mysql2" %>
25+
adapter: mysql2
26+
database: fixture_kit_test_primary
27+
host: <%= host %>
28+
username: <%= username %>
29+
password: <%= password %>
30+
encoding: utf8mb4
31+
pool: 5
32+
<% else %>
333
adapter: sqlite3
434
database: tmp/primary_test.sqlite3
535
pool: 5
636
timeout: 5000
37+
<% end %>
738
analytics:
39+
<% case adapter
40+
when "postgresql" %>
41+
adapter: postgresql
42+
database: fixture_kit_test_analytics
43+
host: <%= host %>
44+
username: <%= username %>
45+
password: <%= password %>
46+
encoding: unicode
47+
pool: 5
48+
<% when "mysql2" %>
49+
adapter: mysql2
50+
database: fixture_kit_test_analytics
51+
host: <%= host %>
52+
username: <%= username %>
53+
password: <%= password %>
54+
encoding: utf8mb4
55+
pool: 5
56+
<% else %>
857
adapter: sqlite3
958
database: tmp/analytics_test.sqlite3
1059
pool: 5
1160
timeout: 5000
61+
<% end %>

0 commit comments

Comments
 (0)