Skip to content

Commit

Permalink
Add support for Rails 7
Browse files Browse the repository at this point in the history
Co-authored-by: Dino Maric <dino.onex@gmail.com>
  • Loading branch information
rkrage and dixpac committed Apr 22, 2022
1 parent e8c2fb3 commit f24ef58
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 58 deletions.
62 changes: 40 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
shared_config: &shared_config
machine:
image: circleci/classic:edge
image: ubuntu-2004:202201-02

steps:
- checkout
Expand Down Expand Up @@ -47,80 +47,98 @@ shared_config: &shared_config
version: 2
jobs:
build-ruby-2.5.0-pg-10:
build-ruby-2.7-pg-10:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: 2.5.0
CONTAINER_RUBY_VERSION: 2.7
CONTAINER_PG_VERSION: 10
RAILS_VERSIONS: "5.0 5.1 5.2"
RAILS_VERSIONS: "5.2 6.0 6.1 7.0"

build-ruby-2.5.0-pg-11:
build-ruby-2.7-pg-11:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: 2.5.0
CONTAINER_RUBY_VERSION: 2.7
CONTAINER_PG_VERSION: 11
RAILS_VERSIONS: "5.0 5.1 5.2"
RAILS_VERSIONS: "5.2 6.0 6.1 7.0"

build-ruby-2.5.0-pg-12:
build-ruby-2.7-pg-12:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: 2.5.0
CONTAINER_RUBY_VERSION: 2.7
CONTAINER_PG_VERSION: 12
RAILS_VERSIONS: "5.0 5.1 5.2"
RAILS_VERSIONS: "5.2 6.0 6.1 7.0"

build-ruby-2.5.0-pg-13:
build-ruby-2.7-pg-13:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: 2.5.0
CONTAINER_RUBY_VERSION: 2.7
CONTAINER_PG_VERSION: 13
RAILS_VERSIONS: "5.0 5.1 5.2"
RAILS_VERSIONS: "5.2 6.0 6.1 7.0"

build-ruby-2.7-pg-14:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: 2.7
CONTAINER_PG_VERSION: 14
RAILS_VERSIONS: "5.2 6.0 6.1 7.0"
UPLOAD_COVERAGE: true

build-ruby-latest-pg-10:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: latest
CONTAINER_PG_VERSION: 10
RAILS_VERSIONS: "6.0 6.1"
RAILS_VERSIONS: "6.0 6.1 7.0"

build-ruby-latest-pg-11:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: latest
CONTAINER_PG_VERSION: 11
RAILS_VERSIONS: "6.0 6.1"
RAILS_VERSIONS: "6.0 6.1 7.0"

build-ruby-latest-pg-12:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: latest
CONTAINER_PG_VERSION: 12
RAILS_VERSIONS: "6.0 6.1"
RAILS_VERSIONS: "6.0 6.1 7.0"

build-ruby-latest-pg-13:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: latest
CONTAINER_PG_VERSION: 13
RAILS_VERSIONS: "6.0 6.1"
UPLOAD_COVERAGE: true
RAILS_VERSIONS: "6.0 6.1 7.0"

build-ruby-latest-pg-14:
<<: *shared_config

environment:
CONTAINER_RUBY_VERSION: latest
CONTAINER_PG_VERSION: 14
RAILS_VERSIONS: "6.0 6.1 7.0"

workflows:
version: 2
build_matrix:
jobs:
- build-ruby-2.5.0-pg-10
- build-ruby-2.5.0-pg-11
- build-ruby-2.5.0-pg-12
- build-ruby-2.5.0-pg-13
- build-ruby-2.7-pg-10
- build-ruby-2.7-pg-11
- build-ruby-2.7-pg-12
- build-ruby-2.7-pg-13
- build-ruby-2.7-pg-14
- build-ruby-latest-pg-10
- build-ruby-latest-pg-11
- build-ruby-latest-pg-12
- build-ruby-latest-pg-13
- build-ruby-latest-pg-14
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.yardoc
/Gemfile.lock
/gemfiles/*.lock
/gemfiles/bin
/_yardoc/
/coverage/
/doc/
Expand Down
13 changes: 5 additions & 8 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# frozen_string_literal: true

appraise "ar-5.0" do
gem "activerecord", "~> 5.0.0"
end

appraise "ar-5.1" do
gem "activerecord", "~> 5.1.0"
end

appraise "ar-5.2" do
gem "activerecord", "~> 5.2.0"
end
Expand All @@ -20,3 +12,8 @@ appraise "ar-6.1" do
gem "activerecord", "~> 6.1.0"
gem "pg", "~> 1.1"
end

appraise "ar-7.0" do
gem "activerecord", "~> 7.0.0"
gem "pg", "~> 1.1"
end
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ FROM ruby:$CONTAINER_RUBY_VERSION
ARG CONTAINER_PG_VERSION

RUN export DEBIAN_CODENAME=$(cat /etc/os-release | grep "VERSION=" | cut -d "(" -f2 | cut -d ")" -f1) && \
sed "/jessie-updates/s/^/# /" -i /etc/apt/sources.list && \
echo "deb http://apt.postgresql.org/pub/repos/apt/ $DEBIAN_CODENAME-pgdg main $CONTAINER_PG_VERSION" >> /etc/apt/sources.list.d/pgdg.list && \
echo "deb http://apt.postgresql.org/pub/repos/apt/ $DEBIAN_CODENAME-pgdg main" >> /etc/apt/sources.list.d/pgdg.list && \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
apt-get update && \
apt-get install -y --fix-missing --no-install-recommends \
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "activerecord", "~> 5.0.0"
gem "activerecord", "~> 5.2.0"
gem "pg", "~> 0.21.0"

gemspec
8 changes: 0 additions & 8 deletions gemfiles/ar_5.1.gemfile

This file was deleted.

4 changes: 2 additions & 2 deletions gemfiles/ar_5.0.gemfile → gemfiles/ar_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "activerecord", "~> 5.0.0"
gem "pg", "~> 0.21.0"
gem "activerecord", "~> 7.0.0"
gem "pg", "~> 1.1"

gemspec path: "../"
12 changes: 4 additions & 8 deletions lib/pg_party/model_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def partition_key_eq(value)
if complex_partition_key
complex_partition_key_query("(#{partition_key}) = (?)", value)
else
where_partition_key(:eq, value)
where(partition_key_arel(:eq, value))
end
end

Expand All @@ -48,9 +48,7 @@ def range_partition_key_in(start_range, end_range)
end_range
)
else
where_partition_key(:gteq, start_range).merge(
where_partition_key(:lt, end_range)
)
where(partition_key_arel(:gteq, start_range).and(partition_key_arel(:lt, end_range)))
end
end

Expand Down Expand Up @@ -146,15 +144,15 @@ def complex_partition_key_query(clause, *interpolated_values)
from(subquery, current_alias)
end

def where_partition_key(meth, values)
def partition_key_arel(meth, values)
partition_key_array = Array.wrap(partition_key)
values = Array.wrap(values)

if partition_key_array.size != values.size
raise "number of provided values does not match the number of partition key columns"
end

arel_query = partition_key_array.zip(values).inject(nil) do |obj, (column, value)|
partition_key_array.zip(values).inject(nil) do |obj, (column, value)|
node = current_arel_table[column].send(meth, value)

if obj.nil?
Expand All @@ -163,8 +161,6 @@ def where_partition_key(meth, values)
obj.and(node)
end
end

where(arel_query)
end
end
end
2 changes: 1 addition & 1 deletion lib/pg_party/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module PgParty
VERSION = "1.5.0"
VERSION = "1.6.0"
end
7 changes: 4 additions & 3 deletions pg_party.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/rkrage/pg_party"
spec.license = "MIT"

spec.required_ruby_version = ">= 2.5.0"
spec.required_ruby_version = ">= 2.7.0"

spec.files = Dir["LICENSE.txt", "README.md", "lib/**/*"]

spec.require_paths = ["lib"]

spec.add_runtime_dependency "activerecord", ">= 5.0", "< 6.2"
spec.add_runtime_dependency "activerecord", ">= 5.2", "< 7.1"
spec.add_runtime_dependency "ruby2_keywords", "~> 0.0.2"
spec.add_runtime_dependency "parallel", "~> 1.0"

Expand All @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec-its", "~> 1.3"
spec.add_development_dependency "rspec-rails", "~> 3.8"
spec.add_development_dependency "rspec_junit_formatter", "~> 0.4"
spec.add_development_dependency "simplecov", "~> 0.17.0" # https://github.com/codeclimate/test-reporter/issues/413
spec.add_development_dependency "simplecov", "~> 0.21"
spec.add_development_dependency "timecop", "~> 0.9"
spec.add_development_dependency "psych", "~> 3.3" # psych 4 ships with ruby 3.1 and breaks a lot of things
end
7 changes: 7 additions & 0 deletions spec/integration/model/uuid_string_range_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@
it { is_expected.to contain_exactly(record_one, record_two, record_three) }
end

context "when excluding records with a lower bound" do
let(:start_range) { "f" }
let(:end_range) { "z" }

it { is_expected.to contain_exactly(record_two, record_three) }
end

context "when chaining methods" do
subject { described_class.partition_key_in(start_range, end_range).where(some_string: "d") }

Expand Down
13 changes: 11 additions & 2 deletions spec/integration/structure_dump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@

RSpec.describe "db:structure:dump" do
subject do
ActiveRecord::Base.schema_format = :sql
Rake::Task["db:structure:dump"].invoke
if Rails.gem_version < Gem::Version.new("6.1")
ActiveRecord::Base.schema_format = :sql
Rake::Task["db:structure:dump"].invoke
elsif Rails.gem_version < Gem::Version.new("7.0")
ActiveRecord::Base.schema_format = :sql
Rake::Task["db:schema:dump"].invoke
else
ActiveRecord.schema_format = :sql
Rake::Task["db:schema:dump"].invoke
end

File.read(File.expand_path("../../dummy/db/structure.sql", __FILE__))
end

Expand Down
8 changes: 7 additions & 1 deletion spec/support/pg_dump_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ def pg_env_string
end

def self.config
@config ||= ActiveRecord::Base.connection_config
@config ||= begin
if Rails.gem_version < Gem::Version.new("6.1")
ActiveRecord::Base.connection_config
else
ActiveRecord::Base.connection_db_config.as_json["configuration_hash"].symbolize_keys!
end
end
end

def config
Expand Down

0 comments on commit f24ef58

Please sign in to comment.