Skip to content

Commit

Permalink
pg 17 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pawurb committed Oct 8, 2024
1 parent df673ca commit 4d5f287
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 46 deletions.
63 changes: 33 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,52 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby-version: ['3.2', '3.1', '3.0', '2.7', '2.6']
ruby-version: ['3.3', '3.2', '3.1', '3.0', '2.7', '2.6']
steps:
- uses: actions/checkout@v3
- name: Run PostgreSQL 11
- uses: actions/checkout@v4
- name: Run PostgreSQL 12
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=rails-pg-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5432:5432 postgres:11.18-alpine \
-d -p 5432:5432 postgres:12.20-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
- name: Run PostgreSQL 12
- name: Run PostgreSQL 13
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=rails-pg-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5433:5432 postgres:12.13-alpine \
-d -p 5433:5432 postgres:13.16-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
- name: Run PostgreSQL 13
- name: Run PostgreSQL 14
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=rails-pg-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5434:5432 postgres:13.9-alpine \
-d -p 5434:5432 postgres:14.13-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
- name: Run PostgreSQL 14
- name: Run PostgreSQL 15
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=rails-pg-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5435:5432 postgres:14.6-alpine \
-d -p 5435:5432 postgres:15.8-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
- name: Run PostgreSQL 15
sleep 15
- name: Run PostgreSQL 16
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=rails-pg-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5436:5432 postgres:16.4-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
sleep 15
- name: Run PostgreSQL 17
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=rails-pg-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5436:5432 postgres:15.1-alpine \
-d -p 5437:5432 postgres:17.0-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
sleep 15
- name: Set up Ruby ${{ matrix.ruby-version }}
Expand All @@ -64,64 +73,58 @@ jobs:
bundle config set --local path 'vendor/bundle'
bundle install
sleep 10
- name: Run tests for PG 11
- name: Run tests for PG 12
env:
PG_VERSION: 11
PG_VERSION: 12
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
DATABASE_URL: postgresql://postgres:secret@localhost:5432/rails-pg-extras-test
run: |
bundle exec rspec spec/
- name: Run tests for PG 11
- name: Run tests for PG 13
env:
PG_VERSION: 11
PG_VERSION: 13
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
DATABASE_URL: postgresql://postgres:secret@localhost:5432/rails-pg-extras-test
run: |
bundle exec rspec spec/
- name: Run tests for PG 12
- name: Run tests for PG 14
env:
PG_VERSION: 12
PG_VERSION: 14
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
DATABASE_URL: postgresql://postgres:secret@localhost:5433/rails-pg-extras-test
run: |
bundle exec rspec spec/
- name: Run tests for PG 13
- name: Run tests for PG 15
env:
PG_VERSION: 13
PG_VERSION: 15
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
DATABASE_URL: postgresql://postgres:secret@localhost:5434/rails-pg-extras-test
run: |
bundle exec rspec spec/
- name: Run tests for PG 14
- name: Run tests for PG 16
env:
PG_VERSION: 14
PG_VERSION: 16
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
DATABASE_URL: postgresql://postgres:secret@localhost:5435/rails-pg-extras-test
run: |
bundle exec rspec spec/
- name: Run tests for PG 15
- name: Run tests for PG 17
env:
PG_VERSION: 15
PG_VERSION: 17
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
DATABASE_URL: postgresql://postgres:secret@localhost:5436/rails-pg-extras-test
run: |
bundle exec rspec spec/
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ RSpec::Core::RakeTask.new(:spec)

desc "Test all PG versions"
task :test_all do
system("PG_VERSION=11 bundle exec rspec spec/ && PG_VERSION=12 bundle exec rspec spec/ && PG_VERSION=13 bundle exec rspec spec/ && PG_VERSION=14 bundle exec rspec spec/")
system("PG_VERSION=12 bundle exec rspec spec/ && PG_VERSION=13 bundle exec rspec spec/ && PG_VERSION=14 bundle exec rspec spec/ && PG_VERSION=15 bundle exec rspec spec/ && PG_VERSION=16 bundle exec rspec spec/ && PG_VERSION=17 bundle exec rspec spec/")
end
37 changes: 27 additions & 10 deletions docker-compose.yml.sample
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
version: '3'

services:
postgres11:
image: postgres:11.16-alpine
postgres12:
image: postgres:12.20-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5432:5432'
postgres12:
image: postgres:12.11-alpine
postgres13:
image: postgres:13.16-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5433:5432'
postgres13:
image: postgres:13.7-alpine
postgres14:
image: postgres:14.13-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5434:5432'
postgres14:
image: postgres:14.3-alpine
postgres15:
image: postgres:15.8-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5435:5432'
postgres16:
image: postgres:16.4-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5436:5432'
postgres17:
image: postgres:17.0-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: rails-pg-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5437:5432'

3 changes: 3 additions & 0 deletions lib/rails-pg-extras.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module RailsPgExtras
QUERIES = RubyPgExtras::QUERIES
DEFAULT_ARGS = RubyPgExtras::DEFAULT_ARGS
NEW_PG_STAT_STATEMENTS = RubyPgExtras::NEW_PG_STAT_STATEMENTS
PG_STAT_STATEMENTS_17 = RubyPgExtras::PG_STAT_STATEMENTS_17

QUERIES.each do |query_name|
define_singleton_method query_name do |options = {}|
Expand All @@ -33,6 +34,8 @@ def self.run_query(query_name:, in_format:, args: {})
.to_a[0].fetch("installed_version", nil))
if Gem::Version.new(version) < Gem::Version.new(NEW_PG_STAT_STATEMENTS)
query_name = "#{query_name}_legacy".to_sym
elsif Gem::Version.new(version) >= Gem::Version.new(PG_STAT_STATEMENTS_17)
query_name = "#{query_name}_17".to_sym
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_pg_extras/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RailsPgExtras
VERSION = "5.4.0"
VERSION = "5.4.1"
end
1 change: 1 addition & 0 deletions spec/smoke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

it "supports custom RAILS_PG_EXTRAS_DATABASE_URL" do
ENV["RAILS_PG_EXTRAS_DATABASE_URL"] = ENV["DATABASE_URL"]
puts ENV["RAILS_PG_EXTRAS_DATABASE_URL"]

expect do
RailsPgExtras.calls
Expand Down
12 changes: 8 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@

pg_version = ENV["PG_VERSION"]

port = if pg_version == "11"
port = if pg_version == "12"
"5432"
elsif pg_version == "12"
"5433"
elsif pg_version == "13"
"5434"
"5433"
elsif pg_version == "14"
"5434"
elsif pg_version == "15"
"5435"
elsif pg_version == "16"
"5436"
elsif pg_version == "17"
"5437"
else
"5432"
end
Expand Down

0 comments on commit 4d5f287

Please sign in to comment.