ros-apartment 2.8.1.rc1 → 2.8.1.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f446466c85cecc098b1fec480bd1400bc849ea49ea4f7b5607c1bb3bd46ab6b6
4
- data.tar.gz: ed713631a71b9b9948f942f25f6cb5dba586a41dcdebe40f14fdef6effccf25c
3
+ metadata.gz: f4eae53ab581ffa6402db4640424f23f864b8a4f72a1cf38bd35dc200fc014bf
4
+ data.tar.gz: f0ca3c1ae5102e4aa644aab5758543032455d6266fc86c5b3d97bb6e21eab731
5
5
  SHA512:
6
- metadata.gz: a7bf926bd676c7025c1567063b1b97eb01993e7d6f4821ff8e103e9b1057791712a8590247191070764fdbbfd17dc70cc54848fee5c5a7e5379315eda4554cb5
7
- data.tar.gz: 86375a0c10ce05b3a2e9c217c9c0e574a643725fcba1f98631165d7e8682f9d840d152238d24370ebc55d2713989ff47d633e35fd7c2cdde171443cbcbc3dd07
6
+ metadata.gz: f4bca612be122515d41ab388cf1bc22d96216b0baa8178a6d6d1a52418c932bcafe97f4089dfc1eff3725544ee1044391772f35935b86caf67c66d311e85c7ac
7
+ data.tar.gz: fb489d69d50d6caea7c3a19be53b8e693fb8ea24782c8850eb4efca070eecce7364f3f2fc7d8f17a37e93caeed6a08ef6cfad3dbd7c47857c91442803e44e51c
@@ -0,0 +1,78 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ rubocop: hanachin/rubocop@0.0.6
5
+
6
+ jobs:
7
+ build:
8
+ docker:
9
+ - image: circleci/<< parameters.ruby_version >>
10
+ - image: circleci/postgres:9.6.2-alpine
11
+ - image: circleci/mysql:5.7
12
+ environment:
13
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
14
+ parameters:
15
+ ruby_version:
16
+ type: string
17
+ gemfile:
18
+ type: string
19
+ environment:
20
+ BUNDLE_GEMFILE: << parameters.gemfile >>
21
+ steps:
22
+ - checkout
23
+ # Restore Cached Dependencies
24
+ # - restore_cache:
25
+ # keys:
26
+ # - gem-cache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "<< parameters.gemfile >>.lock" }}
27
+ # - gem-cache-v1-{{ arch }}-{{ .Branch }}
28
+ # - gem-cache-v1
29
+
30
+ - run: bundle install --path vendor/bundle
31
+
32
+ # - save_cache:
33
+ # key: gem-cache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "<< parameters.gemfile >>.lock" }}
34
+ # paths:
35
+ # - vendor/bundle
36
+
37
+ - run:
38
+ name: Install postgres client
39
+ command: sudo apt install -y postgresql-client
40
+
41
+ - run:
42
+ name: Install mysql client
43
+ command: sudo apt install -y default-mysql-client
44
+
45
+ - run:
46
+ name: Configure config database.yml
47
+ command: bundle exec rake db:copy_credentials
48
+
49
+ - run:
50
+ name: wait for postgresql
51
+ command: dockerize -wait tcp://localhost:5432 -timeout 1m
52
+
53
+ - run:
54
+ name: wait for mysql
55
+ command: dockerize -wait tcp://localhost:3306 -timeout 1m
56
+
57
+ - run:
58
+ name: Database Setup
59
+ command: |
60
+ bundle exec rake db:test:prepare
61
+
62
+ - run:
63
+ name: Run tests
64
+ command: bundle exec rspec
65
+
66
+ workflows:
67
+ tests:
68
+ jobs:
69
+ - build:
70
+ matrix:
71
+ parameters:
72
+ ruby_version: ["ruby:2.6-buster", "ruby:2.7-buster"]
73
+ gemfile: ["gemfiles/rails_5_2.gemfile", "gemfiles/rails_6_0.gemfile"]
74
+
75
+ rubocop:
76
+ jobs:
77
+ - rubocop/rubocop:
78
+ version: 0.88.0
@@ -4,6 +4,11 @@ AllCops:
4
4
  Exclude:
5
5
  - 'gemfiles/**/*.gemfile'
6
6
  - 'gemfiles/vendor/**/*'
7
+ - 'spec/dummy_engine/dummy_engine.gemspec'
8
+
9
+ Gemspec/RequiredRubyVersion:
10
+ Exclude:
11
+ - 'ros-apartment.gemspec'
7
12
 
8
13
  Style/WordArray:
9
14
  Exclude:
@@ -9,6 +9,7 @@
9
9
  **Fixed bugs:**
10
10
 
11
11
  - New version raises an error with ActiveSupport::LogSubscriber [#128](https://github.com/rails-on-services/apartment/issues/128)
12
+ - Weird logs when tenant fails to create [#127](<https://github.com/rails-on-services/apartment/issues/127>)
12
13
 
13
14
  **Closed issues:**
14
15
 
data/README.md CHANGED
@@ -351,7 +351,7 @@ Please note that our custom logger inherits from `ActiveRecord::LogSubscriber` s
351
351
 
352
352
  ```ruby
353
353
  Apartment.configure do |config|
354
- active_record_log = true
354
+ config.active_record_log = true
355
355
  end
356
356
  ```
357
357
 
data/Rakefile CHANGED
@@ -47,9 +47,9 @@ namespace :db do
47
47
  rails_db_file = 'spec/dummy/config/database.yml'
48
48
 
49
49
  unless File.exist?(apartment_db_file)
50
- FileUtils.copy(apartment_db_file + '.sample', apartment_db_file, verbose: true)
50
+ FileUtils.copy("#{apartment_db_file}.sample", apartment_db_file, verbose: true)
51
51
  end
52
- FileUtils.copy(rails_db_file + '.sample', rails_db_file, verbose: true) unless File.exist?(rails_db_file)
52
+ FileUtils.copy("#{rails_db_file}.sample", rails_db_file, verbose: true) unless File.exist?(rails_db_file)
53
53
  end
54
54
  end
55
55
 
@@ -65,6 +65,7 @@ namespace :postgres do
65
65
  params << "-U#{pg_config['username']}"
66
66
  params << "-h#{pg_config['host']}" if pg_config['host']
67
67
  params << "-p#{pg_config['port']}" if pg_config['port']
68
+
68
69
  begin
69
70
  `createdb #{params.join(' ')}`
70
71
  rescue StandardError
@@ -201,11 +201,13 @@ module Apartment
201
201
  # @param {String} tenant: Database name
202
202
  # @param {Boolean} with_database: if true, use the actual tenant's db name
203
203
  # if false, use the default db name from the db
204
+ # rubocop:disable Style/OptionalBooleanParameter
204
205
  def multi_tenantify(tenant, with_database = true)
205
206
  db_connection_config(tenant).tap do |config|
206
207
  multi_tenantify_with_tenant_db_name(config, tenant) if with_database
207
208
  end
208
209
  end
210
+ # rubocop:enable Style/OptionalBooleanParameter
209
211
 
210
212
  def multi_tenantify_with_tenant_db_name(config, tenant)
211
213
  config[:database] = environmentify(tenant)
@@ -98,7 +98,7 @@ module Apartment
98
98
 
99
99
  def create_tenant_command(conn, tenant)
100
100
  # NOTE: This was causing some tests to fail because of the database strategy for rspec
101
- if ActiveRecord::Base.connection.open_transactions > 0
101
+ if ActiveRecord::Base.connection.open_transactions.positive?
102
102
  conn.execute(%(CREATE SCHEMA "#{tenant}"))
103
103
  else
104
104
  schema = %(BEGIN;
@@ -113,7 +113,7 @@ module Apartment
113
113
  end
114
114
 
115
115
  def rollback_transaction(conn)
116
- conn.execute("ROLLBACK;")
116
+ conn.execute('ROLLBACK;')
117
117
  end
118
118
 
119
119
  # Generate the final search path to set including persistent_schemas
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # A workaraound to get `reload!` to also call Apartment::Tenant.init
3
+ # A workaround to get `reload!` to also call Apartment::Tenant.init
4
4
  # This is unfortunate, but I haven't figured out how to hook into the reload process *after* files are reloaded
5
5
 
6
6
  # reloads the environment
7
+ # rubocop:disable Style/OptionalBooleanParameter
7
8
  def reload!(print = true)
8
9
  puts 'Reloading...' if print
9
10
 
@@ -13,6 +14,7 @@ def reload!(print = true)
13
14
  Apartment::Tenant.init
14
15
  true
15
16
  end
17
+ # rubocop:enable Style/OptionalBooleanParameter
16
18
 
17
19
  def st(schema_name = nil)
18
20
  if schema_name.nil?
@@ -3,10 +3,14 @@
3
3
  require 'active_record/log_subscriber'
4
4
 
5
5
  module Apartment
6
+ # Custom Log subscriber to include database name and schema name in sql logs
6
7
  class LogSubscriber < ActiveRecord::LogSubscriber
8
+ # NOTE: for some reason, if the method definition is not here, then the custom debug method is not called
9
+ # rubocop:disable Lint/UselessMethodDefinition
7
10
  def sql(event)
8
11
  super(event)
9
12
  end
13
+ # rubocop:enable Lint/UselessMethodDefinition
10
14
 
11
15
  private
12
16
 
@@ -17,7 +21,7 @@ module Apartment
17
21
  end
18
22
 
19
23
  def apartment_log
20
- database = color("[#{Apartment.connection.current_database}] ", ActiveSupport::LogSubscriber::MAGENTA, true)
24
+ database = color("[#{Apartment.connection.raw_connection.db}] ", ActiveSupport::LogSubscriber::MAGENTA, true)
21
25
  schema = nil
22
26
  unless Apartment.connection.schema_search_path.nil?
23
27
  schema = color("[#{Apartment.connection.schema_search_path.tr('"', '')}] ",
@@ -6,7 +6,6 @@ require 'apartment/reloader'
6
6
 
7
7
  module Apartment
8
8
  class Railtie < Rails::Railtie
9
-
10
9
  #
11
10
  # Set up our default config options
12
11
  # Do this before the app initializers run so we don't override custom settings
@@ -27,13 +26,14 @@ module Apartment
27
26
  end
28
27
 
29
28
  # Hook into ActionDispatch::Reloader to ensure Apartment is properly initialized
30
- # Note that this doens't entirely work as expected in Development, because this is called before classes are reloaded
29
+ # Note that this doesn't entirely work as expected in Development,
30
+ # because this is called before classes are reloaded
31
31
  # See the middleware/console declarations below to help with this. Hope to fix that soon.
32
32
  #
33
33
  config.to_prepare do
34
34
  next if ARGV.any? { |arg| arg =~ /\Aassets:(?:precompile|clean)\z/ }
35
35
  next if ARGV.any? { |arg| arg == 'webpacker:compile' }
36
- next if ENV["APARTMENT_DISABLE_INIT"]
36
+ next if ENV['APARTMENT_DISABLE_INIT']
37
37
 
38
38
  begin
39
39
  Apartment.connection_class.connection_pool.with_connection do
@@ -45,7 +45,7 @@ module Apartment
45
45
  end
46
46
  end
47
47
 
48
- config.after_initialize do |app|
48
+ config.after_initialize do
49
49
  # NOTE: Load the custom log subscriber if enabled
50
50
  if Apartment.active_record_log
51
51
  ActiveSupport::Notifications.unsubscribe 'sql.active_record'
@@ -72,10 +72,13 @@ module Apartment
72
72
  app.config.middleware.use Apartment::Reloader
73
73
  end
74
74
 
75
- # Overrides reload! to also call Apartment::Tenant.init as well so that the reloaded classes have the proper table_names
75
+ # Overrides reload! to also call Apartment::Tenant.init as well
76
+ # so that the reloaded classes have the proper table_names
77
+ # rubocop:disable Lint/Debugger
76
78
  console do
77
79
  require 'apartment/console'
78
80
  end
81
+ # rubocop:enable Lint/Debugger
79
82
  end
80
83
  end
81
84
  end
@@ -24,9 +24,10 @@ module Apartment
24
24
  adapter_method = "#{config[:adapter]}_adapter"
25
25
 
26
26
  if defined?(JRUBY_VERSION)
27
- if config[:adapter] =~ /mysql/
27
+ case config[:adapter]
28
+ when /mysql/
28
29
  adapter_method = 'jdbc_mysql_adapter'
29
- elsif config[:adapter] =~ /postgresql/
30
+ when /postgresql/
30
31
  adapter_method = 'jdbc_postgresql_adapter'
31
32
  end
32
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apartment
4
- VERSION = '2.8.1.rc1'
4
+ VERSION = '2.8.1.rc2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ros-apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.1.rc1
4
+ version: 2.8.1.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner
@@ -228,6 +228,7 @@ executables: []
228
228
  extensions: []
229
229
  extra_rdoc_files: []
230
230
  files:
231
+ - ".circleci/config.yml"
231
232
  - ".github/ISSUE_TEMPLATE.md"
232
233
  - ".github/workflows/changelog.yml"
233
234
  - ".gitignore"
@@ -236,7 +237,6 @@ files:
236
237
  - ".rubocop.yml"
237
238
  - ".rubocop_todo.yml"
238
239
  - ".story_branch.yml"
239
- - ".travis.yml"
240
240
  - Appraisals
241
241
  - CHANGELOG.md
242
242
  - Gemfile
@@ -1,49 +0,0 @@
1
- os: linux
2
-
3
- language: ruby
4
- services:
5
- - docker
6
- rvm:
7
- - jruby-9.2.11.0
8
- - 2.4.10
9
- - 2.5.8
10
- - 2.6.6
11
- - 2.7.1
12
- - jruby-head
13
- - ruby-head
14
-
15
- branches:
16
- only:
17
- - master
18
- - development
19
-
20
- gemfile:
21
- - gemfiles/rails_5_0.gemfile
22
- - gemfiles/rails_5_1.gemfile
23
- - gemfiles/rails_5_2.gemfile
24
- - gemfiles/rails_6_0.gemfile
25
- - gemfiles/rails_master.gemfile
26
-
27
- bundler_args: --without local
28
- before_install:
29
- - sudo /etc/init.d/mysql stop
30
- - sudo /etc/init.d/postgresql stop
31
- - docker-compose up -d
32
-
33
- env:
34
- RUBY_GC_MALLOC_LIMIT: 90000000
35
- RUBY_GC_HEAP_FREE_SLOTS: 200000
36
- jobs:
37
- include:
38
- - name: Rubocop Lint
39
- script: gem install rubocop
40
-
41
- allow_failures:
42
- - rvm: ruby-head
43
- - rvm: jruby-head
44
- - gemfile: gemfiles/rails_master.gemfile
45
- exclude:
46
- - rvm: 2.4.10
47
- gemfile: gemfiles/rails_6_0.gemfile
48
- fast_finish: true
49
- cache: bundler