Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare Release 2.5.0 #44

Merged
merged 50 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
841fbca
support rails 6.1, remove warnings
jean-francois-labbe Feb 13, 2020
54c9c72
fix rubocop
jean-francois-labbe Mar 23, 2020
504588e
Merge pull request #7 from jean-francois-labbe/fix-rails-6-1
rpbaltazar Apr 2, 2020
fa0f0f0
[#11] Remove old ruby and rails versions from the supported versions
rpbaltazar Mar 22, 2020
91b1d68
Fixing rubocop vesion and ignoring gemfiles
rpbaltazar Mar 22, 2020
ad32b08
[CI] removed unused exclusions
rpbaltazar Apr 2, 2020
d527441
[Chore] ran rubocop safe autocorrect
rpbaltazar Apr 2, 2020
b609d48
Remove test related files from gem
rpbaltazar Apr 2, 2020
23bcbbd
[Chore] fixed rubocop warning
rpbaltazar Apr 2, 2020
2e0256b
[Chore] refactored files to their names
rpbaltazar Apr 7, 2020
3213a4e
[Chore] removed commented block
rpbaltazar Apr 7, 2020
155f788
[i-27] Added tenant_connected_to to replace active record base connec…
rpbaltazar Apr 3, 2020
12cc206
[i-27] removed special method for switching tenant and adding alias f…
rpbaltazar Apr 3, 2020
2780a1e
[i-27] fix rubocop
rpbaltazar Apr 3, 2020
d145a51
[i-27] moving monkeypatches to their folders
rpbaltazar Apr 6, 2020
0595ff0
[i-27] Adding apartment model that resolves arel table based on apart…
rpbaltazar Apr 6, 2020
e50e324
[i-27] skiping table name modification if not using schemas
rpbaltazar Apr 7, 2020
b513bd8
[i-27] removed commented code
rpbaltazar Apr 7, 2020
72c0c32
[i-27] using config to enable schema prepend
rpbaltazar Apr 7, 2020
ed71488
[i-27] added prepend_tenant_name config to spec
rpbaltazar Apr 7, 2020
94de7f6
[i-27] renamed method
rpbaltazar Apr 7, 2020
2d1819d
[i-27] attempt to run tests with apartment model
rpbaltazar Apr 7, 2020
421d825
[i-27] updating test
rpbaltazar Apr 7, 2020
651288c
[i-27] creating schema
rpbaltazar Apr 7, 2020
be771ed
[i-27] fix test setup
rpbaltazar Apr 7, 2020
79e07f4
[i-27] fix failing test
rpbaltazar Apr 7, 2020
6e61591
[i-27] duplicate test coverage for jdbc postgresql adapter
rpbaltazar Apr 7, 2020
23e9e1e
[i-27] fix rubocop
rpbaltazar Apr 7, 2020
d3e695e
[i-27] updated readme
rpbaltazar Apr 7, 2020
27fc97a
[i-27] remove extra whitespaces
rpbaltazar Apr 7, 2020
29c7434
[i-27] for some reason there is an extra space in the output of to_sql
rpbaltazar Apr 7, 2020
f5b833f
using the other approach for updating the tenant based on the connect…
rpbaltazar Apr 8, 2020
55368fb
Fixed loading path
rpbaltazar Apr 8, 2020
c6eda8e
patch postgresql arel visit table to determine which schema to use
rpbaltazar Apr 8, 2020
f78afc9
cached find by statement to use tenant for cache key
rpbaltazar Apr 8, 2020
b0ad53c
Address rubocop errors
rpbaltazar Apr 8, 2020
b6bdcdf
Fixed failing specs
rpbaltazar Apr 8, 2020
d141639
Fixed cache key format. Added notes on cached find_by_statement
rpbaltazar Apr 9, 2020
ff12543
[Resolves #27] Some errors were being thrown due to caching issues
rpbaltazar Apr 9, 2020
5d76a8c
[#31] Updated travis ruby versions
rpbaltazar Apr 8, 2020
0ba04de
[#31] Added jruby head to test matrix
rpbaltazar Apr 8, 2020
6d754f5
[#31] Excluding 2.4.10 and rails 6 combination
rpbaltazar Apr 8, 2020
80bb3a4
[#31] Using bundler 2.x
rpbaltazar Apr 8, 2020
e260dfc
[#31] relaxed bundler development dependency
rpbaltazar Apr 9, 2020
8b32e93
[Resolves #31] Add latest ruby verisons to test matrix
rpbaltazar Apr 9, 2020
8b4723d
[#35] update cache key to use a string or an array depending on what …
rpbaltazar Apr 9, 2020
8439fc4
[Resolves #35] update cache key to use a string or an array
rpbaltazar Apr 9, 2020
b27311d
Added before hook to connected to to try to set the tenant
rpbaltazar Apr 14, 2020
3fa374a
[Chore] Removed references to allow prepend tenant name
rpbaltazar Apr 15, 2020
b19ba24
[Resolves #27] Added before hook to connected to to try to set the te…
rpbaltazar Apr 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ inherit_gem:
perx-rubocop:
- default.yml

AllCops:
Exclude:
- 'gemfiles/**/*.gemfile'

Style/WordArray:
Exclude:
- spec/schemas/**/*.rb
Expand Down
38 changes: 8 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ services:
- docker
rvm:
- jruby-9.2.11.0
- 2.1.9
- 2.2.9
- 2.3.6
- 2.4.3
- 2.5.0
- 2.6.2
- 2.4.10
- 2.5.8
- 2.6.6
- 2.7.1
- jruby-head
- ruby-head

branches:
Expand All @@ -19,48 +18,27 @@ branches:
- development

gemfile:
- gemfiles/rails_4_2.gemfile
- gemfiles/rails_5_0.gemfile
- gemfiles/rails_5_1.gemfile
- gemfiles/rails_5_2.gemfile
- gemfiles/rails_6_0.gemfile
- gemfiles/rails_master.gemfile

bundler_args: --without local
before_install:
- sudo /etc/init.d/mysql stop
- sudo /etc/init.d/postgresql stop
- docker-compose up -d
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
- gem uninstall bundler -v '>= 2' -x || true
- gem install bundler -v '< 2'
env:
RUBY_GC_MALLOC_LIMIT: 90000000
RUBY_GC_HEAP_FREE_SLOTS: 200000
jobs:
allow_failures:
- rvm: ruby-head
- rvm: jruby-head
- gemfile: gemfiles/rails_master.gemfile
- rvm: 2.2.9
gemfile: gemfiles/rails_5_2.gemfile
# JRuby does not provide support for anything below rails 5
- rvm: jruby-9.2.11.0
gemfile: gemfiles/rails_4_2.gemfile
exclude:
- rvm: 2.1.9
gemfile: gemfiles/rails_5_0.gemfile
- rvm: 2.1.9
gemfile: gemfiles/rails_5_1.gemfile
- rvm: 2.1.9
gemfile: gemfiles/rails_5_2.gemfile
- rvm: 2.1.9
gemfile: gemfiles/rails_6_0.gemfile
- rvm: 2.1.9
gemfile: gemfiles/rails_master.gemfile
- rvm: 2.2.9
gemfile: gemfiles/rails_6_0.gemfile
- rvm: 2.3.6
gemfile: gemfiles/rails_6_0.gemfile
- rvm: 2.4.3
- rvm: 2.4.10
gemfile: gemfiles/rails_6_0.gemfile
fast_finish: true
cache: bundler
21 changes: 4 additions & 17 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
# frozen_string_literal: true

appraise 'rails-4-2' do
gem 'rails', '~> 4.2.0'
platforms :ruby do
gem 'pg', '< 1.0.0'
gem 'mysql2', '~> 0.4.0'
end
platforms :jruby do
gem 'activerecord-jdbc-adapter', '~> 1.3'
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
end
end

appraise 'rails-5-0' do
gem 'rails', '~> 5.0.0'
platforms :ruby do
Expand Down Expand Up @@ -47,14 +34,14 @@ appraise 'rails-5-2' do
end

appraise 'rails-6-0' do
gem 'rails', '~> 6.0.0.rc1'
gem 'rails', '~> 6.0.0'
platforms :ruby do
gem 'sqlite3', '~> 1.4'
end
platforms :jruby do
gem 'activerecord-jdbc-adapter', '~> 60.0.rc1'
gem 'activerecord-jdbcpostgresql-adapter', '~> 60.0.rc1'
gem 'activerecord-jdbcmysql-adapter', '~> 60.0.rc1'
gem 'activerecord-jdbc-adapter', '~> 60.0'
gem 'activerecord-jdbcpostgresql-adapter', '~> 60.0'
gem 'activerecord-jdbcmysql-adapter', '~> 60.0'
end
end

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ source 'http://rubygems.org'

gemspec

gem 'rails', '>= 3.1.2'
gem 'perx-rubocop', '~> 0.0.3'
gem 'rails', '>= 3.1.2'

group :local do
gem 'guard-rspec', '~> 4.2'
Expand Down
4 changes: 3 additions & 1 deletion Guardfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :rspec do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/apartment/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
watch(%r{^lib/apartment/(.+)\.rb$}) { |m| "spec/integration/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch('spec/spec_helper.rb') { 'spec' }

# # Rails example
# watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
Expand Down
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,20 @@ Rails will always access the 'public' tenant when accessing these models, but no

### Postgresql Schemas

## Providing a Different default_schema
#### Alternative: Creating new schemas by using raw SQL dumps

Apartment can be forced to use raw SQL dumps insted of `schema.rb` for creating new schemas. Use this when you are using some extra features in postgres that can't be represented in `schema.rb`, like materialized views etc.

This only applies while using postgres adapter and `config.use_schemas` is set to `true`.
(Note: this option doesn't use `db/structure.sql`, it creates SQL dump by executing `pg_dump`)

Enable this option with:

```ruby
config.use_sql = true
```

### Providing a Different default_schema

By default, ActiveRecord will use `"$user", public` as the default `schema_search_path`. This can be modified if you wish to use a different default schema be setting:

Expand All @@ -351,7 +364,7 @@ config.default_schema = "some_other_schema"

With that set, all excluded models will use this schema as the table name prefix instead of `public` and `reset` on `Apartment::Tenant` will return to this schema as well.

## Persistent Schemas
### Persistent Schemas

Apartment will normally just switch the `schema_search_path` whole hog to the one passed in. This can lead to problems if you want other schemas to always be searched as well. Enter `persistent_schemas`. You can configure a list of other schemas that will always remain in the search path, while the default gets swapped out:

Expand Down Expand Up @@ -457,18 +470,6 @@ schema in the `search_path` at all times. We won't be able to do this though unt
also contain the tenanted tables, which is an open issue with no real milestone to be completed.
Happy to accept PR's on the matter.

#### Alternative: Creating new schemas by using raw SQL dumps

Apartment can be forced to use raw SQL dumps insted of `schema.rb` for creating new schemas. Use this when you are using some extra features in postgres that can't be represented in `schema.rb`, like materialized views etc.

This only applies while using postgres adapter and `config.use_schemas` is set to `true`.
(Note: this option doesn't use `db/structure.sql`, it creates SQL dump by executing `pg_dump`)

Enable this option with:
```ruby
config.use_sql = true
```

### Managing Migrations

In order to migrate all of your tenants (or postgresql schemas) you need to provide a list
Expand Down
56 changes: 34 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
require 'bundler' rescue 'You must `gem install bundler` and `bundle install` to run rake tasks'
# frozen_string_literal: true

begin
require 'bundler'
rescue StandardError
'You must `gem install bundler` and `bundle install` to run rake tasks'
end
Bundler.setup
Bundler::GemHelper.install_tasks

require 'appraisal'

require "rspec"
require "rspec/core/rake_task"
require 'rspec'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec => %w{ db:copy_credentials db:test:prepare }) do |spec|
spec.pattern = "spec/**/*_spec.rb"
RSpec::Core::RakeTask.new(spec: %w[db:copy_credentials db:test:prepare]) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
# spec.rspec_opts = '--order rand:47078'
end

namespace :spec do
[:tasks, :unit, :adapters, :integration].each do |type|
%i[tasks unit adapters integration].each do |type|
RSpec::Core::RakeTask.new(type => :spec) do |spec|
spec.pattern = "spec/#{type}/**/*_spec.rb"
end
Expand All @@ -27,11 +33,11 @@ task :console do
Pry.start
end

task :default => :spec
task default: :spec

namespace :db do
namespace :test do
task :prepare => %w{postgres:drop_db postgres:build_db mysql:drop_db mysql:build_db}
task prepare: %w[postgres:drop_db postgres:build_db mysql:drop_db mysql:build_db]
end

desc "copy sample database credential files over if real files don't exist"
Expand All @@ -40,44 +46,47 @@ namespace :db do
apartment_db_file = 'spec/config/database.yml'
rails_db_file = 'spec/dummy/config/database.yml'

FileUtils.copy(apartment_db_file + '.sample', apartment_db_file, :verbose => true) unless File.exists?(apartment_db_file)
FileUtils.copy(rails_db_file + '.sample', rails_db_file, :verbose => true) unless File.exists?(rails_db_file)
FileUtils.copy(apartment_db_file + '.sample', apartment_db_file, verbose: true) unless File.exist?(apartment_db_file)
FileUtils.copy(rails_db_file + '.sample', rails_db_file, verbose: true) unless File.exist?(rails_db_file)
end
end

namespace :postgres do
require 'active_record'
require "#{File.join(File.dirname(__FILE__), 'spec', 'support', 'config')}"
require File.join(File.dirname(__FILE__), 'spec', 'support', 'config').to_s

desc 'Build the PostgreSQL test databases'
task :build_db do
params = []
params << "-E UTF8"
params << '-E UTF8'
params << pg_config['database']
params << "-U#{pg_config['username']}"
params << "-h#{pg_config['host']}" if pg_config['host']
params << "-p#{pg_config['port']}" if pg_config['port']
%x{ createdb #{params.join(' ')} } rescue "test db already exists"
begin
`createdb #{params.join(' ')}`
rescue StandardError
'test db already exists'
end
ActiveRecord::Base.establish_connection pg_config
migrate
end

desc "drop the PostgreSQL test database"
desc 'drop the PostgreSQL test database'
task :drop_db do
puts "dropping database #{pg_config['database']}"
params = []
params << pg_config['database']
params << "-U#{pg_config['username']}"
params << "-h#{pg_config['host']}" if pg_config['host']
params << "-p#{pg_config['port']}" if pg_config['port']
%x{ dropdb #{params.join(' ')} }
`dropdb #{params.join(' ')}`
end

end

namespace :mysql do
require 'active_record'
require "#{File.join(File.dirname(__FILE__), 'spec', 'support', 'config')}"
require File.join(File.dirname(__FILE__), 'spec', 'support', 'config').to_s

desc 'Build the MySQL test databases'
task :build_db do
Expand All @@ -86,25 +95,28 @@ namespace :mysql do
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']
%x{ mysqladmin #{params.join(' ')} create #{my_config['database']} } rescue "test db already exists"
begin
`mysqladmin #{params.join(' ')} create #{my_config['database']}`
rescue StandardError
'test db already exists'
end
ActiveRecord::Base.establish_connection my_config
migrate
end

desc "drop the MySQL test database"
desc 'drop the MySQL test database'
task :drop_db do
puts "dropping database #{my_config['database']}"
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']
%x{ mysqladmin #{params.join(' ')} drop #{my_config['database']} --force}
`mysqladmin #{params.join(' ')} drop #{my_config['database']} --force`
end

end

# TODO clean this up
# TODO: clean this up
def config
Apartment::Test.config['connections']
end
Expand Down
14 changes: 11 additions & 3 deletions apartment.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ Gem::Specification.new do |s|
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 = ['[email protected]', '[email protected]', '[email protected]']
s.files = `git ls-files`.split($/)
# 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.
s.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject do |f|
# NOTE: ignore all test related
f.match(%r{^(test|spec|features)/})
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']
Expand All @@ -20,13 +28,13 @@ Gem::Specification.new do |s|
s.licenses = ['MIT']

# must be >= 3.1.2 due to bug in prepared_statements
s.add_dependency 'activerecord', '>= 3.1.2', '< 6.1'
s.add_dependency 'activerecord', '>= 5.0.0', '< 6.1'
s.add_dependency 'parallel', '< 2.0'
s.add_dependency 'public_suffix', '>= 2.0.5', '< 5.0'
s.add_dependency 'rack', '>= 1.3.6', '< 3.0'

s.add_development_dependency 'appraisal', '~> 2.2'
s.add_development_dependency 'bundler', '>= 1.3', '< 2.0'
s.add_development_dependency 'bundler', '>= 1.3', '< 3.0'
s.add_development_dependency 'capybara', '~> 2.0'
s.add_development_dependency 'rake', '~> 0.9'
s.add_development_dependency 'rspec', '~> 3.4'
Expand Down
21 changes: 10 additions & 11 deletions gemfiles/rails_5_0.gemfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
# frozen_string_literal: true

# This file was generated by Appraisal

source 'http://rubygems.org'
source "http://rubygems.org"

gem 'rails', '~> 5.0.0'
gem "perx-rubocop", "~> 0.0.3"
gem "rails", "~> 5.0.0"

group :local do
gem 'guard-rspec', '~> 4.2'
gem 'pry'
gem "guard-rspec", "~> 4.2"
gem "pry"
end

platforms :ruby do
gem 'pg', '< 1.0.0'
gem "pg", "< 1.0.0"
end

platforms :jruby do
gem 'activerecord-jdbc-adapter', '~> 50.0'
gem 'activerecord-jdbcmysql-adapter', '~> 50.0'
gem 'activerecord-jdbcpostgresql-adapter', '~> 50.0'
gem "activerecord-jdbc-adapter", "~> 50.0"
gem "activerecord-jdbcpostgresql-adapter", "~> 50.0"
gem "activerecord-jdbcmysql-adapter", "~> 50.0"
end

gemspec path: '../'
gemspec path: "../"
Loading