activerecord-multi-tenant 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c5c0ba14d59d29394780c14bc3af728e9f9e8c4
4
- data.tar.gz: 76633446183eeca8bf24f5763db3dab4582d83fa
3
+ metadata.gz: 9d6ecfbf3c596f4c97db44220ae47b9b17370060
4
+ data.tar.gz: a13da12778bcc68651a52fd03f25b5e99f32fee4
5
5
  SHA512:
6
- metadata.gz: 83055c97bedeab4a83b32a4a772c2ed62511f464529e392283832fb42fe39d0e04e0c33e710e1950c49e0cf14ac9a3d95da7a73375e813898fdd07f79a664597
7
- data.tar.gz: a89de927f75b3e5824d07cfb731fe21c506e5104d10e42e9406609d10b9d70b08ab1152919e7ea9f9191d7b57a04ba60c0fcde1b4795d9dac12f6890580ecaa0
6
+ metadata.gz: 40aab782eaa7eaf613f576febca765da3942d7678fe3ee3bad99fb7b0aa495dcb3bbac651d33eea5d5807461b42c934329a489a74d9c77691a310965ac1e7429
7
+ data.tar.gz: 0ff0d1fbf17c30c5730ec24e8f8274a0367af4382f790d67f97908c8ea4623676c312f6f3b14788237ab8698a41128ec84c5fcc4310902a51316d5ccac936d76
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.1 2017-02-13
4
+
5
+ * Rails 5 API controller support [@mstahl](https://github.com/mstahl) [#4](https://github.com/citusdata/activerecord-multi-tenant/pull/4)
6
+ * Citus 6.1 compatibility
7
+
8
+
3
9
  ## 0.3.0 2016-12-30
4
10
 
5
11
  * Remove dependency on acts_as_tenant - instead copy the code thats necessary
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-multi-tenant (0.3.0)
4
+ activerecord-multi-tenant (0.3.1)
5
5
  rails (>= 3.1)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -144,8 +144,10 @@ DEPENDENCIES
144
144
  appraisal
145
145
  database_cleaner (~> 1.3.0)
146
146
  pg
147
+ rake
147
148
  rspec (>= 3.0)
148
149
  rspec-rails
150
+ thor
149
151
 
150
152
  BUNDLED WITH
151
153
  1.11.2
data/README.md CHANGED
@@ -65,18 +65,11 @@ class ApplicationController < ActionController::Base
65
65
  end
66
66
  ```
67
67
 
68
- ## Considerations when using Ruby on Rails with Citus
68
+ ## Frequently Asked Questions
69
69
 
70
- In case you use Ruby on Rails together with Citus, please also note the following.
70
+ * **What if I have a table that doesn't relate to my tenant?** (e.g. templates that are the same in every account)
71
71
 
72
- You'll need to disable prepared_statements in your database.yml like this:
73
-
74
- ```
75
- default: &default
76
- adapter: postgresql
77
- url: <%= ENV['DATABASE_URL'] %>
78
- prepared_statements: false
79
- ```
72
+ We recommend not using activerecord-multi-tenant on these tables. In case only some records in a table are not associated to a tenant (i.e. your templates are in the same table as actual objects), we recommend setting the tenant_id to 0, and then using MultiTenant.with_id(0) to access these objects.
80
73
 
81
74
  ## Credits
82
75
 
@@ -22,4 +22,6 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency 'rspec-rails'
23
23
  s.add_development_dependency 'database_cleaner', '~> 1.3.0'
24
24
  s.add_development_dependency 'pg'
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'thor'
25
27
  end
data/docker-compose.yml CHANGED
@@ -2,15 +2,15 @@ version: '2'
2
2
 
3
3
  services:
4
4
  master:
5
- image: 'citusdata/citus:6.0.1'
5
+ image: 'citusdata/citus:6.1.0'
6
6
  ports: ['5600:5432']
7
7
  labels: ['com.citusdata.role=Master']
8
8
  volumes: ['/var/run/postgresql']
9
9
  worker1:
10
- image: 'citusdata/citus:6.0.1'
10
+ image: 'citusdata/citus:6.1.0'
11
11
  labels: ['com.citusdata.role=Worker']
12
12
  worker2:
13
- image: 'citusdata/citus:6.0.1'
13
+ image: 'citusdata/citus:6.1.0'
14
14
  labels: ['com.citusdata.role=Worker']
15
15
  config:
16
16
  image: 'citusdata/workerlist-gen:2.0.0'
@@ -5,3 +5,5 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "test-unit", "~> 3.0"
7
7
  gem "rails", "3.2.22.5"
8
+
9
+ gemspec :path => "../"
@@ -1,3 +1,10 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ activerecord-multi-tenant (0.3.1)
5
+ rails (>= 3.1)
6
+ request_store (>= 1.0.5)
7
+
1
8
  GEM
2
9
  remote: https://rubygems.org/
3
10
  specs:
@@ -34,6 +41,8 @@ GEM
34
41
  thor (>= 0.14.0)
35
42
  arel (3.0.3)
36
43
  builder (3.0.4)
44
+ database_cleaner (1.3.0)
45
+ diff-lcs (1.2.5)
37
46
  erubis (2.7.0)
38
47
  hike (1.2.3)
39
48
  i18n (0.7.0)
@@ -44,6 +53,7 @@ GEM
44
53
  treetop (~> 1.4.8)
45
54
  mime-types (1.25.1)
46
55
  multi_json (1.12.1)
56
+ pg (0.19.0)
47
57
  polyglot (0.3.5)
48
58
  power_assert (0.4.1)
49
59
  rack (1.4.7)
@@ -71,6 +81,28 @@ GEM
71
81
  rake (12.0.0)
72
82
  rdoc (3.12.2)
73
83
  json (~> 1.4)
84
+ request_store (1.3.1)
85
+ rspec (3.5.0)
86
+ rspec-core (~> 3.5.0)
87
+ rspec-expectations (~> 3.5.0)
88
+ rspec-mocks (~> 3.5.0)
89
+ rspec-core (3.5.4)
90
+ rspec-support (~> 3.5.0)
91
+ rspec-expectations (3.5.0)
92
+ diff-lcs (>= 1.2.0, < 2.0)
93
+ rspec-support (~> 3.5.0)
94
+ rspec-mocks (3.5.0)
95
+ diff-lcs (>= 1.2.0, < 2.0)
96
+ rspec-support (~> 3.5.0)
97
+ rspec-rails (3.5.2)
98
+ actionpack (>= 3.0)
99
+ activesupport (>= 3.0)
100
+ railties (>= 3.0)
101
+ rspec-core (~> 3.5.0)
102
+ rspec-expectations (~> 3.5.0)
103
+ rspec-mocks (~> 3.5.0)
104
+ rspec-support (~> 3.5.0)
105
+ rspec-support (3.5.0)
74
106
  sprockets (2.2.3)
75
107
  hike (~> 1.2)
76
108
  multi_json (~> 1.0)
@@ -89,9 +121,16 @@ PLATFORMS
89
121
  ruby
90
122
 
91
123
  DEPENDENCIES
124
+ activerecord-multi-tenant!
92
125
  appraisal
126
+ database_cleaner (~> 1.3.0)
127
+ pg
93
128
  rails (= 3.2.22.5)
129
+ rake
130
+ rspec (>= 3.0)
131
+ rspec-rails
94
132
  test-unit (~> 3.0)
133
+ thor
95
134
 
96
135
  BUNDLED WITH
97
136
  1.11.2
@@ -4,3 +4,5 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "rails", "4.2.7.1"
7
+
8
+ gemspec :path => "../"
@@ -1,3 +1,10 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ activerecord-multi-tenant (0.3.1)
5
+ rails (>= 3.1)
6
+ request_store (>= 1.0.5)
7
+
1
8
  GEM
2
9
  remote: https://rubygems.org/
3
10
  specs:
@@ -43,6 +50,8 @@ GEM
43
50
  arel (6.0.4)
44
51
  builder (3.2.2)
45
52
  concurrent-ruby (1.0.4)
53
+ database_cleaner (1.3.0)
54
+ diff-lcs (1.2.5)
46
55
  erubis (2.7.0)
47
56
  globalid (0.3.7)
48
57
  activesupport (>= 4.1.0)
@@ -59,6 +68,7 @@ GEM
59
68
  minitest (5.10.1)
60
69
  nokogiri (1.7.0)
61
70
  mini_portile2 (~> 2.1.0)
71
+ pg (0.19.0)
62
72
  rack (1.6.5)
63
73
  rack-test (0.6.3)
64
74
  rack (>= 1.0)
@@ -87,6 +97,28 @@ GEM
87
97
  rake (>= 0.8.7)
88
98
  thor (>= 0.18.1, < 2.0)
89
99
  rake (12.0.0)
100
+ request_store (1.3.1)
101
+ rspec (3.5.0)
102
+ rspec-core (~> 3.5.0)
103
+ rspec-expectations (~> 3.5.0)
104
+ rspec-mocks (~> 3.5.0)
105
+ rspec-core (3.5.4)
106
+ rspec-support (~> 3.5.0)
107
+ rspec-expectations (3.5.0)
108
+ diff-lcs (>= 1.2.0, < 2.0)
109
+ rspec-support (~> 3.5.0)
110
+ rspec-mocks (3.5.0)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.5.0)
113
+ rspec-rails (3.5.2)
114
+ actionpack (>= 3.0)
115
+ activesupport (>= 3.0)
116
+ railties (>= 3.0)
117
+ rspec-core (~> 3.5.0)
118
+ rspec-expectations (~> 3.5.0)
119
+ rspec-mocks (~> 3.5.0)
120
+ rspec-support (~> 3.5.0)
121
+ rspec-support (3.5.0)
90
122
  sprockets (3.7.1)
91
123
  concurrent-ruby (~> 1.0)
92
124
  rack (> 1, < 3)
@@ -103,8 +135,15 @@ PLATFORMS
103
135
  ruby
104
136
 
105
137
  DEPENDENCIES
138
+ activerecord-multi-tenant!
106
139
  appraisal
140
+ database_cleaner (~> 1.3.0)
141
+ pg
107
142
  rails (= 4.2.7.1)
143
+ rake
144
+ rspec (>= 3.0)
145
+ rspec-rails
146
+ thor
108
147
 
109
148
  BUNDLED WITH
110
149
  1.11.2
@@ -4,3 +4,5 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "rails", "5.0.1"
7
+
8
+ gemspec :path => "../"
@@ -1,3 +1,10 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ activerecord-multi-tenant (0.3.1)
5
+ rails (>= 3.1)
6
+ request_store (>= 1.0.5)
7
+
1
8
  GEM
2
9
  remote: https://rubygems.org/
3
10
  specs:
@@ -45,6 +52,8 @@ GEM
45
52
  arel (7.1.4)
46
53
  builder (3.2.2)
47
54
  concurrent-ruby (1.0.4)
55
+ database_cleaner (1.3.0)
56
+ diff-lcs (1.2.5)
48
57
  erubis (2.7.0)
49
58
  globalid (0.3.7)
50
59
  activesupport (>= 4.1.0)
@@ -62,6 +71,7 @@ GEM
62
71
  nio4r (1.2.1)
63
72
  nokogiri (1.7.0)
64
73
  mini_portile2 (~> 2.1.0)
74
+ pg (0.19.0)
65
75
  rack (2.0.1)
66
76
  rack-test (0.6.3)
67
77
  rack (>= 1.0)
@@ -89,6 +99,28 @@ GEM
89
99
  rake (>= 0.8.7)
90
100
  thor (>= 0.18.1, < 2.0)
91
101
  rake (12.0.0)
102
+ request_store (1.3.1)
103
+ rspec (3.5.0)
104
+ rspec-core (~> 3.5.0)
105
+ rspec-expectations (~> 3.5.0)
106
+ rspec-mocks (~> 3.5.0)
107
+ rspec-core (3.5.4)
108
+ rspec-support (~> 3.5.0)
109
+ rspec-expectations (3.5.0)
110
+ diff-lcs (>= 1.2.0, < 2.0)
111
+ rspec-support (~> 3.5.0)
112
+ rspec-mocks (3.5.0)
113
+ diff-lcs (>= 1.2.0, < 2.0)
114
+ rspec-support (~> 3.5.0)
115
+ rspec-rails (3.5.2)
116
+ actionpack (>= 3.0)
117
+ activesupport (>= 3.0)
118
+ railties (>= 3.0)
119
+ rspec-core (~> 3.5.0)
120
+ rspec-expectations (~> 3.5.0)
121
+ rspec-mocks (~> 3.5.0)
122
+ rspec-support (~> 3.5.0)
123
+ rspec-support (3.5.0)
92
124
  sprockets (3.7.1)
93
125
  concurrent-ruby (~> 1.0)
94
126
  rack (> 1, < 3)
@@ -108,8 +140,15 @@ PLATFORMS
108
140
  ruby
109
141
 
110
142
  DEPENDENCIES
143
+ activerecord-multi-tenant!
111
144
  appraisal
145
+ database_cleaner (~> 1.3.0)
146
+ pg
112
147
  rails (= 5.0.1)
148
+ rake
149
+ rspec (>= 3.0)
150
+ rspec-rails
151
+ thor
113
152
 
114
153
  BUNDLED WITH
115
154
  1.11.2
@@ -2,16 +2,19 @@ module MultiTenant
2
2
  module ControllerExtensions
3
3
  def set_current_tenant_through_filter
4
4
  self.class_eval do
5
- helper_method :current_tenant
5
+ if respond_to?(:helper_method)
6
+ helper_method :current_tenant
7
+ end
6
8
 
7
9
  private
8
- def set_current_tenant(current_tenant_object)
9
- MultiTenant.current_tenant = current_tenant_object
10
- end
11
10
 
12
- def current_tenant
13
- MultiTenant.current_tenant
14
- end
11
+ def set_current_tenant(current_tenant_object)
12
+ MultiTenant.current_tenant = current_tenant_object
13
+ end
14
+
15
+ def current_tenant
16
+ MultiTenant.current_tenant
17
+ end
15
18
  end
16
19
  end
17
20
  end
@@ -20,3 +23,7 @@ end
20
23
  if defined?(ActionController::Base)
21
24
  ActionController::Base.extend MultiTenant::ControllerExtensions
22
25
  end
26
+
27
+ if defined?(ActionController::API)
28
+ ActionController::API.extend MultiTenant::ControllerExtensions
29
+ end
@@ -1,17 +1,30 @@
1
1
  module MultiTenant
2
2
  module MigrationExtensions
3
3
  def create_distributed_table(table_name, partition_key)
4
+ return unless citus_version.present?
4
5
  execute "SELECT create_distributed_table($$#{table_name}$$, $$#{partition_key}$$)"
5
6
  end
6
7
 
7
8
  def execute_on_all_nodes(sql)
8
9
  execute sql
9
- execute "SELECT citus_run_on_all_workers($$#{sql}$$)"
10
+
11
+ case citus_version
12
+ when '6.0'
13
+ execute "SELECT citus_run_on_all_workers($$#{sql}$$)" # initial citus_tools.sql with different names
14
+ when nil
15
+ # Do nothing, this is regular Postgres
16
+ else # 6.1 and newer
17
+ execute "SELECT run_command_on_workers($$#{sql}$$)"
18
+ end
10
19
  end
11
20
 
12
21
  def enable_extension_on_all_nodes(extension)
13
22
  execute_on_all_nodes "CREATE EXTENSION IF NOT EXISTS \"#{extension}\""
14
23
  end
24
+
25
+ def citus_version
26
+ execute("SELECT extversion FROM pg_extension WHERE extname = 'citus'").getvalue(0,0).try(:split, '-').try(:first)
27
+ end
15
28
  end
16
29
  end
17
30
 
@@ -1,3 +1,3 @@
1
1
  module MultiTenant
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -28,3 +28,30 @@ describe ApplicationController, type: :controller do
28
28
  expect(MultiTenant.current_tenant.name).to eq 'account1'
29
29
  end
30
30
  end
31
+
32
+ if Rails::VERSION::MAJOR >= 5
33
+ class APIApplicationController < ActionController::API
34
+ include Rails.application.routes.url_helpers
35
+ set_current_tenant_through_filter
36
+ before_action :your_method_that_finds_the_current_tenant
37
+
38
+ def your_method_that_finds_the_current_tenant
39
+ current_account = Account.new
40
+ current_account.name = 'account1'
41
+ set_current_tenant(current_account)
42
+ end
43
+ end
44
+
45
+ describe APIApplicationController, type: :controller do
46
+ controller do
47
+ def index
48
+ render body: 'custom called'
49
+ end
50
+ end
51
+
52
+ it 'Finds the correct tenant using the filter command' do
53
+ get :index
54
+ expect(MultiTenant.current_tenant.name).to eq 'account1'
55
+ end
56
+ end
57
+ end
data/spec/schema.rb CHANGED
@@ -1,4 +1,4 @@
1
- false && ActiveRecord::Schema.define(version: 1) do
1
+ ActiveRecord::Schema.define(version: 1) do
2
2
  create_table :accounts, force: true do |t|
3
3
  t.column :name, :string
4
4
  t.column :subdomain, :string
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,9 @@ ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.
13
13
  ActiveRecord::Base.establish_connection(dbconfig['test'])
14
14
 
15
15
  RSpec.configure do |config|
16
+ config.infer_base_class_for_anonymous_controllers = true
17
+ config.use_transactional_fixtures = false
18
+
16
19
  config.after(:each) do
17
20
  MultiTenant.current_tenant = nil
18
21
  end
@@ -29,8 +32,6 @@ RSpec.configure do |config|
29
32
  config.after(:each) do
30
33
  DatabaseCleaner[:active_record].clean
31
34
  end
32
-
33
- config.infer_base_class_for_anonymous_controllers = true
34
35
  end
35
36
 
36
37
  module MultiTenantTest
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-multi-tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Citus Data
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-31 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: request_store
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description: ''
98
126
  email: engage@citusdata.com
99
127
  executables: []