From 4d5f287c2e44c507362245ca6e68fbe479259f0b Mon Sep 17 00:00:00 2001 From: pawurb Date: Tue, 8 Oct 2024 11:08:17 +0200 Subject: [PATCH] pg 17 compatibility --- .github/workflows/ci.yml | 63 ++++++++++++++++++---------------- Rakefile | 2 +- docker-compose.yml.sample | 37 ++++++++++++++------ lib/rails-pg-extras.rb | 3 ++ lib/rails_pg_extras/version.rb | 2 +- spec/smoke_spec.rb | 1 + spec/spec_helper.rb | 12 ++++--- 7 files changed, 74 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1656419..04858c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} @@ -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/ diff --git a/Rakefile b/Rakefile index a48ca54..a0dab5c 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/docker-compose.yml.sample b/docker-compose.yml.sample index 4c198e3..a501454 100644 --- a/docker-compose.yml.sample +++ b/docker-compose.yml.sample @@ -1,8 +1,6 @@ -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 @@ -10,8 +8,8 @@ services: 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 @@ -19,8 +17,8 @@ services: 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 @@ -28,8 +26,8 @@ services: 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 @@ -37,3 +35,22 @@ services: 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' + diff --git a/lib/rails-pg-extras.rb b/lib/rails-pg-extras.rb index 5bfb3ec..eeeb914 100644 --- a/lib/rails-pg-extras.rb +++ b/lib/rails-pg-extras.rb @@ -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 = {}| @@ -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 diff --git a/lib/rails_pg_extras/version.rb b/lib/rails_pg_extras/version.rb index 0854e4c..09a266f 100644 --- a/lib/rails_pg_extras/version.rb +++ b/lib/rails_pg_extras/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RailsPgExtras - VERSION = "5.4.0" + VERSION = "5.4.1" end diff --git a/spec/smoke_spec.rb b/spec/smoke_spec.rb index 48f6940..732ea25 100644 --- a/spec/smoke_spec.rb +++ b/spec/smoke_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c04685a..d83b772 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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