From 608c29df50ab2222f13ecdfeca3b7bc26525fa84 Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Wed, 14 Aug 2024 13:09:18 -0400 Subject: [PATCH 01/18] Support rails 7.2 (#278) --- .github/workflows/main.yml | 4 +++- Appraisals | 12 ++++++++++++ Rakefile | 6 +++++- gemfiles/rails_7_2.gemfile | 17 +++++++++++++++++ lib/apartment/adapters/abstract_adapter.rb | 2 +- lib/apartment/migrator.rb | 18 +++++++++++++++--- ros-apartment.gemspec | 4 ++-- spec/examples/generic_adapter_examples.rb | 15 +-------------- .../apartment_rake_integration_spec.rb | 12 ++++++++++-- 9 files changed, 66 insertions(+), 24 deletions(-) create mode 100644 gemfiles/rails_7_2.gemfile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0057e434..feabdc00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,6 @@ jobs: fail-fast: false matrix: ruby_version: - - "3.0" - 3.1 - 3.2 - 3.3 @@ -26,10 +25,13 @@ jobs: - 6_1 - 7_0 - 7_1 + - 7_2 # - master # versions failing exclude: - ruby_version: jruby rails_version: 7_1 + - ruby_version: jruby + rails_version: 7_2 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}.gemfile CI: true diff --git a/Appraisals b/Appraisals index a9efbab6..409b47b5 100644 --- a/Appraisals +++ b/Appraisals @@ -36,6 +36,18 @@ appraise 'rails-7-1' do end end +appraise 'rails-7-2' do + gem 'rails', '~> 7.2.0' + platforms :ruby do + gem 'sqlite3', '~> 1.6' + end + platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 70.0' + gem 'activerecord-jdbcpostgresql-adapter', '~> 70.0' + gem 'activerecord-jdbcmysql-adapter', '~> 70.0' + end +end + # Install Rails from the main branch are failing # appraise 'rails-master' do # gem 'rails', git: 'https://github.com/rails/rails.git' diff --git a/Rakefile b/Rakefile index f4318d74..aca38df5 100644 --- a/Rakefile +++ b/Rakefile @@ -135,5 +135,9 @@ end def migrate # TODO: Figure out if there is any other possibility that can/should be # passed here as the second argument for the migration context - ActiveRecord::MigrationContext.new('spec/dummy/db/migrate', ActiveRecord::SchemaMigration).migrate + if ActiveRecord.version > "7.1" + ActiveRecord::MigrationContext.new('spec/dummy/db/migrate').migrate + else + ActiveRecord::MigrationContext.new('spec/dummy/db/migrate', ActiveRecord::SchemaMigration).migrate + end end diff --git a/gemfiles/rails_7_2.gemfile b/gemfiles/rails_7_2.gemfile new file mode 100644 index 00000000..4b644dbf --- /dev/null +++ b/gemfiles/rails_7_2.gemfile @@ -0,0 +1,17 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "rails", "~> 7.2.0" + +platforms :ruby do + gem "sqlite3", "~> 1.6" +end + +platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 70.0' + gem "activerecord-jdbcpostgresql-adapter", "~> 70.0" + gem "activerecord-jdbcmysql-adapter", "~> 70.0" +end + +gemspec path: "../" diff --git a/lib/apartment/adapters/abstract_adapter.rb b/lib/apartment/adapters/abstract_adapter.rb index e59ba523..b3cc21d4 100644 --- a/lib/apartment/adapters/abstract_adapter.rb +++ b/lib/apartment/adapters/abstract_adapter.rb @@ -181,7 +181,7 @@ def connect_to_new(tenant) query_cache_enabled = ActiveRecord::Base.connection.query_cache_enabled Apartment.establish_connection multi_tenantify(tenant) - Apartment.connection.active? # call active? to manually check if this connection is valid + Apartment.connection.verify! # call active? to manually check if this connection is valid Apartment.connection.enable_query_cache! if query_cache_enabled rescue *rescuable_exceptions => e diff --git a/lib/apartment/migrator.rb b/lib/apartment/migrator.rb index aff59600..a8c5f435 100644 --- a/lib/apartment/migrator.rb +++ b/lib/apartment/migrator.rb @@ -13,21 +13,33 @@ def migrate(database) migration_scope_block = ->(migration) { ENV['SCOPE'].blank? || (ENV['SCOPE'] == migration.scope) } - ActiveRecord::Base.connection.migration_context.migrate(version, &migration_scope_block) + if ActiveRecord.version >= Gem::Version.new('7.2.0') + ActiveRecord::Base.connection_pool.migration_context.migrate(version, &migration_scope_block) + else + ActiveRecord::Base.connection.migration_context.migrate(version, &migration_scope_block) + end end end # Migrate up/down to a specific version def run(direction, database, version) Tenant.switch(database) do - ActiveRecord::Base.connection.migration_context.run(direction, version) + if ActiveRecord.version >= Gem::Version.new('7.2.0') + ActiveRecord::Base.connection_pool.migration_context.run(direction, version) + else + ActiveRecord::Base.connection.migration_context.run(direction, version) + end end end # rollback latest migration `step` number of times def rollback(database, step = 1) Tenant.switch(database) do - ActiveRecord::Base.connection.migration_context.rollback(step) + if ActiveRecord.version >= Gem::Version.new('7.2.0') + ActiveRecord::Base.connection_pool.migration_context.rollback(step) + else + ActiveRecord::Base.connection.migration_context.rollback(step) + end end end end diff --git a/ros-apartment.gemspec b/ros-apartment.gemspec index 918026da..ee6d6a71 100644 --- a/ros-apartment.gemspec +++ b/ros-apartment.gemspec @@ -30,9 +30,9 @@ Gem::Specification.new do |s| 'github_repo' => 'ssh://github.com/rails-on-services/apartment' } - s.required_ruby_version = '>= 3.0', '< 3.4' + s.required_ruby_version = '>= 3.1', '<= 3.4' - s.add_dependency 'activerecord', '>= 6.1.0', '< 7.2' + s.add_dependency 'activerecord', '>= 6.1.0', '<= 8.1' s.add_dependency 'parallel', '< 2.0' s.add_dependency 'public_suffix', '>= 2.0.5', '< 6.0' s.add_dependency 'rack', '>= 1.3.6', '< 4.0' diff --git a/spec/examples/generic_adapter_examples.rb b/spec/examples/generic_adapter_examples.rb index 8289b3f9..2f8a3ea0 100644 --- a/spec/examples/generic_adapter_examples.rb +++ b/spec/examples/generic_adapter_examples.rb @@ -12,19 +12,6 @@ end describe '#init' do - it 'should not retain a connection after railtie' do - ActiveRecord::Base.connection_pool.disconnect! - - Apartment::Railtie.config.to_prepare_blocks.map(&:call) - - num_available_connections = Apartment.connection_class.connection_pool - .instance_variable_get(:@available) - .instance_variable_get(:@queue) - .size - - expect(num_available_connections).to eq(1) - end - it 'should not connect if env var is set' do ENV['APARTMENT_DISABLE_INIT'] = 'true' begin @@ -113,7 +100,7 @@ it 'should raise an error if database is invalid' do expect do subject.switch! 'unknown_database' - end.to raise_error(Apartment::ApartmentError) + end.to raise_error(Apartment::TenantNotFound) end end diff --git a/spec/integration/apartment_rake_integration_spec.rb b/spec/integration/apartment_rake_integration_spec.rb index 17eb04e2..530f8146 100644 --- a/spec/integration/apartment_rake_integration_spec.rb +++ b/spec/integration/apartment_rake_integration_spec.rb @@ -52,7 +52,11 @@ describe '#migrate' do it 'should migrate all databases' do - allow(ActiveRecord::Base.connection).to receive(:migration_context) { migration_context_double } + if ActiveRecord.version >= Gem::Version.new('7.2.0') + allow(ActiveRecord::Base.connection_pool) + else + allow(ActiveRecord::Base.connection) + end.to receive(:migration_context) { migration_context_double } expect(migration_context_double).to receive(:migrate).exactly(company_count).times @rake['apartment:migrate'].invoke @@ -61,7 +65,11 @@ describe '#rollback' do it 'should rollback all dbs' do - allow(ActiveRecord::Base.connection).to receive(:migration_context) { migration_context_double } + if ActiveRecord.version >= Gem::Version.new('7.2.0') + allow(ActiveRecord::Base.connection_pool) + else + allow(ActiveRecord::Base.connection) + end.to receive(:migration_context) { migration_context_double } expect(migration_context_double).to receive(:rollback).exactly(company_count).times @rake['apartment:rollback'].invoke From 973828f666eb0febc4f60c850e6b928bbf2eab42 Mon Sep 17 00:00:00 2001 From: Ferdy Date: Wed, 14 Aug 2024 22:39:30 +0530 Subject: [PATCH 02/18] Update .ruby-version (#279) Signed-off-by: Ferdy --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index bea438e9..a0891f56 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.3.1 +3.3.4 From 87247aa9e3ad9c19b1c1a9532c4d712e6078b6ad Mon Sep 17 00:00:00 2001 From: Ryan Wood Date: Wed, 14 Aug 2024 10:11:01 -0700 Subject: [PATCH 03/18] Properly reset sequence if switching with multiple schemas (#203) --- .../active_record/postgresql_adapter.rb | 12 ++++++-- spec/examples/schema_adapter_examples.rb | 30 ++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/apartment/active_record/postgresql_adapter.rb b/lib/apartment/active_record/postgresql_adapter.rb index 3d1d2043..ca0adbcb 100644 --- a/lib/apartment/active_record/postgresql_adapter.rb +++ b/lib/apartment/active_record/postgresql_adapter.rb @@ -12,12 +12,13 @@ def default_sequence_name(table, _column) # for JDBC driver, if rescued in super_method, trim leading and trailing quotes res.delete!('"') if defined?(JRUBY_VERSION) - schema_prefix = "#{Apartment::Tenant.current}." - default_tenant_prefix = "#{Apartment::Tenant.default_tenant}." + schema_prefix = "#{sequence_schema(res)}." # NOTE: Excluded models should always access the sequence from the default # tenant schema if excluded_model?(table) + default_tenant_prefix = "#{Apartment::Tenant.default_tenant}." + res.sub!(schema_prefix, default_tenant_prefix) if schema_prefix != default_tenant_prefix return res end @@ -29,6 +30,13 @@ def default_sequence_name(table, _column) private + def sequence_schema(sequence_name) + current = Apartment::Tenant.current + return current unless current.is_a?(Array) + + current.find { |schema| sequence_name.starts_with?("#{schema}.") } + end + def excluded_model?(table) Apartment.excluded_models.any? { |m| m.constantize.table_name == table } end diff --git a/spec/examples/schema_adapter_examples.rb b/spec/examples/schema_adapter_examples.rb index aa1a1340..35623cde 100644 --- a/spec/examples/schema_adapter_examples.rb +++ b/spec/examples/schema_adapter_examples.rb @@ -130,6 +130,10 @@ it 'connects and resets' do subject.switch(schema1) do + # Ensure sequence is not cached + Company.reset_sequence_name + User.reset_sequence_name + expect(connection.schema_search_path).to start_with %("#{schema1}") expect(User.sequence_name).to eq "#{User.table_name}_id_seq" expect(Company.sequence_name).to eq "#{public_schema}.#{Company.table_name}_id_seq" @@ -140,10 +144,28 @@ expect(Company.sequence_name).to eq "#{public_schema}.#{Company.table_name}_id_seq" end - it 'allows a list of schemas' do - subject.switch([schema1, schema2]) do - expect(connection.schema_search_path).to include %("#{schema1}") - expect(connection.schema_search_path).to include %("#{schema2}") + describe 'multiple schemas' do + it 'allows a list of schemas' do + subject.switch([schema1, schema2]) do + expect(connection.schema_search_path).to include %("#{schema1}") + expect(connection.schema_search_path).to include %("#{schema2}") + end + end + + it 'connects and resets' do + subject.switch([schema1, schema2]) do + # Ensure sequence is not cached + Company.reset_sequence_name + User.reset_sequence_name + + expect(connection.schema_search_path).to start_with %("#{schema1}") + expect(User.sequence_name).to eq "#{User.table_name}_id_seq" + expect(Company.sequence_name).to eq "#{public_schema}.#{Company.table_name}_id_seq" + end + + expect(connection.schema_search_path).to start_with %("#{public_schema}") + expect(User.sequence_name).to eq "#{User.table_name}_id_seq" + expect(Company.sequence_name).to eq "#{public_schema}.#{Company.table_name}_id_seq" end end end From 81ae1f1bb791456d248f10e693e453383c0663d5 Mon Sep 17 00:00:00 2001 From: Marvin Tangpos Date: Wed, 21 Aug 2024 02:40:13 +0800 Subject: [PATCH 04/18] Support public_suffix major version 6 (#281) --- ros-apartment.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros-apartment.gemspec b/ros-apartment.gemspec index ee6d6a71..1cf73614 100644 --- a/ros-apartment.gemspec +++ b/ros-apartment.gemspec @@ -34,7 +34,7 @@ Gem::Specification.new do |s| s.add_dependency 'activerecord', '>= 6.1.0', '<= 8.1' s.add_dependency 'parallel', '< 2.0' - s.add_dependency 'public_suffix', '>= 2.0.5', '< 6.0' + s.add_dependency 'public_suffix', '>= 2.0.5', '<= 6.0.1' s.add_dependency 'rack', '>= 1.3.6', '< 4.0' s.add_development_dependency 'appraisal', '~> 2.2' From 44ee01b86d5764c702c05b6b0eb3abf76607d15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Zieli=C5=84ski?= Date: Fri, 27 Sep 2024 16:55:47 +0200 Subject: [PATCH 05/18] squash (#287) --- Rakefile | 2 +- lib/apartment.rb | 3 ++- lib/apartment/deprecation.rb | 6 +----- ros-apartment.gemspec | 1 + 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index aca38df5..b4c66d5e 100644 --- a/Rakefile +++ b/Rakefile @@ -135,7 +135,7 @@ end def migrate # TODO: Figure out if there is any other possibility that can/should be # passed here as the second argument for the migration context - if ActiveRecord.version > "7.1" + if ActiveRecord.version > '7.1' ActiveRecord::MigrationContext.new('spec/dummy/db/migrate').migrate else ActiveRecord::MigrationContext.new('spec/dummy/db/migrate', ActiveRecord::SchemaMigration).migrate diff --git a/lib/apartment.rb b/lib/apartment.rb index 0bf253f1..e35fda4a 100644 --- a/lib/apartment.rb +++ b/lib/apartment.rb @@ -5,6 +5,7 @@ require 'forwardable' require 'active_record' require 'apartment/tenant' +require 'apartment/deprecation' require_relative 'apartment/log_subscriber' require_relative 'apartment/active_record/connection_handling' @@ -47,7 +48,7 @@ def tenants_with_config end def tld_length=(_) - Apartment::Deprecation.warn('`config.tld_length` have no effect because it was removed in https://github.com/influitive/apartment/pull/309') + Apartment::DEPRECATOR.warn('`config.tld_length` have no effect because it was removed in https://github.com/influitive/apartment/pull/309') end def db_config_for(tenant) diff --git a/lib/apartment/deprecation.rb b/lib/apartment/deprecation.rb index db73dd5d..d12864a5 100644 --- a/lib/apartment/deprecation.rb +++ b/lib/apartment/deprecation.rb @@ -3,9 +3,5 @@ require 'active_support/deprecation' module Apartment - module Deprecation - def self.warn(message) - ActiveSupport::Deprecation.warn message - end - end + DEPRECATOR = ActiveSupport::Deprecation.new(Apartment::VERSION, 'Apartment') end diff --git a/ros-apartment.gemspec b/ros-apartment.gemspec index 1cf73614..f413e49e 100644 --- a/ros-apartment.gemspec +++ b/ros-apartment.gemspec @@ -33,6 +33,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 3.1', '<= 3.4' s.add_dependency 'activerecord', '>= 6.1.0', '<= 8.1' + s.add_dependency 'activesupport', '>= 6.1.0' s.add_dependency 'parallel', '< 2.0' s.add_dependency 'public_suffix', '>= 2.0.5', '<= 6.0.1' s.add_dependency 'rack', '>= 1.3.6', '< 4.0' From 0c0faf1c796d89108c76856903df5c30fcd2fb50 Mon Sep 17 00:00:00 2001 From: Nick Giancola Date: Fri, 27 Sep 2024 07:56:05 -0700 Subject: [PATCH 06/18] Prevent Rails 7.1 create_schema from being added to db/schema.rb (#276) * Prevent Rails 7.1 create_schema from being added to db/schema.rb as schemas are managed by Apartment not ActiveRecord like they would be in a vanilla Rails setup. * Need to also require the abstract superclass * Only suppress create_schema when use_schemas = true --- lib/apartment.rb | 4 ++++ .../active_record/postgres/schema_dumper.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 lib/apartment/active_record/postgres/schema_dumper.rb diff --git a/lib/apartment.rb b/lib/apartment.rb index e35fda4a..0ae34add 100644 --- a/lib/apartment.rb +++ b/lib/apartment.rb @@ -12,6 +12,10 @@ require_relative 'apartment/active_record/schema_migration' require_relative 'apartment/active_record/internal_metadata' +if ActiveRecord.version.release >= Gem::Version.new('7.1') + require_relative 'apartment/active_record/postgres/schema_dumper' +end + # Apartment main definitions module Apartment class << self diff --git a/lib/apartment/active_record/postgres/schema_dumper.rb b/lib/apartment/active_record/postgres/schema_dumper.rb new file mode 100644 index 00000000..e81fde24 --- /dev/null +++ b/lib/apartment/active_record/postgres/schema_dumper.rb @@ -0,0 +1,12 @@ +# This patch prevents `create_schema` from being added to db/schema.rb as schemas are managed by Apartment +# not ActiveRecord like they would be in a vanilla Rails setup. + +require "active_record/connection_adapters/abstract/schema_dumper" +require "active_record/connection_adapters/postgresql/schema_dumper" + +class ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaDumper + alias_method :_original_schemas, :schemas + def schemas(stream) + _original_schemas(stream) unless Apartment.use_schemas + end +end From ce37f62f2dde7bca322c6d9a5dc9a992d454cf4c Mon Sep 17 00:00:00 2001 From: Lalit Pokhrel <54302165+lit-poks@users.noreply.github.com> Date: Wed, 9 Oct 2024 18:56:24 +0600 Subject: [PATCH 07/18] fix: Deprecation cannot find version error (#291) * fix: Deprecation cannot find version error * indextation fix --- lib/apartment/deprecation.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/apartment/deprecation.rb b/lib/apartment/deprecation.rb index d12864a5..5dd9039e 100644 --- a/lib/apartment/deprecation.rb +++ b/lib/apartment/deprecation.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'active_support/deprecation' +require_relative 'version' module Apartment DEPRECATOR = ActiveSupport::Deprecation.new(Apartment::VERSION, 'Apartment') From d2f1d216782124ad250b24b04191f0c2755a6da1 Mon Sep 17 00:00:00 2001 From: Justin Granofsky Date: Wed, 9 Oct 2024 09:39:24 -0400 Subject: [PATCH 08/18] Fix: ActiveRecord monkeypatch breaking Solid Cache (#290) --- lib/apartment/active_record/connection_handling.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/apartment/active_record/connection_handling.rb b/lib/apartment/active_record/connection_handling.rb index 0c5773dd..d0be105f 100644 --- a/lib/apartment/active_record/connection_handling.rb +++ b/lib/apartment/active_record/connection_handling.rb @@ -15,10 +15,10 @@ def connected_to_with_tenant(database: nil, role: nil, prevent_writes: false, &b end end else - def connected_to_with_tenant(role: nil, prevent_writes: false, &blk) + def connected_to_with_tenant(role: nil, shard: nil, prevent_writes: false, &blk) current_tenant = Apartment::Tenant.current - connected_to_without_tenant(role: role, prevent_writes: prevent_writes) do + connected_to_without_tenant(role: role, shard: shard, prevent_writes: prevent_writes) do Apartment::Tenant.switch!(current_tenant) yield(blk) end From 2aae992d3d20acbd634ee128c0e275348cb3202b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Baril=C3=ADk?= <58255651+martinbarilik@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:43:29 +0200 Subject: [PATCH 09/18] fix: ignore transaction_timeout statement added in postgresql 17 (#289) --- lib/apartment/adapters/postgresql_adapter.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/apartment/adapters/postgresql_adapter.rb b/lib/apartment/adapters/postgresql_adapter.rb index 7b85aa51..89f1f2a3 100644 --- a/lib/apartment/adapters/postgresql_adapter.rb +++ b/lib/apartment/adapters/postgresql_adapter.rb @@ -152,7 +152,8 @@ class PostgresqlSchemaFromSqlAdapter < PostgresqlSchemaAdapter /SET idle_in_transaction_session_timeout/i, # new in postgresql 9.6 /SET default_table_access_method/i, # new in postgresql 12 /CREATE SCHEMA public/i, - /COMMENT ON SCHEMA public/i + /COMMENT ON SCHEMA public/i, + /SET transaction_timeout/i, # new in postgresql 17 ].freeze From ddd0c1df8c427a6c967d03f5769c031d8d79dd3e Mon Sep 17 00:00:00 2001 From: Masanori OKAZAKI Date: Fri, 25 Oct 2024 01:44:58 +0900 Subject: [PATCH 10/18] Exclude the default tenant table if it exists in the procedure (#184) * append pg option fix rubocop fix rubocop (line length) * append test code fix test code --------- Co-authored-by: Mauricio Novelo <5916364+mnovelo@users.noreply.github.com> --- lib/apartment.rb | 3 +- lib/apartment/adapters/postgresql_adapter.rb | 24 ++++----- spec/adapters/postgresql_adapter_spec.rb | 56 ++++++++++++++++++++ spec/examples/generic_adapter_examples.rb | 2 +- spec/examples/schema_adapter_examples.rb | 2 +- 5 files changed, 72 insertions(+), 15 deletions(-) diff --git a/lib/apartment.rb b/lib/apartment.rb index 0ae34add..6fd7c197 100644 --- a/lib/apartment.rb +++ b/lib/apartment.rb @@ -22,7 +22,8 @@ class << self extend Forwardable ACCESSOR_METHODS = %i[use_schemas use_sql seed_after_create prepend_environment default_tenant - append_environment with_multi_server_setup tenant_presence_check active_record_log].freeze + append_environment with_multi_server_setup tenant_presence_check + active_record_log pg_exclude_clone_tables].freeze WRITER_METHODS = %i[tenant_names database_schema_file excluded_models persistent_schemas connection_class diff --git a/lib/apartment/adapters/postgresql_adapter.rb b/lib/apartment/adapters/postgresql_adapter.rb index 89f1f2a3..b5f50c10 100644 --- a/lib/apartment/adapters/postgresql_adapter.rb +++ b/lib/apartment/adapters/postgresql_adapter.rb @@ -195,15 +195,13 @@ def copy_schema_migrations # @return {String} raw SQL contaning only postgres schema dump # def pg_dump_schema - # Skip excluded tables? :/ - # excluded_tables = - # collect_table_names(Apartment.excluded_models) - # .map! {|t| "-T #{t}"} - # .join(' ') - - # `pg_dump -s -x -O -n #{default_tenant} #{excluded_tables} #{dbname}` - - with_pg_env { `pg_dump -s -x -O -n #{default_tenant} #{dbname}` } + exclude_table = + if Apartment.pg_exclude_clone_tables + excluded_tables.map! { |t| "-T #{t}" }.join(' ') + else + '' + end + with_pg_env { `pg_dump -s -x -O -n #{default_tenant} #{dbname} #{exclude_table}` } end # Dump data from schema_migrations table @@ -255,6 +253,8 @@ def swap_schema_qualifier(sql) sql.gsub(/#{default_tenant}\.\w*/) do |match| if Apartment.pg_excluded_names.any? { |name| match.include? name } match + elsif Apartment.pg_exclude_clone_tables && excluded_tables.any?(match) + match else match.gsub("#{default_tenant}.", %("#{current}".)) end @@ -267,10 +267,10 @@ def check_input_against_regexps(input, regexps) regexps.select { |c| input.match c } end - # Collect table names from AR Models + # Convenience method for excluded table names # - def collect_table_names(models) - models.map do |m| + def excluded_tables + Apartment.excluded_models.map do |m| m.constantize.table_name end end diff --git a/spec/adapters/postgresql_adapter_spec.rb b/spec/adapters/postgresql_adapter_spec.rb index 981440f6..841ac5e5 100644 --- a/spec/adapters/postgresql_adapter_spec.rb +++ b/spec/adapters/postgresql_adapter_spec.rb @@ -63,5 +63,61 @@ def tenant_names it_behaves_like 'a generic apartment adapter able to handle custom configuration' it_behaves_like 'a connection based apartment adapter' end + + context 'when using pg_exclude_clone_tables with SQL dump' do + before do + Apartment.excluded_models = ['Company'] + Apartment.use_schemas = true + Apartment.use_sql = true + Apartment.pg_exclude_clone_tables = true + ActiveRecord::Base.connection.execute <<-PROCEDURE + CREATE OR REPLACE FUNCTION test_function() RETURNS INTEGER AS $function$ + DECLARE + r1 INTEGER; + r2 INTEGER; + BEGIN + SELECT COUNT(*) INTO r1 FROM public.companies; + SELECT COUNT(*) INTO r2 FROM public.users; + RETURN r1 + r2; + END; + $function$ LANGUAGE plpgsql; + PROCEDURE + end + + after do + Apartment::Tenant.drop('has-procedure') if Apartment.connection.schema_exists? 'has-procedure' + ActiveRecord::Base.connection.execute('DROP FUNCTION IF EXISTS test_function();') + # Apartment::Tenant.init creates per model connection. + # Remove the connection after testing not to unintentionally keep the connection across tests. + Apartment.excluded_models.each do |excluded_model| + excluded_model.constantize.remove_connection + end + end + + # Not sure why, but somehow using let(:tenant_names) memoizes for the whole example group, not just each test + def tenant_names + ActiveRecord::Base.connection.execute('SELECT nspname FROM pg_namespace;').collect { |row| row['nspname'] } + end + + let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.schema_search_path.delete('"') } } + let(:c) { rand(5) } + let(:u) { rand(5) } + + it_behaves_like 'a generic apartment adapter' + it_behaves_like 'a schema based apartment adapter' + + # rubocop:disable RSpec/ExampleLength + it 'not change excluded_models in the procedure code' do + Apartment::Tenant.init + Apartment::Tenant.create('has-procedure') + Apartment::Tenant.switch!('has-procedure') + c.times { Company.create } + u.times { User.create } + count = ActiveRecord::Base.connection.execute('SELECT test_function();')[0]['test_function'] + expect(count).to(eq(Company.count + User.count)) + Company.delete_all + end + # rubocop:enable RSpec/ExampleLength + end end end diff --git a/spec/examples/generic_adapter_examples.rb b/spec/examples/generic_adapter_examples.rb index 2f8a3ea0..7999a6d2 100644 --- a/spec/examples/generic_adapter_examples.rb +++ b/spec/examples/generic_adapter_examples.rb @@ -42,7 +42,7 @@ it 'should load schema.rb to new schema' do subject.switch(db1) do - expect(connection.tables).to include('companies') + expect(connection.tables).to include('users') end end diff --git a/spec/examples/schema_adapter_examples.rb b/spec/examples/schema_adapter_examples.rb index 35623cde..fdb955bc 100644 --- a/spec/examples/schema_adapter_examples.rb +++ b/spec/examples/schema_adapter_examples.rb @@ -63,7 +63,7 @@ describe '#create' do it 'should load schema.rb to new schema' do connection.schema_search_path = schema1 - expect(connection.tables).to include('companies') + expect(connection.tables).to include('users') end it 'should yield to block if passed and reset' do From 3780a5fe76eb517e2f8a7f838a1a29cb0e77dfc4 Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Thu, 24 Oct 2024 10:48:48 -0600 Subject: [PATCH 11/18] Use `Rails.application.executor.wrap` in Threads (#288) --- lib/apartment/tasks/task_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/apartment/tasks/task_helper.rb b/lib/apartment/tasks/task_helper.rb index 32cd908e..52d2fdd5 100644 --- a/lib/apartment/tasks/task_helper.rb +++ b/lib/apartment/tasks/task_helper.rb @@ -4,7 +4,9 @@ module Apartment module TaskHelper def self.each_tenant(&block) Parallel.each(tenants_without_default, in_threads: Apartment.parallel_migration_threads) do |tenant| - block.call(tenant) + Rails.application.executor.wrap do + block.call(tenant) + end end end From b3810fbb0368ee61bbb901f5e7d5a50c91275086 Mon Sep 17 00:00:00 2001 From: Mauricio Novelo <5916364+mnovelo@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:16:18 -0400 Subject: [PATCH 12/18] Split specs according to db version (#292) * Split specs according to db version * DB engine specific db configs * Fix typo * Typo and indentation fixes * Refactor database configuration tasks * Debug YAML load * Fix file reading and test names * Fix rspec versions, workflow names, and writing db configs * Fix workflow test names * Fix gemspec * Remove no db config * Including lambda * Try no db settings * Try excluding * Safe operator if db undefined * Use postgres as the default * Update configs * Re-add Appraisal generated Gemfiles * Try more appraisal versions * Try deleting dummy gemspec to avoid conflicts * Don't explicitly require sqlite3 * Specify sqlite3 first * Still list sqlite3 as dependency, but Rails specify version * Don't specify a version for the jdbc drivers * Update sqlite3 configs * Update adapter specs and loading * Update adapters and specs * Try without a No DB specification * Match symbols * Try to always run specs that don't specify a db engine * There is no activerecord-jdbc-adapter ~> 71.0 * Fix mysql db config * Fix mysql commands * Update Rakefile * Accommodate 6.1 MigrationContext * SchemaMigration context * Try passing connection in migrate * Fix version specification * Use default connection * Remove jruby combos for Rails 7.1 and 7.2 * Add additional postgres versions * Fix pg naming * Install postgres clients * Use sudo apt-get * Try adding the Postgres APT repo first * Update how we get all the client libraries * Update pg_dump install again * Use automated repo config * Try simulating enter key * Debug pg adapter * Fix prefix for excluded models * Don't double add prefixes * Simplify logic for sequence prefixes * Make changelog legacy * Add spec coverage * Update README and add CODE_OF_CONDUCT * Auto-close stale issues --- .github/workflows/close-stale-issues.yml | 30 ++ .github/workflows/main.yml | 76 --- .github/workflows/rspec_mysql_8_0.yml | 92 ++++ .github/workflows/rspec_pg_14.yml | 100 ++++ .github/workflows/rspec_pg_15.yml | 100 ++++ .github/workflows/rspec_pg_16.yml | 100 ++++ .github/workflows/rspec_pg_17.yml | 100 ++++ .github/workflows/rspec_sqlite_3.yml | 79 ++++ .github/workflows/rubocop.yml | 2 +- .rubocop.yml | 61 ++- .rubocop_todo.yml | 439 ------------------ .ruby-version | 2 +- Appraisals | 160 ++++++- CODE_OF_CONDUCT.md | 71 +++ Gemfile | 15 + README.md | 78 ++-- Rakefile | 66 +-- gemfiles/rails_6_1.gemfile | 17 - gemfiles/rails_6_1_jdbc_mysql.gemfile | 27 ++ gemfiles/rails_6_1_jdbc_postgresql.gemfile | 27 ++ gemfiles/rails_6_1_jdbc_sqlite3.gemfile | 27 ++ gemfiles/rails_6_1_mysql.gemfile | 22 + gemfiles/rails_6_1_postgresql.gemfile | 22 + gemfiles/rails_6_1_sqlite3.gemfile | 22 + gemfiles/rails_7_0.gemfile | 17 - gemfiles/rails_7_0_jdbc_mysql.gemfile | 27 ++ gemfiles/rails_7_0_jdbc_postgresql.gemfile | 27 ++ gemfiles/rails_7_0_jdbc_sqlite3.gemfile | 27 ++ gemfiles/rails_7_0_mysql.gemfile | 22 + gemfiles/rails_7_0_postgresql.gemfile | 22 + gemfiles/rails_7_0_sqlite3.gemfile | 22 + gemfiles/rails_7_1.gemfile | 17 - gemfiles/rails_7_1_jdbc_mysql.gemfile | 27 ++ gemfiles/rails_7_1_jdbc_postgresql.gemfile | 27 ++ gemfiles/rails_7_1_jdbc_sqlite3.gemfile | 27 ++ gemfiles/rails_7_1_mysql.gemfile | 22 + gemfiles/rails_7_1_postgresql.gemfile | 22 + gemfiles/rails_7_1_sqlite3.gemfile | 22 + gemfiles/rails_7_2.gemfile | 17 - gemfiles/rails_7_2_jdbc_mysql.gemfile | 27 ++ gemfiles/rails_7_2_jdbc_postgresql.gemfile | 27 ++ gemfiles/rails_7_2_jdbc_sqlite3.gemfile | 27 ++ gemfiles/rails_7_2_mysql.gemfile | 22 + gemfiles/rails_7_2_postgresql.gemfile | 22 + gemfiles/rails_7_2_sqlite3.gemfile | 22 + CHANGELOG.md => legacy_CHANGELOG.md | 0 .../active_record/postgres/schema_dumper.rb | 20 +- .../active_record/postgresql_adapter.rb | 11 +- lib/apartment/adapters/postgresql_adapter.rb | 5 - ros-apartment.gemspec | 44 +- spec/adapters/jdbc_mysql_adapter_spec.rb | 2 +- spec/adapters/jdbc_postgresql_adapter_spec.rb | 2 +- spec/adapters/mysql2_adapter_spec.rb | 8 +- spec/adapters/postgresql_adapter_spec.rb | 8 +- spec/adapters/sqlite3_adapter_spec.rb | 8 +- spec/adapters/trilogy_adapter_spec.rb | 8 +- spec/config/database.yml.sample | 49 -- spec/config/mysql.yml.erb | 14 + spec/config/postgresql.yml.erb | 17 + spec/config/sqlite.yml.erb | 6 + spec/dummy/config/database.yml.sample | 44 -- spec/dummy/db/test.sqlite3 | Bin 12288 -> 0 bytes spec/dummy_engine/Gemfile | 2 +- .../config/initializers/apartment.rb | 2 +- spec/dummy_engine/dummy_engine.gemspec | 26 -- spec/integration/query_caching_spec.rb | 4 +- spec/spec_helper.rb | 37 +- spec/support/config.rb | 4 +- spec/support/setup.rb | 2 +- spec/tenant_spec.rb | 13 +- 70 files changed, 1684 insertions(+), 879 deletions(-) create mode 100644 .github/workflows/close-stale-issues.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/rspec_mysql_8_0.yml create mode 100644 .github/workflows/rspec_pg_14.yml create mode 100644 .github/workflows/rspec_pg_15.yml create mode 100644 .github/workflows/rspec_pg_16.yml create mode 100644 .github/workflows/rspec_pg_17.yml create mode 100644 .github/workflows/rspec_sqlite_3.yml delete mode 100644 .rubocop_todo.yml create mode 100644 CODE_OF_CONDUCT.md delete mode 100644 gemfiles/rails_6_1.gemfile create mode 100644 gemfiles/rails_6_1_jdbc_mysql.gemfile create mode 100644 gemfiles/rails_6_1_jdbc_postgresql.gemfile create mode 100644 gemfiles/rails_6_1_jdbc_sqlite3.gemfile create mode 100644 gemfiles/rails_6_1_mysql.gemfile create mode 100644 gemfiles/rails_6_1_postgresql.gemfile create mode 100644 gemfiles/rails_6_1_sqlite3.gemfile delete mode 100644 gemfiles/rails_7_0.gemfile create mode 100644 gemfiles/rails_7_0_jdbc_mysql.gemfile create mode 100644 gemfiles/rails_7_0_jdbc_postgresql.gemfile create mode 100644 gemfiles/rails_7_0_jdbc_sqlite3.gemfile create mode 100644 gemfiles/rails_7_0_mysql.gemfile create mode 100644 gemfiles/rails_7_0_postgresql.gemfile create mode 100644 gemfiles/rails_7_0_sqlite3.gemfile delete mode 100644 gemfiles/rails_7_1.gemfile create mode 100644 gemfiles/rails_7_1_jdbc_mysql.gemfile create mode 100644 gemfiles/rails_7_1_jdbc_postgresql.gemfile create mode 100644 gemfiles/rails_7_1_jdbc_sqlite3.gemfile create mode 100644 gemfiles/rails_7_1_mysql.gemfile create mode 100644 gemfiles/rails_7_1_postgresql.gemfile create mode 100644 gemfiles/rails_7_1_sqlite3.gemfile delete mode 100644 gemfiles/rails_7_2.gemfile create mode 100644 gemfiles/rails_7_2_jdbc_mysql.gemfile create mode 100644 gemfiles/rails_7_2_jdbc_postgresql.gemfile create mode 100644 gemfiles/rails_7_2_jdbc_sqlite3.gemfile create mode 100644 gemfiles/rails_7_2_mysql.gemfile create mode 100644 gemfiles/rails_7_2_postgresql.gemfile create mode 100644 gemfiles/rails_7_2_sqlite3.gemfile rename CHANGELOG.md => legacy_CHANGELOG.md (100%) delete mode 100644 spec/config/database.yml.sample create mode 100644 spec/config/mysql.yml.erb create mode 100644 spec/config/postgresql.yml.erb create mode 100644 spec/config/sqlite.yml.erb delete mode 100644 spec/dummy/config/database.yml.sample delete mode 100644 spec/dummy/db/test.sqlite3 delete mode 100644 spec/dummy_engine/dummy_engine.gemspec diff --git a/.github/workflows/close-stale-issues.yml b/.github/workflows/close-stale-issues.yml new file mode 100644 index 00000000..b0676090 --- /dev/null +++ b/.github/workflows/close-stale-issues.yml @@ -0,0 +1,30 @@ +name: Close Stale Issues + +on: + schedule: + - cron: '0 0 * * *' # Runs daily at midnight + workflow_dispatch: + +permissions: + contents: write # only for delete-branch option + issues: write + pull-requests: write + +jobs: + close-stale-issues: + name: Close Stale Issues + runs-on: ubuntu-latest + steps: + - name: Close stale issues and pull requests + uses: actions/stale@v9 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.' + stale-pr-message: 'This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.' + days-before-stale: 30 + days-before-close: 7 + stale-issue-label: 'stale' + exempt-issue-labels: 'pinned,security' + stale-pr-label: 'stale' + exempt-pr-labels: 'work-in-progress' + delete-branch: true \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index feabdc00..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: RSpec -on: - push: - branches: - - development - - main - pull_request: - types: [opened, synchronize, reopened] - release: - types: [published] - -jobs: - test: - name: rails / rspec - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - ruby_version: - - 3.1 - - 3.2 - - 3.3 - - jruby - rails_version: - - 6_1 - - 7_0 - - 7_1 - - 7_2 - # - master # versions failing - exclude: - - ruby_version: jruby - rails_version: 7_1 - - ruby_version: jruby - rails_version: 7_2 - env: - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}.gemfile - CI: true - services: - postgres: - image: postgres:14 # pg_dump tests currently depend on this version - env: - POSTGRES_PASSWORD: postgres - POSTGRES_HOST_AUTH_METHOD: trust - POSTGRES_DB: apartment_postgresql_test - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - mysql: - image: mysql:8.0 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: true - MYSQL_DATABASE: apartment_mysql_test - options: >- - --health-cmd "mysqladmin ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 3306:3306 - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby ${{ matrix.ruby-version }} - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby_version }} - bundler-cache: true - - name: Configure config database.yml - run: bundle exec rake db:copy_credentials - - name: Database Setup - run: bundle exec rake db:test:prepare - - name: Run tests - run: bundle exec rspec --format progress --format RspecJunitFormatter -o ~/test-results/rspec/rspec.xml diff --git a/.github/workflows/rspec_mysql_8_0.yml b/.github/workflows/rspec_mysql_8_0.yml new file mode 100644 index 00000000..d4e89fed --- /dev/null +++ b/.github/workflows/rspec_mysql_8_0.yml @@ -0,0 +1,92 @@ +name: RSpec MySQL 8.0 +on: + push: + branches: + - development + - main + pull_request: + types: [opened, synchronize, reopened] + release: + types: [published] + +jobs: + test: + name: ${{ github.workflow }}, Ruby ${{ matrix.ruby_version }}, Rails ${{ matrix.rails_version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby_version: + - 3.1 + - 3.2 + - 3.3 + - jruby + rails_version: + - 6_1 + - 7_0 + - 7_1 + - 7_2 + # - master # versions failing + exclude: + - ruby_version: jruby + rails_version: 7_1 + - ruby_version: jruby + rails_version: 7_2 + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_mysql.gemfile + CI: true + DATABASE_ENGINE: mysql + RUBY_VERSION: ${{ matrix.ruby_version }} + RAILS_VERSION: ${{ matrix.rails_version }} + services: + mysql: + image: mysql:8.0-alpine + env: + MYSQL_ALLOW_EMPTY_PASSWORD: true + MYSQL_DATABASE: apartment_mysql_test + options: >- + --health-cmd "mysqladmin ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 3306:3306 + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + - name: Configure config database.yml + run: bundle exec rake db:load_credentials + - name: Database Setup + run: bundle exec rake db:test:prepare + - name: Run tests + id: rspec-tests + timeout-minutes: 20 + continue-on-error: true + run: | + mkdir -p ./coverage + bundle exec rspec --format progress \ + --format RspecJunitFormatter -o ./coverage/test-results.xml \ + --profile + - name: Codecov Upload + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/coverage.json + - name: Upload test results to Codecov + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/test-results.xml + - name: Notify of test failure + if: steps.rspec-tests.outcome == 'failure' + run: exit 1 diff --git a/.github/workflows/rspec_pg_14.yml b/.github/workflows/rspec_pg_14.yml new file mode 100644 index 00000000..dc9029ac --- /dev/null +++ b/.github/workflows/rspec_pg_14.yml @@ -0,0 +1,100 @@ +name: RSpec PostgreSQL 14 +on: + push: + branches: + - development + - main + pull_request: + types: [opened, synchronize, reopened] + release: + types: [published] + +jobs: + test: + name: ${{ github.workflow }}, Ruby ${{ matrix.ruby_version }}, Rails ${{ matrix.rails_version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby_version: + - 3.1 + - 3.2 + - 3.3 + - jruby + rails_version: + - 6_1 + - 7_0 + - 7_1 + - 7_2 + # - master # versions failing + exclude: + - ruby_version: jruby + rails_version: 7_1 + - ruby_version: jruby + rails_version: 7_2 + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_postgresql.gemfile + CI: true + DATABASE_ENGINE: postgresql + RUBY_VERSION: ${{ matrix.ruby_version }} + RAILS_VERSION: ${{ matrix.rails_version }} + services: + postgres: + image: postgres:14-alpine + env: + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_DB: apartment_postgresql_test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - name: Install PostgreSQL client + run: | + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends postgresql-common + echo | sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends postgresql-client-14 + - uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + - name: Configure config database.yml + run: bundle exec rake db:load_credentials + - name: Database Setup + run: bundle exec rake db:test:prepare + - name: Run tests + id: rspec-tests + timeout-minutes: 20 + continue-on-error: true + run: | + mkdir -p ./coverage + bundle exec rspec --format progress \ + --format RspecJunitFormatter -o ./coverage/test-results.xml \ + --profile + - name: Codecov Upload + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/coverage.json + - name: Upload test results to Codecov + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/test-results.xml + - name: Notify of test failure + if: steps.rspec-tests.outcome == 'failure' + run: exit 1 \ No newline at end of file diff --git a/.github/workflows/rspec_pg_15.yml b/.github/workflows/rspec_pg_15.yml new file mode 100644 index 00000000..a6d2c41d --- /dev/null +++ b/.github/workflows/rspec_pg_15.yml @@ -0,0 +1,100 @@ +name: RSpec PostgreSQL 15 +on: + push: + branches: + - development + - main + pull_request: + types: [opened, synchronize, reopened] + release: + types: [published] + +jobs: + test: + name: ${{ github.workflow }}, Ruby ${{ matrix.ruby_version }}, Rails ${{ matrix.rails_version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby_version: + - 3.1 + - 3.2 + - 3.3 + - jruby + rails_version: + - 6_1 + - 7_0 + - 7_1 + - 7_2 + # - master # versions failing + exclude: + - ruby_version: jruby + rails_version: 7_1 + - ruby_version: jruby + rails_version: 7_2 + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_postgresql.gemfile + CI: true + DATABASE_ENGINE: postgresql + RUBY_VERSION: ${{ matrix.ruby_version }} + RAILS_VERSION: ${{ matrix.rails_version }} + services: + postgres: + image: postgres:15-alpine + env: + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_DB: apartment_postgresql_test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - name: Install PostgreSQL client + run: | + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends postgresql-common + echo | sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends postgresql-client-15 + - uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + - name: Configure config database.yml + run: bundle exec rake db:load_credentials + - name: Database Setup + run: bundle exec rake db:test:prepare + - name: Run tests + id: rspec-tests + timeout-minutes: 20 + continue-on-error: true + run: | + mkdir -p ./coverage + bundle exec rspec --format progress \ + --format RspecJunitFormatter -o ./coverage/test-results.xml \ + --profile + - name: Codecov Upload + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/coverage.json + - name: Upload test results to Codecov + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/test-results.xml + - name: Notify of test failure + if: steps.rspec-tests.outcome == 'failure' + run: exit 1 \ No newline at end of file diff --git a/.github/workflows/rspec_pg_16.yml b/.github/workflows/rspec_pg_16.yml new file mode 100644 index 00000000..9fd2071f --- /dev/null +++ b/.github/workflows/rspec_pg_16.yml @@ -0,0 +1,100 @@ +name: RSpec PostgreSQL 16 +on: + push: + branches: + - development + - main + pull_request: + types: [opened, synchronize, reopened] + release: + types: [published] + +jobs: + test: + name: ${{ github.workflow }}, Ruby ${{ matrix.ruby_version }}, Rails ${{ matrix.rails_version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby_version: + - 3.1 + - 3.2 + - 3.3 + - jruby + rails_version: + - 6_1 + - 7_0 + - 7_1 + - 7_2 + # - master # versions failing + exclude: + - ruby_version: jruby + rails_version: 7_1 + - ruby_version: jruby + rails_version: 7_2 + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_postgresql.gemfile + CI: true + DATABASE_ENGINE: postgresql + RUBY_VERSION: ${{ matrix.ruby_version }} + RAILS_VERSION: ${{ matrix.rails_version }} + services: + postgres: + image: postgres:16-alpine + env: + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_DB: apartment_postgresql_test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - name: Install PostgreSQL client + run: | + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends postgresql-common + echo | sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends postgresql-client-16 + - uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + - name: Configure config database.yml + run: bundle exec rake db:load_credentials + - name: Database Setup + run: bundle exec rake db:test:prepare + - name: Run tests + id: rspec-tests + timeout-minutes: 20 + continue-on-error: true + run: | + mkdir -p ./coverage + bundle exec rspec --format progress \ + --format RspecJunitFormatter -o ./coverage/test-results.xml \ + --profile + - name: Codecov Upload + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/coverage.json + - name: Upload test results to Codecov + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/test-results.xml + - name: Notify of test failure + if: steps.rspec-tests.outcome == 'failure' + run: exit 1 \ No newline at end of file diff --git a/.github/workflows/rspec_pg_17.yml b/.github/workflows/rspec_pg_17.yml new file mode 100644 index 00000000..349a5fe7 --- /dev/null +++ b/.github/workflows/rspec_pg_17.yml @@ -0,0 +1,100 @@ +name: RSpec PostgreSQL 17 +on: + push: + branches: + - development + - main + pull_request: + types: [opened, synchronize, reopened] + release: + types: [published] + +jobs: + test: + name: ${{ github.workflow }}, Ruby ${{ matrix.ruby_version }}, Rails ${{ matrix.rails_version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby_version: + - 3.1 + - 3.2 + - 3.3 + - jruby + rails_version: + - 6_1 + - 7_0 + - 7_1 + - 7_2 + # - master # versions failing + exclude: + - ruby_version: jruby + rails_version: 7_1 + - ruby_version: jruby + rails_version: 7_2 + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_postgresql.gemfile + CI: true + DATABASE_ENGINE: postgresql + RUBY_VERSION: ${{ matrix.ruby_version }} + RAILS_VERSION: ${{ matrix.rails_version }} + services: + postgres: + image: postgres:17-alpine + env: + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_DB: apartment_postgresql_test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - name: Install PostgreSQL client + run: | + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends postgresql-common + echo | sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends postgresql-client-17 + - uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + - name: Configure config database.yml + run: bundle exec rake db:load_credentials + - name: Database Setup + run: bundle exec rake db:test:prepare + - name: Run tests + id: rspec-tests + timeout-minutes: 20 + continue-on-error: true + run: | + mkdir -p ./coverage + bundle exec rspec --format progress \ + --format RspecJunitFormatter -o ./coverage/test-results.xml \ + --profile + - name: Codecov Upload + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/coverage.json + - name: Upload test results to Codecov + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/test-results.xml + - name: Notify of test failure + if: steps.rspec-tests.outcome == 'failure' + run: exit 1 \ No newline at end of file diff --git a/.github/workflows/rspec_sqlite_3.yml b/.github/workflows/rspec_sqlite_3.yml new file mode 100644 index 00000000..964e96e4 --- /dev/null +++ b/.github/workflows/rspec_sqlite_3.yml @@ -0,0 +1,79 @@ +name: RSpec SQLite 3 +on: + push: + branches: + - development + - main + pull_request: + types: [opened, synchronize, reopened] + release: + types: [published] + +jobs: + test: + name: ${{ github.workflow }}, Ruby ${{ matrix.ruby_version }}, Rails ${{ matrix.rails_version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby_version: + - 3.1 + - 3.2 + - 3.3 + # - jruby # We don't support jruby for sqlite yet + rails_version: + - 6_1 + - 7_0 + - 7_1 + - 7_2 + # - master # versions failing + exclude: + - ruby_version: jruby + rails_version: 7_1 + - ruby_version: jruby + rails_version: 7_2 + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_sqlite3.gemfile + CI: true + DATABASE_ENGINE: sqlite + RUBY_VERSION: ${{ matrix.ruby_version }} + RAILS_VERSION: ${{ matrix.rails_version }} + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + - name: Configure config database.yml + run: bundle exec rake db:load_credentials + - name: Database Setup + run: bundle exec rake db:test:prepare + - name: Run tests + id: rspec-tests + timeout-minutes: 20 + continue-on-error: true + run: | + mkdir -p ./coverage + bundle exec rspec --format progress \ + --format RspecJunitFormatter -o ./coverage/test-results.xml \ + --profile + - name: Codecov Upload + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/coverage.json + - name: Upload test results to Codecov + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + disable_search: true + env_vars: DATABASE_ENGINE, RUBY_VERSION, RAILS_VERSION + file: ./coverage/test-results.xml + - name: Notify of test failure + if: steps.rspec-tests.outcome == 'failure' + run: exit 1 \ No newline at end of file diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 74bc6791..aa848c87 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -13,7 +13,7 @@ jobs: name: runner / rubocop runs-on: ubuntu-latest env: - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_7_0.gemfile + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_7_2_postgresql.gemfile steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 diff --git a/.rubocop.yml b/.rubocop.yml index 96016cce..67b73f9a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,11 +1,5 @@ -inherit_from: .rubocop_todo.yml - -require: - - rubocop-rails - - rubocop-performance - - rubocop-rspec - AllCops: + NewCops: enable Exclude: - vendor/bundle/**/* - gemfiles/**/*.gemfile @@ -13,12 +7,20 @@ AllCops: - spec/dummy_engine/dummy_engine.gemspec - spec/schemas/**/*.rb - NewCops: enable +require: + - rubocop-rails + - rubocop-performance + - rubocop-thread_safety + - rubocop-rake + - rubocop-rspec Gemspec/RequiredRubyVersion: Exclude: - 'ros-apartment.gemspec' +Layout/MultilineMethodCallIndentation: + EnforcedStyle: indented + Metrics/BlockLength: Exclude: - spec/**/*.rb @@ -33,4 +35,45 @@ Rails/Output: Enabled: false Style/Documentation: - Enabled: false \ No newline at end of file + Enabled: false + +Style/StringLiterals: + EnforcedStyle: single_quotes + +Style/InlineComment: + Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: true + Exclude: + - Gemfile + +Style/MethodCallWithArgsParentheses: + Enabled: true + EnforcedStyle: require_parentheses + AllowedPatterns: + - 'puts' + - 'info' + - 'warn' + - 'debug' + - 'error' + - 'fatal' + - 'fail' + +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: comma + +Style/ClassAndModuleChildren: + EnforcedStyle: nested + AutoCorrect: true + +Style/CollectionMethods: + PreferredMethods: + collect: 'map' + collect!: 'map!' + inject: 'reduce' + detect: 'detect' + find_all: 'select' \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 53cdf54a..00000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,439 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2024-05-07 18:57:21 UTC using RuboCop version 1.63.4. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Severity, Include. -# Include: **/*.gemspec -Gemspec/DeprecatedAttributeAssignment: - Exclude: - - 'ros-apartment.gemspec' - -# Offense count: 20 -# Configuration parameters: EnforcedStyle, AllowedGems, Include. -# SupportedStyles: Gemfile, gems.rb, gemspec -# Include: **/*.gemspec, **/Gemfile, **/gems.rb -Gemspec/DevelopmentDependencies: - Exclude: - - 'ros-apartment.gemspec' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Severity, Include. -# Include: **/*.gemspec -Gemspec/RequireMFA: - Exclude: - - 'ros-apartment.gemspec' - -# Offense count: 6 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLineAfterMagicComment: - Exclude: - - 'spec/dummy/config/initializers/backtrace_silencers.rb' - - 'spec/dummy/config/initializers/inflections.rb' - - 'spec/dummy/config/initializers/mime_types.rb' - - 'spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb' - - 'spec/dummy_engine/test/dummy/config/initializers/inflections.rb' - - 'spec/dummy_engine/test/dummy/config/initializers/mime_types.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. -Layout/LeadingCommentSpace: - Exclude: - - 'ros-apartment.gemspec' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: aligned, indented -Layout/LineEndStringConcatenationIndentation: - Exclude: - - 'lib/apartment/custom_console.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Layout/SpaceBeforeComment: - Exclude: - - 'ros-apartment.gemspec' - -# Offense count: 1 -Lint/MixedRegexpCaptureTypes: - Exclude: - - 'lib/apartment/elevators/domain.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Lint/RedundantCopDisableDirective: - Exclude: - - 'spec/support/config.rb' - -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -Lint/RedundantDirGlobSort: - Exclude: - - 'spec/spec_helper.rb' - -# Offense count: 2 -# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. -Metrics/AbcSize: - Max: 28 - -# Offense count: 4 -# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. -# AllowedMethods: refine -Metrics/BlockLength: - Max: 83 - -# Offense count: 1 -# Configuration parameters: CountComments, CountAsOne. -Metrics/ClassLength: - Max: 151 - -# Offense count: 6 -# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. -Metrics/MethodLength: - Max: 23 - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, BlockForwardingName. -# SupportedStyles: anonymous, explicit -Naming/BlockForwarding: - Exclude: - - 'lib/apartment/adapters/abstract_adapter.rb' - - 'lib/apartment/log_subscriber.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Performance/RedundantBlockCall: - Exclude: - - 'lib/apartment/tasks/task_helper.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Performance/StringIdentifierArgument: - Exclude: - - 'lib/apartment/railtie.rb' - -# Offense count: 3 -RSpec/AnyInstance: - Exclude: - - 'spec/unit/migrator_spec.rb' - -# Offense count: 4 -# This cop supports unsafe autocorrection (--autocorrect-all). -RSpec/BeEq: - Exclude: - - 'spec/adapters/sqlite3_adapter_spec.rb' - - 'spec/unit/elevators/first_subdomain_spec.rb' - -# Offense count: 2 -RSpec/BeforeAfterAll: - Exclude: - - 'spec/adapters/sqlite3_adapter_spec.rb' - - 'spec/tasks/apartment_rake_spec.rb' - -# Offense count: 18 -# Configuration parameters: Prefixes, AllowedPatterns. -# Prefixes: when, with, without -RSpec/ContextWording: - Exclude: - - 'spec/adapters/sqlite3_adapter_spec.rb' - - 'spec/examples/generic_adapter_custom_configuration_example.rb' - - 'spec/examples/schema_adapter_examples.rb' - - 'spec/support/contexts.rb' - - 'spec/tasks/apartment_rake_spec.rb' - - 'spec/tenant_spec.rb' - -# Offense count: 5 -# Configuration parameters: IgnoredMetadata. -RSpec/DescribeClass: - Exclude: - - 'spec/integration/apartment_rake_integration_spec.rb' - - 'spec/integration/connection_handling_spec.rb' - - 'spec/integration/query_caching_spec.rb' - - 'spec/integration/use_within_an_engine_spec.rb' - - 'spec/tasks/apartment_rake_spec.rb' - -# Offense count: 6 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants. -# SupportedStyles: described_class, explicit -RSpec/DescribedClass: - Exclude: - - 'spec/apartment_spec.rb' - - 'spec/tenant_spec.rb' - - 'spec/unit/elevators/host_hash_spec.rb' - - 'spec/unit/migrator_spec.rb' - -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -RSpec/EmptyLineAfterFinalLet: - Exclude: - - 'spec/adapters/sqlite3_adapter_spec.rb' - - 'spec/examples/schema_adapter_examples.rb' - -# Offense count: 14 -# Configuration parameters: CountAsOne. -RSpec/ExampleLength: - Max: 12 - -# Offense count: 58 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: CustomTransform, IgnoredWords, DisallowedExamples. -# DisallowedExamples: works -RSpec/ExampleWording: - Exclude: - - 'spec/adapters/sqlite3_adapter_spec.rb' - - 'spec/apartment_spec.rb' - - 'spec/examples/connection_adapter_examples.rb' - - 'spec/examples/generic_adapter_custom_configuration_example.rb' - - 'spec/examples/generic_adapter_examples.rb' - - 'spec/examples/schema_adapter_examples.rb' - - 'spec/integration/apartment_rake_integration_spec.rb' - - 'spec/integration/use_within_an_engine_spec.rb' - - 'spec/tasks/apartment_rake_spec.rb' - - 'spec/tenant_spec.rb' - -# Offense count: 12 -# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. -# Include: **/*_spec*rb*, **/spec/**/* -RSpec/FilePath: - Exclude: - - 'spec/adapters/mysql2_adapter_spec.rb' - - 'spec/adapters/trilogy_adapter_spec.rb' - - 'spec/adapters/postgresql_adapter_spec.rb' - - 'spec/adapters/sqlite3_adapter_spec.rb' - - 'spec/tenant_spec.rb' - - 'spec/unit/config_spec.rb' - - 'spec/unit/elevators/domain_spec.rb' - - 'spec/unit/elevators/first_subdomain_spec.rb' - - 'spec/unit/elevators/generic_spec.rb' - - 'spec/unit/elevators/host_hash_spec.rb' - - 'spec/unit/elevators/host_spec.rb' - - 'spec/unit/elevators/subdomain_spec.rb' - - 'spec/unit/migrator_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, each, example -RSpec/HookArgument: - Exclude: - - 'spec/support/setup.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -RSpec/HooksBeforeExamples: - Exclude: - - 'spec/adapters/sqlite3_adapter_spec.rb' - - 'spec/examples/schema_adapter_examples.rb' - -# Offense count: 4 -# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns. -RSpec/IndexedLet: - Exclude: - - 'spec/examples/schema_adapter_examples.rb' - - 'spec/support/contexts.rb' - -# Offense count: 16 -# Configuration parameters: AssignmentOnly. -RSpec/InstanceVariable: - Exclude: - - 'spec/examples/generic_adapter_examples.rb' - - 'spec/examples/schema_adapter_examples.rb' - - 'spec/integration/apartment_rake_integration_spec.rb' - - 'spec/integration/use_within_an_engine_spec.rb' - - 'spec/tasks/apartment_rake_spec.rb' - -# Offense count: 2 -RSpec/LeakyConstantDeclaration: - Exclude: - - 'spec/examples/generic_adapters_callbacks_examples.rb' - - 'spec/unit/elevators/generic_spec.rb' - -# Offense count: 27 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: have_received, receive -RSpec/MessageSpies: - Exclude: - - 'spec/examples/generic_adapter_custom_configuration_example.rb' - - 'spec/integration/apartment_rake_integration_spec.rb' - - 'spec/integration/use_within_an_engine_spec.rb' - - 'spec/tasks/apartment_rake_spec.rb' - - 'spec/unit/elevators/domain_spec.rb' - - 'spec/unit/elevators/generic_spec.rb' - - 'spec/unit/elevators/host_hash_spec.rb' - - 'spec/unit/elevators/host_spec.rb' - - 'spec/unit/elevators/subdomain_spec.rb' - - 'spec/unit/migrator_spec.rb' - -# Offense count: 11 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: hash, symbol -RSpec/MetadataStyle: - Exclude: - - 'spec/examples/schema_adapter_examples.rb' - - 'spec/support/contexts.rb' - -# Offense count: 27 -RSpec/MultipleExpectations: - Max: 6 - -# Offense count: 46 -# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. -# SupportedStyles: always, named_only -RSpec/NamedSubject: - Exclude: - - 'spec/adapters/mysql2_adapter_spec.rb' - - 'spec/adapters/trilogy_adapter_spec.rb' - - 'spec/adapters/sqlite3_adapter_spec.rb' - - 'spec/support/contexts.rb' - - 'spec/support/requirements.rb' - - 'spec/tenant_spec.rb' - -# Offense count: 22 -# Configuration parameters: AllowedGroups. -RSpec/NestedGroups: - Max: 5 - -# Offense count: 1 -# Configuration parameters: AllowedPatterns. -# AllowedPatterns: ^expect_, ^assert_ -RSpec/NoExpectationExample: - Exclude: - - 'spec/tenant_spec.rb' - -# Offense count: 12 -# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata. -# Include: **/*_spec.rb -RSpec/SpecFilePathFormat: - Exclude: - - 'spec/adapters/mysql2_adapter_spec.rb' - - 'spec/adapters/trilogy_adapter_spec.rb' - - 'spec/adapters/postgresql_adapter_spec.rb' - - 'spec/adapters/sqlite3_adapter_spec.rb' - - 'spec/tenant_spec.rb' - - 'spec/unit/config_spec.rb' - - 'spec/unit/elevators/domain_spec.rb' - - 'spec/unit/elevators/first_subdomain_spec.rb' - - 'spec/unit/elevators/generic_spec.rb' - - 'spec/unit/elevators/host_hash_spec.rb' - - 'spec/unit/elevators/host_spec.rb' - - 'spec/unit/elevators/subdomain_spec.rb' - - 'spec/unit/migrator_spec.rb' - -# Offense count: 2 -# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. -RSpec/VerifiedDoubles: - Exclude: - - 'spec/integration/apartment_rake_integration_spec.rb' - - 'spec/unit/elevators/first_subdomain_spec.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Rails/IndexWith: - Exclude: - - 'lib/apartment.rb' - - 'spec/unit/config_spec.rb' - -# Offense count: 7 -# This cop supports unsafe autocorrection (--autocorrect-all). -Rails/Pluck: - Exclude: - - 'spec/adapters/jdbc_mysql_adapter_spec.rb' - - 'spec/adapters/jdbc_postgresql_adapter_spec.rb' - - 'spec/adapters/mysql2_adapter_spec.rb' - - 'spec/adapters/postgresql_adapter_spec.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Security/IoMethods: - Exclude: - - 'spec/support/config.rb' - -# Offense count: 16 -# Configuration parameters: AllowedConstants. -Style/Documentation: - Exclude: - - 'lib/apartment/adapters/jdbc_mysql_adapter.rb' - - 'lib/apartment/adapters/postgis_adapter.rb' - - 'lib/apartment/adapters/postgresql_adapter.rb' - - 'lib/apartment/adapters/sqlite3_adapter.rb' - - 'lib/apartment/custom_console.rb' - - 'lib/apartment/deprecation.rb' - - 'lib/apartment/migrator.rb' - - 'lib/apartment/model.rb' - - 'lib/apartment/railtie.rb' - - 'lib/apartment/tasks/enhancements.rb' - - 'lib/apartment/tasks/task_helper.rb' - - 'lib/generators/apartment/install/install_generator.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowedVars. -Style/FetchEnvVar: - Exclude: - - 'lib/apartment/adapters/postgresql_adapter.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -# SupportedShorthandSyntax: always, never, either, consistent -Style/HashSyntax: - Exclude: - - 'lib/apartment/active_record/connection_handling.rb' - - 'spec/integration/connection_handling_spec.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle, Autocorrect. -# SupportedStyles: module_function, extend_self, forbidden -Style/ModuleFunction: - Exclude: - - 'lib/apartment/migrator.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantConstantBase: - Exclude: - - 'spec/apartment_spec.rb' - - 'spec/dummy/config.ru' - - 'spec/dummy_engine/test/dummy/config.ru' - - 'spec/dummy_engine/test/dummy/config/environments/production.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantParentheses: - Exclude: - - 'lib/apartment.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpArgument: - Exclude: - - 'lib/apartment/tasks/enhancements.rb' - -# Offense count: 3 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. -# AllowedMethods: present?, blank?, presence, try, try! -Style/SafeNavigation: - Exclude: - - 'lib/apartment/migrator.rb' - - 'lib/tasks/apartment.rake' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/SuperWithArgsParentheses: - Exclude: - - 'lib/apartment/adapters/sqlite3_adapter.rb' - - 'lib/apartment/elevators/host_hash.rb' diff --git a/.ruby-version b/.ruby-version index a0891f56..fa7adc7a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.3.4 +3.3.5 diff --git a/Appraisals b/Appraisals index 409b47b5..7f97187f 100644 --- a/Appraisals +++ b/Appraisals @@ -1,50 +1,170 @@ # frozen_string_literal: true -appraise 'rails-6-1' do +appraise 'rails-6-1-postgresql' do gem 'rails', '~> 6.1.0' - platforms :ruby do - gem 'sqlite3', '~> 1.4' + gem 'pg', '~> 1.5' +end + +appraise 'rails-6-1-mysql' do + gem 'rails', '~> 6.1.0' + gem 'mysql2', '~> 0.5' +end + +appraise 'rails-6-1-sqlite3' do + gem 'rails', '~> 6.1.0' + gem 'sqlite3', '~> 1.4' +end + +appraise 'rails-6-1-jdbc-postgresql' do + gem 'rails', '~> 6.1.0' + platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 61.3' + gem 'activerecord-jdbcpostgresql-adapter', '~> 61.3' + gem 'jdbc-postgres' + end +end + +appraise 'rails-6-1-jdbc-mysql' do + gem 'rails', '~> 6.1.0' + platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 61.3' + gem 'activerecord-jdbcmysql-adapter', '~> 61.3' + gem 'jdbc-mysql' end +end + +appraise 'rails-6-1-jdbc-sqlite3' do + gem 'rails', '~> 6.1.0' platforms :jruby do - gem 'activerecord-jdbc-adapter', '~> 61.0' - gem 'activerecord-jdbcpostgresql-adapter', '~> 61.0' - gem 'activerecord-jdbcmysql-adapter', '~> 61.0' + gem 'activerecord-jdbc-adapter', '~> 61.3' + gem 'activerecord-jdbcsqlite3-adapter', '~> 61.3' + gem 'jdbc-sqlite3' end end -appraise 'rails-7-0' do +appraise 'rails-7-0-postgresql' do + gem 'rails', '~> 7.0.0' + gem 'pg', '~> 1.5' +end + +appraise 'rails-7-0-mysql' do + gem 'rails', '~> 7.0.0' + gem 'mysql2', '~> 0.5' +end + +appraise 'rails-7-0-sqlite3' do + gem 'rails', '~> 7.0.0' + gem 'sqlite3', '~> 1.4' +end + +appraise 'rails-7-0-jdbc-postgresql' do gem 'rails', '~> 7.0.0' - platforms :ruby do - gem 'sqlite3', '~> 1.4' - end platforms :jruby do gem 'activerecord-jdbc-adapter', '~> 70.0' gem 'activerecord-jdbcpostgresql-adapter', '~> 70.0' + gem 'jdbc-postgres' + end +end + +appraise 'rails-7-0-jdbc-mysql' do + gem 'rails', '~> 7.0.0' + platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 70.0' gem 'activerecord-jdbcmysql-adapter', '~> 70.0' + gem 'jdbc-mysql' + end +end + +appraise 'rails-7-0-jdbc-sqlite3' do + gem 'rails', '~> 7.0.0' + platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 70.0' + gem 'activerecord-jdbcsqlite3-adapter', '~> 70.0' + gem 'jdbc-sqlite3' end end -appraise 'rails-7-1' do +appraise 'rails-7-1-postgresql' do + gem 'rails', '~> 7.1.0' + gem 'pg', '~> 1.5' +end + +appraise 'rails-7-1-mysql' do gem 'rails', '~> 7.1.0' - platforms :ruby do - gem 'sqlite3', '~> 1.6' + gem 'mysql2', '~> 0.5' +end + +appraise 'rails-7-1-sqlite3' do + gem 'rails', '~> 7.1.0' + gem 'sqlite3', '~> 2.1' +end + +appraise 'rails-7-1-jdbc-postgresql' do + gem 'rails', '~> 7.1.0' + platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 70.0' + gem 'activerecord-jdbcpostgresql-adapter', '~> 70.0' + gem 'jdbc-postgres' end +end + +appraise 'rails-7-1-jdbc-mysql' do + gem 'rails', '~> 7.1.0' platforms :jruby do - gem 'activerecord-jdbc-adapter', '~> 71.0' - gem 'activerecord-jdbcpostgresql-adapter', '~> 71.0' - gem 'activerecord-jdbcmysql-adapter', '~> 71.0' + gem 'activerecord-jdbc-adapter', '~> 70.0' + gem 'activerecord-jdbcmysql-adapter', '~> 70.0' + gem 'jdbc-mysql' end end -appraise 'rails-7-2' do - gem 'rails', '~> 7.2.0' - platforms :ruby do - gem 'sqlite3', '~> 1.6' +appraise 'rails-7-1-jdbc-sqlite3' do + gem 'rails', '~> 7.1.0' + platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 70.0' + gem 'activerecord-jdbcsqlite3-adapter', '~> 70.0' + gem 'jdbc-sqlite3' end +end + +appraise 'rails-7-2-postgresql' do + gem 'rails', '~> 7.2.0' + gem 'pg', '~> 1.5' +end + +appraise 'rails-7-2-mysql' do + gem 'rails', '~> 7.2.0' + gem 'mysql2', '~> 0.5' +end + +appraise 'rails-7-2-sqlite3' do + gem 'rails', '~> 7.2.0' + gem 'sqlite3', '~> 2.1' +end + +appraise 'rails-7-2-jdbc-postgresql' do + gem 'rails', '~> 7.2.0' platforms :jruby do gem 'activerecord-jdbc-adapter', '~> 70.0' gem 'activerecord-jdbcpostgresql-adapter', '~> 70.0' + gem 'jdbc-postgres' + end +end + +appraise 'rails-7-2-jdbc-mysql' do + gem 'rails', '~> 7.2.0' + platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 70.0' gem 'activerecord-jdbcmysql-adapter', '~> 70.0' + gem 'jdbc-mysql' + end +end + +appraise 'rails-7-2-jdbc-sqlite3' do + gem 'rails', '~> 7.2.0' + platforms :jruby do + gem 'activerecord-jdbc-adapter', '~> 70.0' + gem 'activerecord-jdbcsqlite3-adapter', '~> 70.0' + gem 'jdbc-sqlite3' end end diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..71a9cb54 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,71 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a safe, welcoming, and inclusive experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +- Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +- The use of sexualized language or imagery, and sexual attention or advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others’ private information, such as a physical or email address, without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned with this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [mauricio@campusesp.com]. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. + +### 4. Permanent Ban +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1, available at https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. + +For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq. \ No newline at end of file diff --git a/Gemfile b/Gemfile index f7200f13..8503be3b 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,18 @@ source 'http://rubygems.org' gemspec + +gem 'appraisal', '~> 2.3' +gem 'bundler', '< 3.0' +gem 'pry', '~> 0.13' +gem 'rake', '< 14.0' +gem 'rspec', '~> 3.10' +gem 'rspec_junit_formatter', '~> 0.4' +gem 'rspec-rails', '>= 6.1.0', '< 8.1' +gem 'rubocop', '~> 1.12' +gem 'rubocop-performance', '~> 1.10' +gem 'rubocop-rails', '~> 2.10' +gem 'rubocop-rake', '~> 0.5' +gem 'rubocop-rspec', '~> 3.1' +gem 'rubocop-thread_safety', '~> 0.4' +gem 'simplecov', require: false diff --git a/README.md b/README.md index 220ff6a9..b13af31e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Apartment [![Gem Version](https://badge.fury.io/rb/ros-apartment.svg)](https://badge.fury.io/rb/ros-apartment) -[![Code Climate](https://api.codeclimate.com/v1/badges/b0dc327380bb8438f991/maintainability)](https://codeclimate.com/github/rails-on-services/apartment/maintainability) + *Multitenancy for Rails and ActiveRecord* @@ -9,21 +9,17 @@ Apartment provides tools to help you deal with multiple tenants in your Rails application. If you need to have certain data sequestered based on account or company, but still allow some data to exist in a common tenant, Apartment can help. -## Apartment drop in replacement gem +## Apartment Fork: ros-apartment + +This gem is a fork of the original Apartment gem, which is no longer maintained. We have continued development under the name `ros-apartment` to keep the gem up-to-date and compatible with the latest versions of Rails. `ros-apartment` is designed as a drop-in replacement for the original, allowing you to seamlessly transition your application without code changes. + +## Community Support -After having reached out via github issues and email directly, no replies ever -came. Since we wanted to upgrade our application to Rails 6 we decided to fork -and start some development to support Rails 6. Because we don't have access -to the apartment gem itself, the solution was to release it under a different -name but providing the exact same API as it was before. +This project thrives on community support. Whether you have an idea for a new feature, find a bug, or need help with `ros-apartment`, we encourage you to participate! For questions and troubleshooting, check out our [Discussions board](https://github.com/rails-on-services/apartment/discussions) to connect with the community. You can also open issues or submit pull requests directly. We are committed to maintaining `ros-apartment` and ensuring it remains a valuable tool for Rails developers. -## Help wanted +### Maintainer Update -We were never involved with the development of Apartment gem in the first place -and this project started out of our own needs. We will be more than happy -to collaborate to maintain the gem alive and supporting the latest versions -of ruby and rails, but your help is appreciated. Either by reporting bugs you -may find or proposing improvements to the gem itself. Feel free to reach out. +As of May 2024, Apartment is maintained with the support of [CampusESP](https://www.campusesp.com). We continue to keep Apartment open-source under the MIT license. We also want to recognize and thank the previous maintainers for their valuable contributions to this project. ## Installation @@ -47,10 +43,6 @@ Configure as needed using the docs below. That's all you need to set up the Apartment libraries. If you want to switch tenants on a per-user basis, look under "Usage - Switching tenants per request", below. -> NOTE: If using [postgresql schemas](http://www.postgresql.org/docs/9.0/static/ddl-schemas.html) you must use: -> -> * for Rails 3.1.x: _Rails ~> 3.1.2_, it contains a [patch](https://github.com/rails/rails/pull/3232) that makes prepared statements work with multiple schemas - ## Usage ### Video Tutorial @@ -630,24 +622,50 @@ $ APARTMENT_DISABLE_INIT=true DATABASE_URL=postgresql://localhost:1234/buk_devel # 1 ``` -## Contributing +## Contribution Guidelines + +We welcome and appreciate contributions to `ros-apartment`! Whether you want to report a bug, propose a new feature, or submit a pull request, your help keeps this project thriving. Please review the guidelines below to ensure a smooth collaboration process. + +### How to Contribute + +1. **Check Existing Issues and Discussions** + - Before opening a new issue, please check the [issue tracker](https://github.com/rails-on-services/apartment/issues) and our [Discussions board](https://github.com/rails-on-services/apartment/discussions) to see if the topic has already been reported or discussed. This helps us avoid duplication and focus on solving the issue efficiently. + +2. **Submitting a Bug Report** + - Ensure your report includes a clear description of the problem, steps to reproduce, and relevant logs or error messages. + - If possible, provide a minimal reproducible example or a failing test case that demonstrates the issue. + +3. **Proposing a Feature** + - For new features, open an issue to discuss your idea before starting development. This allows the maintainers and community to provide feedback and ensure the feature aligns with the project's goals. + - Please be as detailed as possible when describing the feature, its use case, and its potential impact on the existing functionality. + +4. **Submitting a Pull Request** + - Fork the repository and create a feature branch (`git checkout -b my-feature-branch`). + - Follow the existing code style and ensure your changes are well-documented and tested. + - Run the tests locally to verify that your changes do not introduce new issues. + - Use [Appraisal](https://github.com/thoughtbot/appraisal) to test against multiple Rails versions. Ensure all tests pass for supported Rails versions. + - Submit your pull request to the `development` branch, not `main`. + - Include a detailed description of your changes and reference any related issue numbers (e.g., "Fixes #123" or "Closes #456"). + +5. **Code Review and Merging Process** + - The maintainers will review your pull request and may provide feedback or request changes. We appreciate your patience during this process, as we strive to maintain a high standard for code quality. + - Once approved, your pull request will be merged into the `development` branch. Periodically, we merge the `development` branch into `main` for official releases. + +6. **Testing** + - Ensure your code is thoroughly tested. We do not merge code changes without adequate tests. Use RSpec for unit and integration tests. + - If your contribution affects multiple versions of Rails, use Appraisal to verify compatibility across versions. + - Rake tasks (see the Rakefile) are available to help set up your test databases and run tests. -* In both `spec/dummy/config` and `spec/config`, you will see `database.yml.sample` files - * Copy them into the same directory but with the name `database.yml` - * Edit them to fit your own settings -* Rake tasks (see the Rakefile) will help you setup your dbs necessary to run tests -* Please issue pull requests to the `development` branch. All development happens here, master is used for releases. -* Ensure that your code is accompanied with tests. No code will be merged without tests +### Code of Conduct -* If you're looking to help, check out the TODO file for some upcoming changes I'd like to implement in Apartment. +We are committed to providing a welcoming and inclusive environment for all contributors. Please review and adhere to our [Code of Conduct](CODE_OF_CONDUCT.md) when participating in the project. -### Running bundle install +### Questions and Support -mysql2 gem in some cases fails to install. -If you face problems running bundle install in OSX, try installing the gem running: +If you have any questions or need support while contributing or using `ros-apartment`, visit our [Discussions board](https://github.com/rails-on-services/apartment/discussions) to ask questions and connect with the maintainer team and community. -`gem install mysql2 -v '0.5.3' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include` +We look forward to your contributions and thank you for helping us keep `ros-apartment` a reliable and robust tool for the Rails community! ## License -Apartment is released under the [MIT License](http://www.opensource.org/licenses/MIT). +Apartment remains an open-source project under the [MIT License](http://www.opensource.org/licenses/MIT). We value open-source principles and aim to make multitenancy accessible to all Rails developers. diff --git a/Rakefile b/Rakefile index b4c66d5e..0be50f8e 100644 --- a/Rakefile +++ b/Rakefile @@ -13,7 +13,7 @@ require 'appraisal' require 'rspec' require 'rspec/core/rake_task' -RSpec::Core::RakeTask.new(spec: %w[db:copy_credentials db:test:prepare]) do |spec| +RSpec::Core::RakeTask.new(spec: %w[db:load_credentials db:test:prepare]) do |spec| spec.pattern = 'spec/**/*_spec.rb' # spec.rspec_opts = '--order rand:47078' end @@ -37,19 +37,36 @@ task default: :spec namespace :db do namespace :test do - task prepare: %w[postgres:drop_db postgres:build_db mysql:drop_db mysql:build_db] + case ENV.fetch('DATABASE_ENGINE', nil) + when 'postgresql' + task prepare: %w[postgres:drop_db postgres:build_db] + when 'mysql' + task prepare: %w[mysql:drop_db mysql:build_db] + when 'sqlite' + task :prepare do + puts 'No need to prepare sqlite3 database' + end + else + task :prepare do + puts 'No database engine specified, skipping db:test:prepare' + end + end end desc "copy sample database credential files over if real files don't exist" - task :copy_credentials do - require 'fileutils' - apartment_db_file = 'spec/config/database.yml' - rails_db_file = 'spec/dummy/config/database.yml' + task :load_credentials do + # If no DATABASE_ENGINE is specified, we default to sqlite so that a db config is generated + db_engine = ENV.fetch('DATABASE_ENGINE', 'sqlite') - unless File.exist?(apartment_db_file) - FileUtils.copy("#{apartment_db_file}.sample", apartment_db_file, verbose: true) - end - FileUtils.copy("#{rails_db_file}.sample", rails_db_file, verbose: true) unless File.exist?(rails_db_file) + next unless db_engine && %w[postgresql mysql sqlite].include?(db_engine) + + # Load and write spec db config + db_config_string = ERB.new(File.read("spec/config/#{db_engine}.yml.erb")).result + File.write('spec/config/database.yml', db_config_string) + + # Load and write dummy app db config + db_config = YAML.safe_load(db_config_string) + File.write('spec/dummy/config/database.yml', { test: db_config['connections'][db_engine] }.to_yaml) end end @@ -67,11 +84,11 @@ namespace :postgres do params << "-p#{pg_config['port']}" if pg_config['port'] begin - `createdb #{params.join(' ')}` + system("createdb #{params.join(' ')}") rescue StandardError 'test db already exists' end - ActiveRecord::Base.establish_connection pg_config + ActiveRecord::Base.establish_connection(pg_config) migrate end @@ -83,7 +100,7 @@ namespace :postgres do params << "-U#{pg_config['username']}" params << "-h#{pg_config['host']}" if pg_config['host'] params << "-p#{pg_config['port']}" if pg_config['port'] - `dropdb #{params.join(' ')}` + system("dropdb #{params.join(' ')}") end end @@ -96,14 +113,14 @@ namespace :mysql do params = [] params << "-h #{my_config['host']}" if my_config['host'] params << "-u #{my_config['username']}" if my_config['username'] - params << "-p#{my_config['password']}" if my_config['password'] - params << "--port #{my_config['port']}" if my_config['port'] + params << "-p #{my_config['password']}" if my_config['password'] + params << "-P #{my_config['port']}" if my_config['port'] begin - `mysqladmin #{params.join(' ')} create #{my_config['database']}` + system("mysqladmin #{params.join(' ')} create #{my_config['database']}") rescue StandardError 'test db already exists' end - ActiveRecord::Base.establish_connection my_config + ActiveRecord::Base.establish_connection(my_config) migrate end @@ -113,13 +130,12 @@ namespace :mysql do params = [] params << "-h #{my_config['host']}" if my_config['host'] params << "-u #{my_config['username']}" if my_config['username'] - params << "-p#{my_config['password']}" if my_config['password'] - params << "--port #{my_config['port']}" if my_config['port'] - `mysqladmin #{params.join(' ')} drop #{my_config['database']} --force` + params << "-p #{my_config['password']}" if my_config['password'] + params << "-P #{my_config['port']}" if my_config['port'] + system("mysqladmin #{params.join(' ')} drop #{my_config['database']} --force") end end -# TODO: clean this up def config Apartment::Test.config['connections'] end @@ -133,11 +149,9 @@ def my_config end def migrate - # TODO: Figure out if there is any other possibility that can/should be - # passed here as the second argument for the migration context - if ActiveRecord.version > '7.1' - ActiveRecord::MigrationContext.new('spec/dummy/db/migrate').migrate - else + if ActiveRecord.version.release < Gem::Version.new('7.1') ActiveRecord::MigrationContext.new('spec/dummy/db/migrate', ActiveRecord::SchemaMigration).migrate + else + ActiveRecord::MigrationContext.new('spec/dummy/db/migrate').migrate end end diff --git a/gemfiles/rails_6_1.gemfile b/gemfiles/rails_6_1.gemfile deleted file mode 100644 index ef48f142..00000000 --- a/gemfiles/rails_6_1.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "rails", "~> 6.1.0" - -platforms :ruby do - gem "sqlite3", "~> 1.4" -end - -platforms :jruby do - gem "activerecord-jdbc-adapter", "~> 61.0" - gem "activerecord-jdbcpostgresql-adapter", "~> 61.0" - gem "activerecord-jdbcmysql-adapter", "~> 61.0" -end - -gemspec path: "../" diff --git a/gemfiles/rails_6_1_jdbc_mysql.gemfile b/gemfiles/rails_6_1_jdbc_mysql.gemfile new file mode 100644 index 00000000..37e28ec9 --- /dev/null +++ b/gemfiles/rails_6_1_jdbc_mysql.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 6.1.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 61.3" + gem "activerecord-jdbcmysql-adapter", "~> 61.3" + gem "jdbc-mysql" +end + +gemspec path: "../" diff --git a/gemfiles/rails_6_1_jdbc_postgresql.gemfile b/gemfiles/rails_6_1_jdbc_postgresql.gemfile new file mode 100644 index 00000000..4a0af24e --- /dev/null +++ b/gemfiles/rails_6_1_jdbc_postgresql.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 6.1.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 61.3" + gem "activerecord-jdbcpostgresql-adapter", "~> 61.3" + gem "jdbc-postgres" +end + +gemspec path: "../" diff --git a/gemfiles/rails_6_1_jdbc_sqlite3.gemfile b/gemfiles/rails_6_1_jdbc_sqlite3.gemfile new file mode 100644 index 00000000..fc10e995 --- /dev/null +++ b/gemfiles/rails_6_1_jdbc_sqlite3.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 6.1.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 61.3" + gem "activerecord-jdbcsqlite3-adapter", "~> 61.3" + gem "jdbc-sqlite3" +end + +gemspec path: "../" diff --git a/gemfiles/rails_6_1_mysql.gemfile b/gemfiles/rails_6_1_mysql.gemfile new file mode 100644 index 00000000..3a89dcf1 --- /dev/null +++ b/gemfiles/rails_6_1_mysql.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 6.1.0" +gem "mysql2", "~> 0.5" + +gemspec path: "../" diff --git a/gemfiles/rails_6_1_postgresql.gemfile b/gemfiles/rails_6_1_postgresql.gemfile new file mode 100644 index 00000000..77617c8d --- /dev/null +++ b/gemfiles/rails_6_1_postgresql.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 6.1.0" +gem "pg", "~> 1.5" + +gemspec path: "../" diff --git a/gemfiles/rails_6_1_sqlite3.gemfile b/gemfiles/rails_6_1_sqlite3.gemfile new file mode 100644 index 00000000..7a85dfbb --- /dev/null +++ b/gemfiles/rails_6_1_sqlite3.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 6.1.0" +gem "sqlite3", "~> 1.4" + +gemspec path: "../" diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile deleted file mode 100644 index 2f99cfe7..00000000 --- a/gemfiles/rails_7_0.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "rails", "~> 7.0.0" - -platforms :ruby do - gem "sqlite3", "~> 1.4" -end - -platforms :jruby do - gem "activerecord-jdbc-adapter", "~> 70.0" - gem "activerecord-jdbcpostgresql-adapter", "~> 70.0" - gem "activerecord-jdbcmysql-adapter", "~> 70.0" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7_0_jdbc_mysql.gemfile b/gemfiles/rails_7_0_jdbc_mysql.gemfile new file mode 100644 index 00000000..21055ef2 --- /dev/null +++ b/gemfiles/rails_7_0_jdbc_mysql.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.0.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 70.0" + gem "activerecord-jdbcmysql-adapter", "~> 70.0" + gem "jdbc-mysql" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_0_jdbc_postgresql.gemfile b/gemfiles/rails_7_0_jdbc_postgresql.gemfile new file mode 100644 index 00000000..0e13cb9c --- /dev/null +++ b/gemfiles/rails_7_0_jdbc_postgresql.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.0.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 70.0" + gem "activerecord-jdbcpostgresql-adapter", "~> 70.0" + gem "jdbc-postgres" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_0_jdbc_sqlite3.gemfile b/gemfiles/rails_7_0_jdbc_sqlite3.gemfile new file mode 100644 index 00000000..bb3633b0 --- /dev/null +++ b/gemfiles/rails_7_0_jdbc_sqlite3.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.0.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 70.0" + gem "activerecord-jdbcsqlite3-adapter", "~> 70.0" + gem "jdbc-sqlite3" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_0_mysql.gemfile b/gemfiles/rails_7_0_mysql.gemfile new file mode 100644 index 00000000..cedaa918 --- /dev/null +++ b/gemfiles/rails_7_0_mysql.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.0.0" +gem "mysql2", "~> 0.5" + +gemspec path: "../" diff --git a/gemfiles/rails_7_0_postgresql.gemfile b/gemfiles/rails_7_0_postgresql.gemfile new file mode 100644 index 00000000..5b7dc078 --- /dev/null +++ b/gemfiles/rails_7_0_postgresql.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.0.0" +gem "pg", "~> 1.5" + +gemspec path: "../" diff --git a/gemfiles/rails_7_0_sqlite3.gemfile b/gemfiles/rails_7_0_sqlite3.gemfile new file mode 100644 index 00000000..3ec3fd8f --- /dev/null +++ b/gemfiles/rails_7_0_sqlite3.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.0.0" +gem "sqlite3", "~> 1.4" + +gemspec path: "../" diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile deleted file mode 100644 index e1e1573f..00000000 --- a/gemfiles/rails_7_1.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "rails", "~> 7.1.0" - -platforms :ruby do - gem "sqlite3", "~> 1.6" -end - -platforms :jruby do - gem "activerecord-jdbc-adapter", "~> 71.0" - gem "activerecord-jdbcpostgresql-adapter", "~> 71.0" - gem "activerecord-jdbcmysql-adapter", "~> 71.0" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7_1_jdbc_mysql.gemfile b/gemfiles/rails_7_1_jdbc_mysql.gemfile new file mode 100644 index 00000000..c7555d3e --- /dev/null +++ b/gemfiles/rails_7_1_jdbc_mysql.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.1.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 70.0" + gem "activerecord-jdbcmysql-adapter", "~> 70.0" + gem "jdbc-mysql" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_1_jdbc_postgresql.gemfile b/gemfiles/rails_7_1_jdbc_postgresql.gemfile new file mode 100644 index 00000000..f019d6dd --- /dev/null +++ b/gemfiles/rails_7_1_jdbc_postgresql.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.1.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 70.0" + gem "activerecord-jdbcpostgresql-adapter", "~> 70.0" + gem "jdbc-postgres" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_1_jdbc_sqlite3.gemfile b/gemfiles/rails_7_1_jdbc_sqlite3.gemfile new file mode 100644 index 00000000..76438213 --- /dev/null +++ b/gemfiles/rails_7_1_jdbc_sqlite3.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.1.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 70.0" + gem "activerecord-jdbcsqlite3-adapter", "~> 70.0" + gem "jdbc-sqlite3" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_1_mysql.gemfile b/gemfiles/rails_7_1_mysql.gemfile new file mode 100644 index 00000000..0effbf64 --- /dev/null +++ b/gemfiles/rails_7_1_mysql.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.1.0" +gem "mysql2", "~> 0.5" + +gemspec path: "../" diff --git a/gemfiles/rails_7_1_postgresql.gemfile b/gemfiles/rails_7_1_postgresql.gemfile new file mode 100644 index 00000000..d73e5d13 --- /dev/null +++ b/gemfiles/rails_7_1_postgresql.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.1.0" +gem "pg", "~> 1.5" + +gemspec path: "../" diff --git a/gemfiles/rails_7_1_sqlite3.gemfile b/gemfiles/rails_7_1_sqlite3.gemfile new file mode 100644 index 00000000..58fdffbb --- /dev/null +++ b/gemfiles/rails_7_1_sqlite3.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.1.0" +gem "sqlite3", "~> 2.1" + +gemspec path: "../" diff --git a/gemfiles/rails_7_2.gemfile b/gemfiles/rails_7_2.gemfile deleted file mode 100644 index 4b644dbf..00000000 --- a/gemfiles/rails_7_2.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "rails", "~> 7.2.0" - -platforms :ruby do - gem "sqlite3", "~> 1.6" -end - -platforms :jruby do - gem 'activerecord-jdbc-adapter', '~> 70.0' - gem "activerecord-jdbcpostgresql-adapter", "~> 70.0" - gem "activerecord-jdbcmysql-adapter", "~> 70.0" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7_2_jdbc_mysql.gemfile b/gemfiles/rails_7_2_jdbc_mysql.gemfile new file mode 100644 index 00000000..f1ee91f8 --- /dev/null +++ b/gemfiles/rails_7_2_jdbc_mysql.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.2.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 70.0" + gem "activerecord-jdbcmysql-adapter", "~> 70.0" + gem "jdbc-mysql" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_2_jdbc_postgresql.gemfile b/gemfiles/rails_7_2_jdbc_postgresql.gemfile new file mode 100644 index 00000000..7528caa0 --- /dev/null +++ b/gemfiles/rails_7_2_jdbc_postgresql.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.2.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 70.0" + gem "activerecord-jdbcpostgresql-adapter", "~> 70.0" + gem "jdbc-postgres" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_2_jdbc_sqlite3.gemfile b/gemfiles/rails_7_2_jdbc_sqlite3.gemfile new file mode 100644 index 00000000..a35c3869 --- /dev/null +++ b/gemfiles/rails_7_2_jdbc_sqlite3.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.2.0" + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 70.0" + gem "activerecord-jdbcsqlite3-adapter", "~> 70.0" + gem "jdbc-sqlite3" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_2_mysql.gemfile b/gemfiles/rails_7_2_mysql.gemfile new file mode 100644 index 00000000..36150e48 --- /dev/null +++ b/gemfiles/rails_7_2_mysql.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.2.0" +gem "mysql2", "~> 0.5" + +gemspec path: "../" diff --git a/gemfiles/rails_7_2_postgresql.gemfile b/gemfiles/rails_7_2_postgresql.gemfile new file mode 100644 index 00000000..49cdeebc --- /dev/null +++ b/gemfiles/rails_7_2_postgresql.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.2.0" +gem "pg", "~> 1.5" + +gemspec path: "../" diff --git a/gemfiles/rails_7_2_sqlite3.gemfile b/gemfiles/rails_7_2_sqlite3.gemfile new file mode 100644 index 00000000..67fb3c89 --- /dev/null +++ b/gemfiles/rails_7_2_sqlite3.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal", "~> 2.3" +gem "bundler", "< 3.0" +gem "pry", "~> 0.13" +gem "rake", "< 14.0" +gem "rspec", "~> 3.10" +gem "rspec_junit_formatter", "~> 0.4" +gem "rspec-rails", ">= 6.1.0", "< 8.1" +gem "rubocop", "~> 1.12" +gem "rubocop-performance", "~> 1.10" +gem "rubocop-rails", "~> 2.10" +gem "rubocop-rake", "~> 0.5" +gem "rubocop-rspec", "~> 3.1" +gem "rubocop-thread_safety", "~> 0.4" +gem "simplecov", require: false +gem "rails", "~> 7.2.0" +gem "sqlite3", "~> 2.1" + +gemspec path: "../" diff --git a/CHANGELOG.md b/legacy_CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to legacy_CHANGELOG.md diff --git a/lib/apartment/active_record/postgres/schema_dumper.rb b/lib/apartment/active_record/postgres/schema_dumper.rb index e81fde24..677fa291 100644 --- a/lib/apartment/active_record/postgres/schema_dumper.rb +++ b/lib/apartment/active_record/postgres/schema_dumper.rb @@ -1,12 +1,20 @@ +# frozen_string_literal: true + # This patch prevents `create_schema` from being added to db/schema.rb as schemas are managed by Apartment # not ActiveRecord like they would be in a vanilla Rails setup. -require "active_record/connection_adapters/abstract/schema_dumper" -require "active_record/connection_adapters/postgresql/schema_dumper" +require 'active_record/connection_adapters/abstract/schema_dumper' +require 'active_record/connection_adapters/postgresql/schema_dumper' -class ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaDumper - alias_method :_original_schemas, :schemas - def schemas(stream) - _original_schemas(stream) unless Apartment.use_schemas +module ActiveRecord + module ConnectionAdapters + module PostgreSQL + class SchemaDumper + alias _original_schemas schemas + def schemas(stream) + _original_schemas(stream) unless Apartment.use_schemas + end + end + end end end diff --git a/lib/apartment/active_record/postgresql_adapter.rb b/lib/apartment/active_record/postgresql_adapter.rb index ca0adbcb..e39c1917 100644 --- a/lib/apartment/active_record/postgresql_adapter.rb +++ b/lib/apartment/active_record/postgresql_adapter.rb @@ -19,11 +19,18 @@ def default_sequence_name(table, _column) if excluded_model?(table) default_tenant_prefix = "#{Apartment::Tenant.default_tenant}." - res.sub!(schema_prefix, default_tenant_prefix) if schema_prefix != default_tenant_prefix + # Unless the res is already prefixed with the default_tenant_prefix + # we should delete the schema_prefix and add the default_tenant_prefix + unless res&.starts_with?(default_tenant_prefix) + res&.delete_prefix!(schema_prefix) + res = default_tenant_prefix + res + end + return res end - res.delete_prefix!(schema_prefix) if res&.starts_with?(schema_prefix) + # Delete the schema_prefix from the res if it is present + res&.delete_prefix!(schema_prefix) res end diff --git a/lib/apartment/adapters/postgresql_adapter.rb b/lib/apartment/adapters/postgresql_adapter.rb index b5f50c10..c5a0b5f0 100644 --- a/lib/apartment/adapters/postgresql_adapter.rb +++ b/lib/apartment/adapters/postgresql_adapter.rb @@ -76,11 +76,6 @@ def connect_to_new(tenant = nil) @current = tenant.is_a?(Array) ? tenant.map(&:to_s) : tenant.to_s Apartment.connection.schema_search_path = full_search_path - - # When the PostgreSQL version is < 9.3, - # there is a issue for prepared statement with changing search_path. - # https://www.postgresql.org/docs/9.3/static/sql-prepare.html - Apartment.connection.clear_cache! if postgresql_version < 90_300 rescue *rescuable_exceptions => e raise_schema_connect_to_new(tenant, e) end diff --git a/ros-apartment.gemspec b/ros-apartment.gemspec index f413e49e..5d08a84c 100644 --- a/ros-apartment.gemspec +++ b/ros-apartment.gemspec @@ -7,10 +7,10 @@ Gem::Specification.new do |s| s.name = 'ros-apartment' s.version = Apartment::VERSION - s.authors = ['Ryan Brunner', 'Brad Robertson', 'Rui Baltazar'] + s.authors = ['Ryan Brunner', 'Brad Robertson', 'Rui Baltazar', 'Mauricio Novelo'] s.summary = 'A Ruby gem for managing database multitenancy. Apartment Gem drop in replacement' s.description = 'Apartment allows Rack applications to deal with database multitenancy through ActiveRecord' - s.email = ['ryan@influitive.com', 'brad@influitive.com', 'rui.p.baltazar@gmail.com'] + s.email = ['ryan@influitive.com', 'brad@influitive.com', 'rui.p.baltazar@gmail.com', 'mauricio@campusesp.com'] # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been # added into git. @@ -21,46 +21,20 @@ Gem::Specification.new do |s| end end s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) } - s.test_files = s.files.grep(%r{^(test|spec|features)/}) s.require_paths = ['lib'] s.homepage = 'https://github.com/rails-on-services/apartment' s.licenses = ['MIT'] s.metadata = { - 'github_repo' => 'ssh://github.com/rails-on-services/apartment' + 'github_repo' => 'ssh://github.com/rails-on-services/apartment', + 'rubygems_mfa_required' => 'true', } s.required_ruby_version = '>= 3.1', '<= 3.4' - s.add_dependency 'activerecord', '>= 6.1.0', '<= 8.1' - s.add_dependency 'activesupport', '>= 6.1.0' - s.add_dependency 'parallel', '< 2.0' - s.add_dependency 'public_suffix', '>= 2.0.5', '<= 6.0.1' - s.add_dependency 'rack', '>= 1.3.6', '< 4.0' - - s.add_development_dependency 'appraisal', '~> 2.2' - s.add_development_dependency 'bundler', '>= 1.3', '< 3.0' - s.add_development_dependency 'guard-rspec', '~> 4.2' - s.add_development_dependency 'pry' - s.add_development_dependency 'rake', '~> 13.0' - s.add_development_dependency 'rspec', '~> 3.4' - s.add_development_dependency 'rspec_junit_formatter' - s.add_development_dependency 'rspec-rails', '~> 6.1' - s.add_development_dependency 'rubocop', '~> 1.63' - s.add_development_dependency 'rubocop-performance', '~> 1.21' - s.add_development_dependency 'rubocop-rails', '~> 2.24' - s.add_development_dependency 'rubocop-rspec', '~> 2.29' - - if defined?(JRUBY_VERSION) - s.add_development_dependency 'activerecord-jdbc-adapter' - s.add_development_dependency 'activerecord-jdbcmysql-adapter' - s.add_development_dependency 'activerecord-jdbcpostgresql-adapter' - s.add_development_dependency 'jdbc-mysql' - s.add_development_dependency 'jdbc-postgres' - else - s.add_development_dependency 'mysql2', '~> 0.5' - s.add_development_dependency 'pg', '~> 1.5' - s.add_development_dependency 'sqlite3', '< 2.0' - s.add_development_dependency 'trilogy', '< 3.0' - end + s.add_dependency('activerecord', '>= 6.1.0', '< 8.1') + s.add_dependency('activesupport', '>= 6.1.0', '< 8.1') + s.add_dependency('parallel', '< 2.0') + s.add_dependency('public_suffix', '>= 2.0.5', '<= 6.0.1') + s.add_dependency('rack', '>= 1.3.6', '< 4.0') end diff --git a/spec/adapters/jdbc_mysql_adapter_spec.rb b/spec/adapters/jdbc_mysql_adapter_spec.rb index ece19886..7c6ad78c 100644 --- a/spec/adapters/jdbc_mysql_adapter_spec.rb +++ b/spec/adapters/jdbc_mysql_adapter_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -if defined?(JRUBY_VERSION) +if defined?(JRUBY_VERSION) && ENV['DATABASE_ENGINE'] == 'mysql' require 'spec_helper' require 'apartment/adapters/jdbc_mysql_adapter' diff --git a/spec/adapters/jdbc_postgresql_adapter_spec.rb b/spec/adapters/jdbc_postgresql_adapter_spec.rb index 4db0eb8b..7b6d02da 100644 --- a/spec/adapters/jdbc_postgresql_adapter_spec.rb +++ b/spec/adapters/jdbc_postgresql_adapter_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -if defined?(JRUBY_VERSION) +if defined?(JRUBY_VERSION) && ENV['DATABASE_ENGINE'] == 'postgresql' require 'spec_helper' require 'apartment/adapters/jdbc_postgresql_adapter' diff --git a/spec/adapters/mysql2_adapter_spec.rb b/spec/adapters/mysql2_adapter_spec.rb index 6ff7c56c..7c2eed9c 100644 --- a/spec/adapters/mysql2_adapter_spec.rb +++ b/spec/adapters/mysql2_adapter_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'spec_helper' -require 'apartment/adapters/mysql2_adapter' +if !defined?(JRUBY_VERSION) && ENV['DATABASE_ENGINE'] == 'mysql' -describe Apartment::Adapters::Mysql2Adapter, database: :mysql do - unless defined?(JRUBY_VERSION) + require 'spec_helper' + require 'apartment/adapters/mysql2_adapter' + describe Apartment::Adapters::Mysql2Adapter, database: :mysql do subject(:adapter) { Apartment::Tenant.adapter } def tenant_names diff --git a/spec/adapters/postgresql_adapter_spec.rb b/spec/adapters/postgresql_adapter_spec.rb index 841ac5e5..6cd0c61c 100644 --- a/spec/adapters/postgresql_adapter_spec.rb +++ b/spec/adapters/postgresql_adapter_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'spec_helper' -require 'apartment/adapters/postgresql_adapter' +if !defined?(JRUBY_VERSION) && ENV['DATABASE_ENGINE'] == 'postgresql' -describe Apartment::Adapters::PostgresqlAdapter, database: :postgresql do - unless defined?(JRUBY_VERSION) + require 'spec_helper' + require 'apartment/adapters/postgresql_adapter' + describe Apartment::Adapters::PostgresqlAdapter, database: :postgresql do subject { Apartment::Tenant.adapter } it_behaves_like 'a generic apartment adapter callbacks' diff --git a/spec/adapters/sqlite3_adapter_spec.rb b/spec/adapters/sqlite3_adapter_spec.rb index 339cb38c..5ae4e5cd 100644 --- a/spec/adapters/sqlite3_adapter_spec.rb +++ b/spec/adapters/sqlite3_adapter_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'spec_helper' -require 'apartment/adapters/sqlite3_adapter' +if !defined?(JRUBY_VERSION) && (ENV['DATABASE_ENGINE'] == 'sqlite' || ENV['DATABASE_ENGINE'].nil?) -describe Apartment::Adapters::Sqlite3Adapter, database: :sqlite do - unless defined?(JRUBY_VERSION) + require 'spec_helper' + require 'apartment/adapters/sqlite3_adapter' + describe Apartment::Adapters::Sqlite3Adapter, database: :sqlite do subject(:adapter) { Apartment::Tenant.adapter } it_behaves_like 'a generic apartment adapter callbacks' diff --git a/spec/adapters/trilogy_adapter_spec.rb b/spec/adapters/trilogy_adapter_spec.rb index 70f7505d..61eca4d4 100644 --- a/spec/adapters/trilogy_adapter_spec.rb +++ b/spec/adapters/trilogy_adapter_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'spec_helper' -require 'apartment/adapters/trilogy_adapter' +if !defined?(JRUBY_VERSION) && ENV['DATABASE_ENGINE'] == 'mysql' -describe Apartment::Adapters::TrilogyAdapter, database: :mysql do - unless defined?(JRUBY_VERSION) + require 'spec_helper' + require 'apartment/adapters/trilogy_adapter' + describe Apartment::Adapters::TrilogyAdapter, database: :mysql do subject(:adapter) { Apartment::Tenant.adapter } def tenant_names diff --git a/spec/config/database.yml.sample b/spec/config/database.yml.sample deleted file mode 100644 index aea46ed4..00000000 --- a/spec/config/database.yml.sample +++ /dev/null @@ -1,49 +0,0 @@ -<% if defined?(JRUBY_VERSION) %> -connections: - postgresql: - adapter: postgresql - database: apartment_postgresql_test - username: postgres - min_messages: WARNING - driver: org.postgresql.Driver - url: jdbc:postgresql://localhost:5432/apartment_postgresql_test - timeout: 5000 - pool: 5 - host: localhost - port: 5432 - - mysql: - adapter: mysql - database: apartment_mysql_test - username: root - min_messages: WARNING - driver: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/apartment_mysql_test - timeout: 5000 - pool: 5 - host: 127.0.0.1 - port: 3306 -<% else %> -connections: - postgresql: - adapter: postgresql - database: apartment_postgresql_test - min_messages: WARNING - username: postgres - schema_search_path: public - password: - host: localhost - port: 5432 - - mysql: - adapter: mysql2 - database: apartment_mysql_test - username: root - password: - host: 127.0.0.1 - port: 3306 - - sqlite: - adapter: sqlite3 - database: <%= File.expand_path('../spec/dummy/db', __FILE__) %>/test.sqlite3 -<% end %> diff --git a/spec/config/mysql.yml.erb b/spec/config/mysql.yml.erb new file mode 100644 index 00000000..8ba107e9 --- /dev/null +++ b/spec/config/mysql.yml.erb @@ -0,0 +1,14 @@ +connections: + mysql: + adapter: mysql2 + database: apartment_mysql_test + username: root + min_messages: WARNING + host: 127.0.0.1 + port: 3306 +<% if defined?(JRUBY_VERSION) %> + driver: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/apartment_mysql_test + timeout: 5000 + pool: 5 +<% end %> diff --git a/spec/config/postgresql.yml.erb b/spec/config/postgresql.yml.erb new file mode 100644 index 00000000..16fea028 --- /dev/null +++ b/spec/config/postgresql.yml.erb @@ -0,0 +1,17 @@ +connections: + postgresql: + adapter: postgresql + database: apartment_postgresql_test + username: postgres + min_messages: WARNING + host: localhost + port: 5432 +<% if defined?(JRUBY_VERSION) %> + driver: org.postgresql.Driver + url: jdbc:postgresql://localhost:5432/apartment_postgresql_test + timeout: 5000 + pool: 5 +<% else %> + schema_search_path: public + password: +<% end %> diff --git a/spec/config/sqlite.yml.erb b/spec/config/sqlite.yml.erb new file mode 100644 index 00000000..a8d41297 --- /dev/null +++ b/spec/config/sqlite.yml.erb @@ -0,0 +1,6 @@ +<% unless defined?(JRUBY_VERSION) %> +connections: + sqlite: + adapter: sqlite3 + database: <%= File.expand_path('../spec/dummy/db', __FILE__) %>/test.sqlite3 +<% end %> diff --git a/spec/dummy/config/database.yml.sample b/spec/dummy/config/database.yml.sample deleted file mode 100644 index 09067020..00000000 --- a/spec/dummy/config/database.yml.sample +++ /dev/null @@ -1,44 +0,0 @@ -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -<% if defined?(JRUBY_VERSION) %> -test: - adapter: postgresql - database: apartment_postgresql_test - username: postgres - min_messages: WARNING - driver: org.postgresql.Driver - url: jdbc:postgresql://localhost:5432/apartment_postgresql_test - timeout: 5000 - pool: 5 - -development: - adapter: postgresql - database: apartment_postgresql_development - username: postgres - min_messages: WARNING - driver: org.postgresql.Driver - url: jdbc:postgresql://localhost:5432/apartment_postgresql_development - timeout: 5000 - pool: 5 -<% else %> -test: - adapter: postgresql - database: apartment_postgresql_test - username: postgres - min_messages: WARNING - pool: 5 - timeout: 5000 - host: localhost - port: 5432 - -development: - adapter: postgresql - database: apartment_postgresql_development - username: postgres - min_messages: WARNING - pool: 5 - timeout: 5000 - host: localhost - port: 5432 -<% end %> diff --git a/spec/dummy/db/test.sqlite3 b/spec/dummy/db/test.sqlite3 deleted file mode 100644 index 50ec17fafa7d262d886a8ee4c4689c7a9c557bc2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI$O>5gQ7zc1EY3#0SunzsLvS5!HN^Jfm#|$5 z{s8?J{d(JH*b{dIr(rLbU9!Khh4ci;dVUHB``!5<$dvdPC!v>#6SmJdXD@_cjNPNV zTJBSaR|3^`CA{5yK%qwChUwROU3;P}sfhvs2tWV=e<5(C>4stO;zQFhZ5@)0SX>T+UZ|#Zbjoo42p+Tp%;|ga;_joWk z7IKz{;a4dx;&`sShyq!Xt99Qz+tZArBR(k~pDyNfU`$iB$W`R4JKe^{lJ5N2jJ!}C z(@3*8Xz0e_Aus%LPCpJmdr_d$bwk^jN3P@lBE3Sd>BjRGFIqt~Q(y8Zpwy?V9V&H&0&a0uX=z1Rwx`T@-j+H~HrA&sXpN^wED+w6aD80SG_<0uX?}&I?q| i|DDej2|@q@5P$##AaE;y^B?~N2tWV=5P-n{C-4Kw&DZh( diff --git a/spec/dummy_engine/Gemfile b/spec/dummy_engine/Gemfile index 59f9baba..53379fe9 100644 --- a/spec/dummy_engine/Gemfile +++ b/spec/dummy_engine/Gemfile @@ -14,4 +14,4 @@ gemspec # To use debugger # gem 'debugger' -gem 'apartment', path: '../../' +gem 'ros-apartment', require: 'apartment', path: '../../' diff --git a/spec/dummy_engine/config/initializers/apartment.rb b/spec/dummy_engine/config/initializers/apartment.rb index a65748eb..419f12dd 100644 --- a/spec/dummy_engine/config/initializers/apartment.rb +++ b/spec/dummy_engine/config/initializers/apartment.rb @@ -23,7 +23,7 @@ # use postgres schemas? config.use_schemas = true - # use raw SQL dumps for creating postgres schemas? (only appies with use_schemas set to true) + # use raw SQL dumps for creating postgres schemas? (only applies with use_schemas set to true) # config.use_sql = true # configure persistent schemas (E.g. hstore ) diff --git a/spec/dummy_engine/dummy_engine.gemspec b/spec/dummy_engine/dummy_engine.gemspec deleted file mode 100644 index afb00e8f..00000000 --- a/spec/dummy_engine/dummy_engine.gemspec +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -$LOAD_PATH << File.expand_path('lib', __dir__) - -# Maintain your gem's version: -require 'dummy_engine/version' - -# Describe your gem and declare its dependencies: -Gem::Specification.new do |s| - s.name = 'dummy_engine' - s.version = DummyEngine::VERSION - s.authors = ['Your name'] - s.email = ['Your email'] - s.homepage = '' - s.summary = 'Summary of DummyEngine.' - s.description = 'Description of DummyEngine.' - s.license = 'MIT' - - s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.rdoc'] - s.test_files = Dir['test/**/*'] - - s.add_dependency 'apartment' - s.add_dependency 'rails', '~> 4.1.6' - - s.add_development_dependency 'sqlite3' -end diff --git a/spec/integration/query_caching_spec.rb b/spec/integration/query_caching_spec.rb index 6026e5a1..e7a4ebdf 100644 --- a/spec/integration/query_caching_spec.rb +++ b/spec/integration/query_caching_spec.rb @@ -60,11 +60,9 @@ end after do - # Avoid cannot drop the currently open database. Maybe there is a better way to handle this. - Apartment::Tenant.switch! 'template1' + Apartment::Tenant.reset Apartment::Tenant.drop(db_name) - Apartment::Tenant.reset Company.delete_all end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ef957d40..b0c88a25 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,14 @@ # frozen_string_literal: true +if ENV['CI'].eql?('true') # ENV['CI'] defined as true by GitHub Actions + require 'simplecov' + require 'simplecov_json_formatter' + + SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter + + SimpleCov.start +end + $LOAD_PATH.unshift(File.dirname(__FILE__)) # Configure Rails Environment @@ -20,15 +29,6 @@ require 'rspec/rails' -begin - require 'pry' - # rubocop:disable Lint/ConstantDefinitionInBlock - silence_warnings { IRB = Pry } - # rubocop:enable Lint/ConstantDefinitionInBlock -rescue LoadError - nil -end - ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.default_url_options[:host] = 'test.com' @@ -36,10 +36,10 @@ Rails.backtrace_cleaner.remove_silencers! # Load support files -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f } +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } RSpec.configure do |config| - config.include Apartment::Spec::Setup + config.include(Apartment::Spec::Setup) # Somewhat brutal hack so that rails 4 postgres extensions don't modify this file # rubocop:disable RSpec/BeforeAfterAll @@ -58,7 +58,20 @@ # # Equivalent to being in spec/controllers # end config.infer_spec_type_from_file_location! + + config.filter_run_excluding(database: lambda { |engine| + case ENV.fetch('DATABASE_ENGINE', nil) + when 'mysql' + %i[sqlite postgresql].include?(engine) + when 'sqlite' + %i[mysql postgresql].include?(engine) + when 'postgresql' + %i[mysql sqlite].include?(engine) + else + false + end + }) end # Load shared examples, must happen after configure for RSpec 3 -Dir["#{File.dirname(__FILE__)}/examples/**/*.rb"].sort.each { |f| require f } +Dir["#{File.dirname(__FILE__)}/examples/**/*.rb"].each { |f| require f } diff --git a/spec/support/config.rb b/spec/support/config.rb index ce91ad1a..fd48421c 100644 --- a/spec/support/config.rb +++ b/spec/support/config.rb @@ -5,9 +5,7 @@ module Apartment module Test def self.config - # rubocop:disable Security/YAMLLoad - @config ||= YAML.load(ERB.new(IO.read('spec/config/database.yml')).result) - # rubocop:enable Security/YAMLLoad + @config ||= YAML.safe_load(ERB.new(File.read('spec/config/database.yml')).result) end end end diff --git a/spec/support/setup.rb b/spec/support/setup.rb index 030273cf..dfc2ded0 100644 --- a/spec/support/setup.rb +++ b/spec/support/setup.rb @@ -17,7 +17,7 @@ def self.included(base) def config db = RSpec.current_example.metadata.fetch(:database, :postgresql) - Apartment::Test.config['connections'][db.to_s].symbolize_keys + Apartment::Test.config['connections'][db.to_s]&.symbolize_keys end # before diff --git a/spec/tenant_spec.rb b/spec/tenant_spec.rb index 13363b9a..7292588e 100644 --- a/spec/tenant_spec.rb +++ b/spec/tenant_spec.rb @@ -8,8 +8,11 @@ describe '#adapter' do it 'should load mysql adapter' do - subject.adapter - expect(Apartment::Adapters::Mysql2Adapter).to be_a(Class) + if defined?(JRUBY_VERSION) + expect(subject.adapter).to be_a(Apartment::Adapters::JDBCMysqlAdapter) + else + expect(subject.adapter).to be_a(Apartment::Adapters::Mysql2Adapter) + end end end @@ -46,7 +49,11 @@ describe '#adapter' do it 'should load postgresql adapter' do - expect(subject.adapter).to be_a(Apartment::Adapters::PostgresqlSchemaAdapter) + if defined?(JRUBY_VERSION) + expect(subject.adapter).to be_a(Apartment::Adapters::JDBCPostgresqlSchemaAdapter) + else + expect(subject.adapter).to be_a(Apartment::Adapters::PostgresqlSchemaAdapter) + end end it 'raises exception with invalid adapter specified' do From b6652527056337e3d763b07d94b7ab2aa4e35def Mon Sep 17 00:00:00 2001 From: Mauricio Novelo <5916364+mnovelo@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:29:48 -0400 Subject: [PATCH 13/18] Fix mysql specs and add codecov (#295) --- .github/workflows/rspec_mysql_8_0.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rspec_mysql_8_0.yml b/.github/workflows/rspec_mysql_8_0.yml index d4e89fed..c24909e6 100644 --- a/.github/workflows/rspec_mysql_8_0.yml +++ b/.github/workflows/rspec_mysql_8_0.yml @@ -40,7 +40,7 @@ jobs: RAILS_VERSION: ${{ matrix.rails_version }} services: mysql: - image: mysql:8.0-alpine + image: mysql:8.0 env: MYSQL_ALLOW_EMPTY_PASSWORD: true MYSQL_DATABASE: apartment_mysql_test diff --git a/README.md b/README.md index b13af31e..ede33171 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Apartment [![Gem Version](https://badge.fury.io/rb/ros-apartment.svg)](https://badge.fury.io/rb/ros-apartment) - +[![codecov](https://codecov.io/gh/rails-on-services/apartment/graph/badge.svg?token=Q4I5QL78SA)](https://codecov.io/gh/rails-on-services/apartment) *Multitenancy for Rails and ActiveRecord* From de7662bc96552948975eda0ef3b04984440406e8 Mon Sep 17 00:00:00 2001 From: Mauricio Novelo <5916364+mnovelo@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:20:32 -0400 Subject: [PATCH 14/18] Only track lib files for code coverage (#296) --- spec/spec_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b0c88a25..f66b46e6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,7 +6,9 @@ SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter - SimpleCov.start + SimpleCov.start do + track_files('lib/**/*.rb') + end end $LOAD_PATH.unshift(File.dirname(__FILE__)) From 4a58bb33aca9c17829f7b70a62e6dc077343d1ba Mon Sep 17 00:00:00 2001 From: Mauricio Novelo <5916364+mnovelo@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:49:06 -0400 Subject: [PATCH 15/18] Filter out spec coverage (#297) --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f66b46e6..c3511ef0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,6 +8,7 @@ SimpleCov.start do track_files('lib/**/*.rb') + add_filter(%r{spec(/|\.)}) end end From ec5a9bc7aef2ba65d7c3d369ca08aa916e56f880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Gonz=C3=A1lez?= <2051199+rbngzlv@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:12:15 +0100 Subject: [PATCH 16/18] Also match custom default tenant on PSQL_DUMP_BLACKLISTED_STATEMENTS (#293) * Add failing spec creating tenant with a default tenant * Make PSQL_DUMP_BLACKLISTED_STATEMENTS work with a default tenant --------- Co-authored-by: Mauricio Novelo <5916364+mnovelo@users.noreply.github.com> --- lib/apartment/adapters/postgresql_adapter.rb | 4 ++-- spec/examples/schema_adapter_examples.rb | 21 ++++++++++++++++++++ spec/support/contexts.rb | 4 +++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/apartment/adapters/postgresql_adapter.rb b/lib/apartment/adapters/postgresql_adapter.rb index c5a0b5f0..1c41b49f 100644 --- a/lib/apartment/adapters/postgresql_adapter.rb +++ b/lib/apartment/adapters/postgresql_adapter.rb @@ -146,8 +146,8 @@ class PostgresqlSchemaFromSqlAdapter < PostgresqlSchemaAdapter /SET row_security/i, # new in postgresql 9.5 /SET idle_in_transaction_session_timeout/i, # new in postgresql 9.6 /SET default_table_access_method/i, # new in postgresql 12 - /CREATE SCHEMA public/i, - /COMMENT ON SCHEMA public/i, + /CREATE SCHEMA/i, + /COMMENT ON SCHEMA/i, /SET transaction_timeout/i, # new in postgresql 17 ].freeze diff --git a/spec/examples/schema_adapter_examples.rb b/spec/examples/schema_adapter_examples.rb index fdb955bc..452eb6f2 100644 --- a/spec/examples/schema_adapter_examples.rb +++ b/spec/examples/schema_adapter_examples.rb @@ -93,6 +93,27 @@ after { subject.drop(db) } end + + context 'with a default_tenant', default_tenant: true do + let(:from_default_tenant) { 'new_from_custom_default_tenant' } + + before do + subject.create(from_default_tenant) + end + + after do + subject.drop(from_default_tenant) + end + + it 'should correctly create the new schema' do + expect(tenant_names).to include(from_default_tenant) + end + + it 'should load schema.rb to new schema' do + connection.schema_search_path = from_default_tenant + expect(connection.tables).to include('users') + end + end end describe '#drop' do diff --git a/spec/support/contexts.rb b/spec/support/contexts.rb index 6581f8b0..6a2c2c3b 100644 --- a/spec/support/contexts.rb +++ b/spec/support/contexts.rb @@ -6,7 +6,9 @@ let(:default_tenant) { Apartment::Test.next_db } before do - Apartment::Test.create_schema(default_tenant) + # create a new tenant using apartment itself instead of Apartment::Test.create_schema + # so the default tenant also have the tables used in tests + Apartment::Tenant.create(default_tenant) Apartment.default_tenant = default_tenant end From 261a7975be295a818c0000a6b8fa2e5d22d20663 Mon Sep 17 00:00:00 2001 From: Lud Date: Tue, 7 Jan 2025 21:26:45 +0100 Subject: [PATCH 17/18] Remove upper bound for Ruby version (#307) Signed-off-by: Lud --- ros-apartment.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros-apartment.gemspec b/ros-apartment.gemspec index 5d08a84c..ecd84593 100644 --- a/ros-apartment.gemspec +++ b/ros-apartment.gemspec @@ -30,7 +30,7 @@ Gem::Specification.new do |s| 'rubygems_mfa_required' => 'true', } - s.required_ruby_version = '>= 3.1', '<= 3.4' + s.required_ruby_version = '>= 3.1' s.add_dependency('activerecord', '>= 6.1.0', '< 8.1') s.add_dependency('activesupport', '>= 6.1.0', '< 8.1') From 9d953888d60e73d7fe63be4e772b1500fca4175e Mon Sep 17 00:00:00 2001 From: Mauricio Novelo <5916364+mnovelo@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:36:43 -0500 Subject: [PATCH 18/18] Update Ruby and Apartment versions for Rails 8.0 support (#309) * Update Ruby and Apartment versions; add new gemfiles for Rails 8.0 support * Exclude testing Ruby 3.1 and Rails 8 --- .github/workflows/rspec_mysql_8_0.yml | 7 +- .github/workflows/rspec_pg_14.yml | 7 +- .github/workflows/rspec_pg_15.yml | 7 +- .github/workflows/rspec_pg_16.yml | 6 +- .github/workflows/rspec_pg_17.yml | 7 +- .github/workflows/rspec_sqlite_3.yml | 15 ++-- .ruby-version | 2 +- Appraisals | 70 +++---------------- gemfiles/rails_7_1_jdbc_postgresql.gemfile | 27 ------- gemfiles/rails_7_1_jdbc_sqlite3.gemfile | 27 ------- gemfiles/rails_7_2_jdbc_postgresql.gemfile | 27 ------- ..._mysql.gemfile => rails_8_0_mysql.gemfile} | 9 +-- ...l.gemfile => rails_8_0_postgresql.gemfile} | 9 +-- ...ite3.gemfile => rails_8_0_sqlite3.gemfile} | 9 +-- lib/apartment/version.rb | 2 +- 15 files changed, 56 insertions(+), 175 deletions(-) delete mode 100644 gemfiles/rails_7_1_jdbc_postgresql.gemfile delete mode 100644 gemfiles/rails_7_1_jdbc_sqlite3.gemfile delete mode 100644 gemfiles/rails_7_2_jdbc_postgresql.gemfile rename gemfiles/{rails_7_1_jdbc_mysql.gemfile => rails_8_0_mysql.gemfile} (75%) rename gemfiles/{rails_7_2_jdbc_mysql.gemfile => rails_8_0_postgresql.gemfile} (75%) rename gemfiles/{rails_7_2_jdbc_sqlite3.gemfile => rails_8_0_sqlite3.gemfile} (75%) diff --git a/.github/workflows/rspec_mysql_8_0.yml b/.github/workflows/rspec_mysql_8_0.yml index c24909e6..bc8b1b79 100644 --- a/.github/workflows/rspec_mysql_8_0.yml +++ b/.github/workflows/rspec_mysql_8_0.yml @@ -20,18 +20,23 @@ jobs: - 3.1 - 3.2 - 3.3 + - 3.4 - jruby rails_version: - 6_1 - 7_0 - 7_1 - 7_2 - # - master # versions failing + - 8_0 exclude: - ruby_version: jruby rails_version: 7_1 - ruby_version: jruby rails_version: 7_2 + - ruby_version: jruby + rails_version: 8_0 + - ruby_version: 3.1 + rails_version: 8_0 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_mysql.gemfile CI: true diff --git a/.github/workflows/rspec_pg_14.yml b/.github/workflows/rspec_pg_14.yml index dc9029ac..3a1e42cd 100644 --- a/.github/workflows/rspec_pg_14.yml +++ b/.github/workflows/rspec_pg_14.yml @@ -20,18 +20,23 @@ jobs: - 3.1 - 3.2 - 3.3 + - 3.4 - jruby rails_version: - 6_1 - 7_0 - 7_1 - 7_2 - # - master # versions failing + - 8_0 exclude: - ruby_version: jruby rails_version: 7_1 - ruby_version: jruby rails_version: 7_2 + - ruby_version: jruby + rails_version: 8_0 + - ruby_version: 3.1 + rails_version: 8_0 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_postgresql.gemfile CI: true diff --git a/.github/workflows/rspec_pg_15.yml b/.github/workflows/rspec_pg_15.yml index a6d2c41d..15423ebf 100644 --- a/.github/workflows/rspec_pg_15.yml +++ b/.github/workflows/rspec_pg_15.yml @@ -20,18 +20,23 @@ jobs: - 3.1 - 3.2 - 3.3 + - 3.4 - jruby rails_version: - 6_1 - 7_0 - 7_1 - 7_2 - # - master # versions failing + - 8_0 exclude: - ruby_version: jruby rails_version: 7_1 - ruby_version: jruby rails_version: 7_2 + - ruby_version: jruby + rails_version: 8_0 + - ruby_version: 3.1 + rails_version: 8_0 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_postgresql.gemfile CI: true diff --git a/.github/workflows/rspec_pg_16.yml b/.github/workflows/rspec_pg_16.yml index 9fd2071f..06f498c6 100644 --- a/.github/workflows/rspec_pg_16.yml +++ b/.github/workflows/rspec_pg_16.yml @@ -20,18 +20,22 @@ jobs: - 3.1 - 3.2 - 3.3 + - 3.4 - jruby rails_version: - 6_1 - 7_0 - 7_1 - 7_2 - # - master # versions failing exclude: - ruby_version: jruby rails_version: 7_1 - ruby_version: jruby rails_version: 7_2 + - ruby_version: jruby + rails_version: 8_0 + - ruby_version: 3.1 + rails_version: 8_0 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_postgresql.gemfile CI: true diff --git a/.github/workflows/rspec_pg_17.yml b/.github/workflows/rspec_pg_17.yml index 349a5fe7..83bb406c 100644 --- a/.github/workflows/rspec_pg_17.yml +++ b/.github/workflows/rspec_pg_17.yml @@ -20,18 +20,23 @@ jobs: - 3.1 - 3.2 - 3.3 + - 3.4 - jruby rails_version: - 6_1 - 7_0 - 7_1 - 7_2 - # - master # versions failing + - 8_0 exclude: - ruby_version: jruby rails_version: 7_1 - ruby_version: jruby rails_version: 7_2 + - ruby_version: jruby + rails_version: 8_0 + - ruby_version: 3.1 + rails_version: 8_0 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_postgresql.gemfile CI: true diff --git a/.github/workflows/rspec_sqlite_3.yml b/.github/workflows/rspec_sqlite_3.yml index 964e96e4..518d3916 100644 --- a/.github/workflows/rspec_sqlite_3.yml +++ b/.github/workflows/rspec_sqlite_3.yml @@ -20,18 +20,23 @@ jobs: - 3.1 - 3.2 - 3.3 + - 3.4 # - jruby # We don't support jruby for sqlite yet rails_version: - 6_1 - 7_0 - 7_1 - 7_2 - # - master # versions failing + - 8_0 exclude: - - ruby_version: jruby - rails_version: 7_1 - - ruby_version: jruby - rails_version: 7_2 + - ruby_version: 3.1 + rails_version: 8_0 + # - ruby_version: jruby + # rails_version: 7_1 + # - ruby_version: jruby + # rails_version: 7_2 + # - ruby_version: jruby + # rails_version: 8_0 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}${{ matrix.ruby_version == 'jruby' && '_jdbc' || '' }}_sqlite3.gemfile CI: true diff --git a/.ruby-version b/.ruby-version index fa7adc7a..9c25013d 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.3.5 +3.3.6 diff --git a/Appraisals b/Appraisals index 7f97187f..988b32c8 100644 --- a/Appraisals +++ b/Appraisals @@ -99,33 +99,6 @@ appraise 'rails-7-1-sqlite3' do gem 'sqlite3', '~> 2.1' end -appraise 'rails-7-1-jdbc-postgresql' do - gem 'rails', '~> 7.1.0' - platforms :jruby do - gem 'activerecord-jdbc-adapter', '~> 70.0' - gem 'activerecord-jdbcpostgresql-adapter', '~> 70.0' - gem 'jdbc-postgres' - end -end - -appraise 'rails-7-1-jdbc-mysql' do - gem 'rails', '~> 7.1.0' - platforms :jruby do - gem 'activerecord-jdbc-adapter', '~> 70.0' - gem 'activerecord-jdbcmysql-adapter', '~> 70.0' - gem 'jdbc-mysql' - end -end - -appraise 'rails-7-1-jdbc-sqlite3' do - gem 'rails', '~> 7.1.0' - platforms :jruby do - gem 'activerecord-jdbc-adapter', '~> 70.0' - gem 'activerecord-jdbcsqlite3-adapter', '~> 70.0' - gem 'jdbc-sqlite3' - end -end - appraise 'rails-7-2-postgresql' do gem 'rails', '~> 7.2.0' gem 'pg', '~> 1.5' @@ -141,42 +114,17 @@ appraise 'rails-7-2-sqlite3' do gem 'sqlite3', '~> 2.1' end -appraise 'rails-7-2-jdbc-postgresql' do - gem 'rails', '~> 7.2.0' - platforms :jruby do - gem 'activerecord-jdbc-adapter', '~> 70.0' - gem 'activerecord-jdbcpostgresql-adapter', '~> 70.0' - gem 'jdbc-postgres' - end +appraise 'rails-8-0-postgresql' do + gem 'rails', '~> 8.0.0' + gem 'pg', '~> 1.5' end -appraise 'rails-7-2-jdbc-mysql' do - gem 'rails', '~> 7.2.0' - platforms :jruby do - gem 'activerecord-jdbc-adapter', '~> 70.0' - gem 'activerecord-jdbcmysql-adapter', '~> 70.0' - gem 'jdbc-mysql' - end +appraise 'rails-8-0-mysql' do + gem 'rails', '~> 8.0.0' + gem 'mysql2', '~> 0.5' end -appraise 'rails-7-2-jdbc-sqlite3' do - gem 'rails', '~> 7.2.0' - platforms :jruby do - gem 'activerecord-jdbc-adapter', '~> 70.0' - gem 'activerecord-jdbcsqlite3-adapter', '~> 70.0' - gem 'jdbc-sqlite3' - end +appraise 'rails-8-0-sqlite3' do + gem 'rails', '~> 8.0.0' + gem 'sqlite3', '~> 2.1' end - -# Install Rails from the main branch are failing -# appraise 'rails-master' do -# gem 'rails', git: 'https://github.com/rails/rails.git' -# platforms :ruby do -# gem 'sqlite3', '~> 2.0' -# end -# platforms :jruby do -# gem 'activerecord-jdbc-adapter', '~> 61.0' -# gem 'activerecord-jdbcpostgresql-adapter', '~> 61.0' -# gem 'activerecord-jdbcmysql-adapter', '~> 61.0' -# end -# end diff --git a/gemfiles/rails_7_1_jdbc_postgresql.gemfile b/gemfiles/rails_7_1_jdbc_postgresql.gemfile deleted file mode 100644 index f019d6dd..00000000 --- a/gemfiles/rails_7_1_jdbc_postgresql.gemfile +++ /dev/null @@ -1,27 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "appraisal", "~> 2.3" -gem "bundler", "< 3.0" -gem "pry", "~> 0.13" -gem "rake", "< 14.0" -gem "rspec", "~> 3.10" -gem "rspec_junit_formatter", "~> 0.4" -gem "rspec-rails", ">= 6.1.0", "< 8.1" -gem "rubocop", "~> 1.12" -gem "rubocop-performance", "~> 1.10" -gem "rubocop-rails", "~> 2.10" -gem "rubocop-rake", "~> 0.5" -gem "rubocop-rspec", "~> 3.1" -gem "rubocop-thread_safety", "~> 0.4" -gem "simplecov", require: false -gem "rails", "~> 7.1.0" - -platforms :jruby do - gem "activerecord-jdbc-adapter", "~> 70.0" - gem "activerecord-jdbcpostgresql-adapter", "~> 70.0" - gem "jdbc-postgres" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7_1_jdbc_sqlite3.gemfile b/gemfiles/rails_7_1_jdbc_sqlite3.gemfile deleted file mode 100644 index 76438213..00000000 --- a/gemfiles/rails_7_1_jdbc_sqlite3.gemfile +++ /dev/null @@ -1,27 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "appraisal", "~> 2.3" -gem "bundler", "< 3.0" -gem "pry", "~> 0.13" -gem "rake", "< 14.0" -gem "rspec", "~> 3.10" -gem "rspec_junit_formatter", "~> 0.4" -gem "rspec-rails", ">= 6.1.0", "< 8.1" -gem "rubocop", "~> 1.12" -gem "rubocop-performance", "~> 1.10" -gem "rubocop-rails", "~> 2.10" -gem "rubocop-rake", "~> 0.5" -gem "rubocop-rspec", "~> 3.1" -gem "rubocop-thread_safety", "~> 0.4" -gem "simplecov", require: false -gem "rails", "~> 7.1.0" - -platforms :jruby do - gem "activerecord-jdbc-adapter", "~> 70.0" - gem "activerecord-jdbcsqlite3-adapter", "~> 70.0" - gem "jdbc-sqlite3" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7_2_jdbc_postgresql.gemfile b/gemfiles/rails_7_2_jdbc_postgresql.gemfile deleted file mode 100644 index 7528caa0..00000000 --- a/gemfiles/rails_7_2_jdbc_postgresql.gemfile +++ /dev/null @@ -1,27 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "appraisal", "~> 2.3" -gem "bundler", "< 3.0" -gem "pry", "~> 0.13" -gem "rake", "< 14.0" -gem "rspec", "~> 3.10" -gem "rspec_junit_formatter", "~> 0.4" -gem "rspec-rails", ">= 6.1.0", "< 8.1" -gem "rubocop", "~> 1.12" -gem "rubocop-performance", "~> 1.10" -gem "rubocop-rails", "~> 2.10" -gem "rubocop-rake", "~> 0.5" -gem "rubocop-rspec", "~> 3.1" -gem "rubocop-thread_safety", "~> 0.4" -gem "simplecov", require: false -gem "rails", "~> 7.2.0" - -platforms :jruby do - gem "activerecord-jdbc-adapter", "~> 70.0" - gem "activerecord-jdbcpostgresql-adapter", "~> 70.0" - gem "jdbc-postgres" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7_1_jdbc_mysql.gemfile b/gemfiles/rails_8_0_mysql.gemfile similarity index 75% rename from gemfiles/rails_7_1_jdbc_mysql.gemfile rename to gemfiles/rails_8_0_mysql.gemfile index c7555d3e..43b119cc 100644 --- a/gemfiles/rails_7_1_jdbc_mysql.gemfile +++ b/gemfiles/rails_8_0_mysql.gemfile @@ -16,12 +16,7 @@ gem "rubocop-rake", "~> 0.5" gem "rubocop-rspec", "~> 3.1" gem "rubocop-thread_safety", "~> 0.4" gem "simplecov", require: false -gem "rails", "~> 7.1.0" - -platforms :jruby do - gem "activerecord-jdbc-adapter", "~> 70.0" - gem "activerecord-jdbcmysql-adapter", "~> 70.0" - gem "jdbc-mysql" -end +gem "rails", "~> 8.0.0" +gem "mysql2", "~> 0.5" gemspec path: "../" diff --git a/gemfiles/rails_7_2_jdbc_mysql.gemfile b/gemfiles/rails_8_0_postgresql.gemfile similarity index 75% rename from gemfiles/rails_7_2_jdbc_mysql.gemfile rename to gemfiles/rails_8_0_postgresql.gemfile index f1ee91f8..f5b82c2f 100644 --- a/gemfiles/rails_7_2_jdbc_mysql.gemfile +++ b/gemfiles/rails_8_0_postgresql.gemfile @@ -16,12 +16,7 @@ gem "rubocop-rake", "~> 0.5" gem "rubocop-rspec", "~> 3.1" gem "rubocop-thread_safety", "~> 0.4" gem "simplecov", require: false -gem "rails", "~> 7.2.0" - -platforms :jruby do - gem "activerecord-jdbc-adapter", "~> 70.0" - gem "activerecord-jdbcmysql-adapter", "~> 70.0" - gem "jdbc-mysql" -end +gem "rails", "~> 8.0.0" +gem "pg", "~> 1.5" gemspec path: "../" diff --git a/gemfiles/rails_7_2_jdbc_sqlite3.gemfile b/gemfiles/rails_8_0_sqlite3.gemfile similarity index 75% rename from gemfiles/rails_7_2_jdbc_sqlite3.gemfile rename to gemfiles/rails_8_0_sqlite3.gemfile index a35c3869..b5b4fa5f 100644 --- a/gemfiles/rails_7_2_jdbc_sqlite3.gemfile +++ b/gemfiles/rails_8_0_sqlite3.gemfile @@ -16,12 +16,7 @@ gem "rubocop-rake", "~> 0.5" gem "rubocop-rspec", "~> 3.1" gem "rubocop-thread_safety", "~> 0.4" gem "simplecov", require: false -gem "rails", "~> 7.2.0" - -platforms :jruby do - gem "activerecord-jdbc-adapter", "~> 70.0" - gem "activerecord-jdbcsqlite3-adapter", "~> 70.0" - gem "jdbc-sqlite3" -end +gem "rails", "~> 8.0.0" +gem "sqlite3", "~> 2.1" gemspec path: "../" diff --git a/lib/apartment/version.rb b/lib/apartment/version.rb index d9cde4b4..f22d226b 100644 --- a/lib/apartment/version.rb +++ b/lib/apartment/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Apartment - VERSION = '3.1.0' + VERSION = '3.2.0' end