Skip to content

Commit 2df7338

Browse files
committed
Add PostgreSQL support and database matrix to CI
Add PostgreSQL gem as a development dependency and configure CI to run tests against both SQLite and PostgreSQL databases. This ensures the database-backed event processing works across both database systems. Changes: - Add PostgreSQL service container to GitHub Actions workflow - Configure database matrix to run tests against sqlite3 and postgresql - Add pg gem to Gemfile and Rails-specific gemfiles - Update test database configuration with PostgreSQL connection details
1 parent 9d02236 commit 2df7338

File tree

8 files changed

+62
-0
lines changed

8 files changed

+62
-0
lines changed

.github/workflows/tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,29 @@ jobs:
66
test:
77
runs-on: ubuntu-latest
88

9+
services:
10+
postgres:
11+
image: postgres:14
12+
env:
13+
POSTGRES_USER: postgres
14+
POSTGRES_PASSWORD: postgres
15+
POSTGRES_DB: journaled_test
16+
ports:
17+
- 5432:5432
18+
options: >-
19+
--health-cmd pg_isready
20+
--health-interval 10s
21+
--health-timeout 5s
22+
--health-retries 5
23+
924
strategy:
1025
fail-fast: false
1126
matrix:
1227
ruby: ['3.2', '3.3', '3.4']
1328
gemfile:
1429
- gemfiles/rails_7_2.gemfile
1530
- gemfiles/rails_8_0.gemfile
31+
database: ['sqlite3', 'postgresql']
1632
steps:
1733
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
1834
- uses: ruby/setup-ruby@e34163cd15f4bb403dcd72d98e295997e6a55798 # v1
@@ -21,7 +37,21 @@ jobs:
2137
with:
2238
ruby-version: ${{ matrix.ruby }}
2339
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
40+
- name: Setup database
41+
if: matrix.database == 'postgresql'
42+
env:
43+
DATABASE_ADAPTER: postgresql
44+
DATABASE_USER: postgres
45+
DATABASE_PASSWORD: postgres
46+
DATABASE_HOST: localhost
47+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
48+
run: |
49+
bundle exec rake db:create db:schema:load
2450
- name: Run tests
2551
env:
2652
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
53+
DATABASE_ADAPTER: ${{ matrix.database }}
54+
DATABASE_USER: postgres
55+
DATABASE_PASSWORD: postgres
56+
DATABASE_HOST: localhost
2757
run: bundle exec rake spec

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ source 'https://rubygems.org'
44

55
gemspec
66

7+
gem 'pg'
78
gem 'sqlite3', '>= 2.1'

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ GEM
119119
parser (3.3.7.0)
120120
ast (~> 2.4.1)
121121
racc
122+
pg (1.6.2-arm64-darwin)
123+
pg (1.6.2-x86_64-linux)
122124
pp (0.6.2)
123125
prettyprint
124126
prettyprint (0.2.0)
@@ -245,6 +247,7 @@ DEPENDENCIES
245247
appraisal
246248
betterlint
247249
journaled!
250+
pg
248251
rspec-rails
249252
rspec_junit_formatter
250253
spring

gemfiles/rails_7_2.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
source "https://rubygems.org"
44

5+
gem "pg"
56
gem "sqlite3", ">= 1.4"
67
gem "railties", "~> 7.2.0"
78

gemfiles/rails_7_2.gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ GEM
119119
parser (3.3.7.0)
120120
ast (~> 2.4.1)
121121
racc
122+
pg (1.6.2-arm64-darwin)
123+
pg (1.6.2-x86_64-linux)
122124
pp (0.6.2)
123125
prettyprint
124126
prettyprint (0.2.0)
@@ -244,6 +246,7 @@ DEPENDENCIES
244246
appraisal
245247
betterlint
246248
journaled!
249+
pg
247250
railties (~> 7.2.0)
248251
rspec-rails
249252
rspec_junit_formatter

gemfiles/rails_8_0.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
source "https://rubygems.org"
44

5+
gem "pg"
56
gem "sqlite3", ">= 2.1"
67
gem "railties", "~> 8.0.0"
78

gemfiles/rails_8_0.gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ GEM
119119
parser (3.3.7.0)
120120
ast (~> 2.4.1)
121121
racc
122+
pg (1.6.2-arm64-darwin)
123+
pg (1.6.2-x86_64-linux)
122124
pp (0.6.2)
123125
prettyprint
124126
prettyprint (0.2.0)
@@ -245,6 +247,7 @@ DEPENDENCIES
245247
appraisal
246248
betterlint
247249
journaled!
250+
pg
248251
railties (~> 8.0.0)
249252
rspec-rails
250253
rspec_junit_formatter

spec/dummy/config/database.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
<% if ENV['DATABASE_ADAPTER'] == 'postgresql' %>
2+
test:
3+
adapter: postgresql
4+
encoding: unicode
5+
database: journaled_test
6+
username: <%= ENV['DATABASE_USER'] || 'postgres' %>
7+
password: <%= ENV['DATABASE_PASSWORD'] || 'postgres' %>
8+
host: <%= ENV['DATABASE_HOST'] || 'localhost' %>
9+
port: <%= ENV['DATABASE_PORT'] || 5432 %>
10+
11+
development:
12+
adapter: postgresql
13+
encoding: unicode
14+
database: journaled_development
15+
username: <%= ENV['DATABASE_USER'] || 'postgres' %>
16+
password: <%= ENV['DATABASE_PASSWORD'] || 'postgres' %>
17+
host: <%= ENV['DATABASE_HOST'] || 'localhost' %>
18+
port: <%= ENV['DATABASE_PORT'] || 5432 %>
19+
<% else %>
120
development:
221
adapter: sqlite3
322
database: ":memory:"
423
test:
524
adapter: sqlite3
625
database: ":memory:"
26+
<% end %>

0 commit comments

Comments
 (0)