Skip to content

Commit

Permalink
Merge pull request #44 from rails-on-services/development
Browse files Browse the repository at this point in the history
Release v2.5.0
  • Loading branch information
rpbaltazar authored May 5, 2020
2 parents 44b95db + b19ba24 commit d8097ae
Show file tree
Hide file tree
Showing 32 changed files with 327 additions and 225 deletions.
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

0 comments on commit d8097ae

Please sign in to comment.