activerecord-multi-tenant 0.2.1 → 0.3.0

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
  SHA1:
3
- metadata.gz: aeff78948e2addc557a047bbf14bc9ff8268ba82
4
- data.tar.gz: 2956b31946178941f0f8b66ed62cff54b7100b60
3
+ metadata.gz: 2c5c0ba14d59d29394780c14bc3af728e9f9e8c4
4
+ data.tar.gz: 76633446183eeca8bf24f5763db3dab4582d83fa
5
5
  SHA512:
6
- metadata.gz: c92d6c7bee05cd4bc1040387e5484586a435bd6c7f376f8de4747cfa027003f7780538ecceb5b973f4d5b73946646b21e77581a1bda4bfc0dcb131997cad68ff
7
- data.tar.gz: ad059f082e84e003a5d67506f5a00d555a7098389346263be4148a1f3f11b7c278c253fab2d871ecd080f8ec56f32b64c2d877b54e08d91d96f5df06ae794280
6
+ metadata.gz: 83055c97bedeab4a83b32a4a772c2ed62511f464529e392283832fb42fe39d0e04e0c33e710e1950c49e0cf14ac9a3d95da7a73375e813898fdd07f79a664597
7
+ data.tar.gz: a89de927f75b3e5824d07cfb731fe21c506e5104d10e42e9406609d10b9d70b08ab1152919e7ea9f9191d7b57a04ba60c0fcde1b4795d9dac12f6890580ecaa0
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ spec/debug.log
2
+ pkg/
data/Appraisals ADDED
@@ -0,0 +1,12 @@
1
+ appraise 'rails-3.2' do
2
+ gem 'test-unit', '~> 3.0'
3
+ gem 'rails', '3.2.22.5'
4
+ end
5
+
6
+ appraise 'rails-4.2' do
7
+ gem 'rails', '4.2.7.1'
8
+ end
9
+
10
+ appraise 'rails-5.0' do
11
+ gem 'rails', '5.0.1'
12
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 2016-12-30
4
+
5
+ * Remove dependency on acts_as_tenant - instead copy the code thats necessary
6
+ * Fix issue with callbacks having TenantIdWrapper instead of the actual object
7
+
8
+
9
+ ## 0.2.1 2016-12-29
10
+
11
+ * Fix bug in CopyFromClient helper
12
+
13
+
14
+ ## 0.2.0 2016-12-27
15
+
16
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'appraisal'
data/Gemfile.lock ADDED
@@ -0,0 +1,151 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ activerecord-multi-tenant (0.3.0)
5
+ rails (>= 3.1)
6
+ request_store (>= 1.0.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.0.1)
12
+ actionpack (= 5.0.1)
13
+ nio4r (~> 1.2)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.0.1)
16
+ actionpack (= 5.0.1)
17
+ actionview (= 5.0.1)
18
+ activejob (= 5.0.1)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.0.1)
22
+ actionview (= 5.0.1)
23
+ activesupport (= 5.0.1)
24
+ rack (~> 2.0)
25
+ rack-test (~> 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.0.1)
29
+ activesupport (= 5.0.1)
30
+ builder (~> 3.1)
31
+ erubis (~> 2.7.0)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
34
+ activejob (5.0.1)
35
+ activesupport (= 5.0.1)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.0.1)
38
+ activesupport (= 5.0.1)
39
+ activerecord (5.0.1)
40
+ activemodel (= 5.0.1)
41
+ activesupport (= 5.0.1)
42
+ arel (~> 7.0)
43
+ activesupport (5.0.1)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (~> 0.7)
46
+ minitest (~> 5.1)
47
+ tzinfo (~> 1.1)
48
+ appraisal (2.1.0)
49
+ bundler
50
+ rake
51
+ thor (>= 0.14.0)
52
+ arel (7.1.4)
53
+ builder (3.2.2)
54
+ concurrent-ruby (1.0.4)
55
+ database_cleaner (1.3.0)
56
+ diff-lcs (1.2.5)
57
+ erubis (2.7.0)
58
+ globalid (0.3.7)
59
+ activesupport (>= 4.1.0)
60
+ i18n (0.7.0)
61
+ loofah (2.0.3)
62
+ nokogiri (>= 1.5.9)
63
+ mail (2.6.4)
64
+ mime-types (>= 1.16, < 4)
65
+ method_source (0.8.2)
66
+ mime-types (3.1)
67
+ mime-types-data (~> 3.2015)
68
+ mime-types-data (3.2016.0521)
69
+ mini_portile2 (2.1.0)
70
+ minitest (5.10.1)
71
+ nio4r (1.2.1)
72
+ nokogiri (1.7.0)
73
+ mini_portile2 (~> 2.1.0)
74
+ pg (0.19.0)
75
+ rack (2.0.1)
76
+ rack-test (0.6.3)
77
+ rack (>= 1.0)
78
+ rails (5.0.1)
79
+ actioncable (= 5.0.1)
80
+ actionmailer (= 5.0.1)
81
+ actionpack (= 5.0.1)
82
+ actionview (= 5.0.1)
83
+ activejob (= 5.0.1)
84
+ activemodel (= 5.0.1)
85
+ activerecord (= 5.0.1)
86
+ activesupport (= 5.0.1)
87
+ bundler (>= 1.3.0, < 2.0)
88
+ railties (= 5.0.1)
89
+ sprockets-rails (>= 2.0.0)
90
+ rails-dom-testing (2.0.2)
91
+ activesupport (>= 4.2.0, < 6.0)
92
+ nokogiri (~> 1.6)
93
+ rails-html-sanitizer (1.0.3)
94
+ loofah (~> 2.0)
95
+ railties (5.0.1)
96
+ actionpack (= 5.0.1)
97
+ activesupport (= 5.0.1)
98
+ method_source
99
+ rake (>= 0.8.7)
100
+ thor (>= 0.18.1, < 2.0)
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)
124
+ sprockets (3.7.1)
125
+ concurrent-ruby (~> 1.0)
126
+ rack (> 1, < 3)
127
+ sprockets-rails (3.2.0)
128
+ actionpack (>= 4.0)
129
+ activesupport (>= 4.0)
130
+ sprockets (>= 3.0.0)
131
+ thor (0.19.4)
132
+ thread_safe (0.3.5)
133
+ tzinfo (1.2.2)
134
+ thread_safe (~> 0.1)
135
+ websocket-driver (0.6.4)
136
+ websocket-extensions (>= 0.1.0)
137
+ websocket-extensions (0.1.2)
138
+
139
+ PLATFORMS
140
+ ruby
141
+
142
+ DEPENDENCIES
143
+ activerecord-multi-tenant!
144
+ appraisal
145
+ database_cleaner (~> 1.3.0)
146
+ pg
147
+ rspec (>= 3.0)
148
+ rspec-rails
149
+
150
+ BUNDLED WITH
151
+ 1.11.2
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # activerecord-multi-tenant [ ![](https://img.shields.io/gem/v/activerecord-multi-tenant.svg)](https://rubygems.org/gems/activerecord-multi-tenant) [ ![](https://img.shields.io/gem/dt/activerecord-multi-tenant.svg)](https://rubygems.org/gems/activerecord-multi-tenant)
2
+
3
+ ActiveRecord/Rails integration for multi-tenant databases, in particular the Citus extension for PostgreSQL.
4
+
5
+ ## Installation
6
+
7
+ Add the following to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'activerecord-multi-tenant'
11
+ ```
12
+
13
+ ## Supported Rails versions
14
+
15
+ All Ruby on Rails versions starting with 3.2 or newer are supported.
16
+
17
+ This gem only supports ActiveRecord (the Rails default ORM), and not alternative ORMs like Sequel.
18
+
19
+ ## Usage
20
+
21
+ It is required that you add `multi_tenant` definitions to your model in order to have full support for Citus, in particular when updating records.
22
+
23
+ In the example of an analytics application, sharding on `customer_id`, annotate your models like this:
24
+
25
+ ```ruby
26
+ class PageView < ActiveRecord::Base
27
+ multi_tenant :customer
28
+ belongs_to :site
29
+
30
+ # ...
31
+ end
32
+
33
+ class Site < ActiveRecord::Base
34
+ multi_tenant :customer
35
+ has_many :page_views
36
+ belongs_to :customer
37
+
38
+ # ...
39
+ end
40
+ ```
41
+
42
+ and then wrap all code that runs queries/modifications in blocks like this:
43
+
44
+ ```ruby
45
+ customer = Customer.find(session[:current_customer_id])
46
+ # ...
47
+ MultiTenant.with(customer) do
48
+ site = Site.find(params[:site_id])
49
+ site.update! last_accessed_at: Time.now
50
+ site.page_views.count
51
+ end
52
+ ```
53
+
54
+ Inside controllers you can use a before_action together with set_current_tenant, to set the tenant for the current request:
55
+
56
+ ```ruby
57
+ class ApplicationController < ActionController::Base
58
+ set_current_tenant_through_filter # Required to opt into this behavior
59
+ before_action :set_customer_as_tenant
60
+
61
+ def set_customer_as_tenant
62
+ customer = Customer.find(session[:current_customer_id])
63
+ set_current_tenant(customer)
64
+ end
65
+ end
66
+ ```
67
+
68
+ ## Considerations when using Ruby on Rails with Citus
69
+
70
+ In case you use Ruby on Rails together with Citus, please also note the following.
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
+ ```
80
+
81
+ ## Credits
82
+
83
+ This gem was initially based on [acts_as_tenant](https://github.com/ErwinM/acts_as_tenant), and still shares some code. We thank the authors for their efforts.
84
+
85
+ ## License
86
+
87
+ Licensed under the MIT license<br>
88
+ Copyright (c) 2016, Citus Data Inc.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'activerecord-multi-tenant/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'activerecord-multi-tenant'
6
+ s.version = MultiTenant::VERSION
7
+ s.summary = 'ActiveRecord/Rails integration for multi-tenant databases, in particular the Citus extension for PostgreSQL'
8
+ s.description = ''
9
+ s.authors = ['Citus Data']
10
+ s.email = 'engage@citusdata.com'
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
14
+ s.require_paths = ['lib']
15
+ s.homepage = 'https://github.com/citusdata/activerecord-multi-tenant'
16
+ s.license = 'MIT'
17
+
18
+ s.add_runtime_dependency('request_store', '>= 1.0.5')
19
+ s.add_dependency('rails','>= 3.1')
20
+
21
+ s.add_development_dependency 'rspec', '>= 3.0'
22
+ s.add_development_dependency 'rspec-rails'
23
+ s.add_development_dependency 'database_cleaner', '~> 1.3.0'
24
+ s.add_development_dependency 'pg'
25
+ end
@@ -0,0 +1,18 @@
1
+ version: '2'
2
+
3
+ services:
4
+ master:
5
+ image: 'citusdata/citus:6.0.1'
6
+ ports: ['5600:5432']
7
+ labels: ['com.citusdata.role=Master']
8
+ volumes: ['/var/run/postgresql']
9
+ worker1:
10
+ image: 'citusdata/citus:6.0.1'
11
+ labels: ['com.citusdata.role=Worker']
12
+ worker2:
13
+ image: 'citusdata/citus:6.0.1'
14
+ labels: ['com.citusdata.role=Worker']
15
+ config:
16
+ image: 'citusdata/workerlist-gen:2.0.0'
17
+ volumes: ['/var/run/docker.sock:/tmp/docker.sock']
18
+ volumes_from: ['master']
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "test-unit", "~> 3.0"
7
+ gem "rails", "3.2.22.5"
@@ -0,0 +1,97 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.22.5)
5
+ actionpack (= 3.2.22.5)
6
+ mail (~> 2.5.4)
7
+ actionpack (3.2.22.5)
8
+ activemodel (= 3.2.22.5)
9
+ activesupport (= 3.2.22.5)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.5)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.22.5)
18
+ activesupport (= 3.2.22.5)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.22.5)
21
+ activemodel (= 3.2.22.5)
22
+ activesupport (= 3.2.22.5)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.22.5)
26
+ activemodel (= 3.2.22.5)
27
+ activesupport (= 3.2.22.5)
28
+ activesupport (3.2.22.5)
29
+ i18n (~> 0.6, >= 0.6.4)
30
+ multi_json (~> 1.0)
31
+ appraisal (2.1.0)
32
+ bundler
33
+ rake
34
+ thor (>= 0.14.0)
35
+ arel (3.0.3)
36
+ builder (3.0.4)
37
+ erubis (2.7.0)
38
+ hike (1.2.3)
39
+ i18n (0.7.0)
40
+ journey (1.0.4)
41
+ json (1.8.3)
42
+ mail (2.5.4)
43
+ mime-types (~> 1.16)
44
+ treetop (~> 1.4.8)
45
+ mime-types (1.25.1)
46
+ multi_json (1.12.1)
47
+ polyglot (0.3.5)
48
+ power_assert (0.4.1)
49
+ rack (1.4.7)
50
+ rack-cache (1.6.1)
51
+ rack (>= 0.4)
52
+ rack-ssl (1.3.4)
53
+ rack
54
+ rack-test (0.6.3)
55
+ rack (>= 1.0)
56
+ rails (3.2.22.5)
57
+ actionmailer (= 3.2.22.5)
58
+ actionpack (= 3.2.22.5)
59
+ activerecord (= 3.2.22.5)
60
+ activeresource (= 3.2.22.5)
61
+ activesupport (= 3.2.22.5)
62
+ bundler (~> 1.0)
63
+ railties (= 3.2.22.5)
64
+ railties (3.2.22.5)
65
+ actionpack (= 3.2.22.5)
66
+ activesupport (= 3.2.22.5)
67
+ rack-ssl (~> 1.3.2)
68
+ rake (>= 0.8.7)
69
+ rdoc (~> 3.4)
70
+ thor (>= 0.14.6, < 2.0)
71
+ rake (12.0.0)
72
+ rdoc (3.12.2)
73
+ json (~> 1.4)
74
+ sprockets (2.2.3)
75
+ hike (~> 1.2)
76
+ multi_json (~> 1.0)
77
+ rack (~> 1.0)
78
+ tilt (~> 1.1, != 1.3.0)
79
+ test-unit (3.2.3)
80
+ power_assert
81
+ thor (0.19.4)
82
+ tilt (1.4.1)
83
+ treetop (1.4.15)
84
+ polyglot
85
+ polyglot (>= 0.3.1)
86
+ tzinfo (0.3.52)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ appraisal
93
+ rails (= 3.2.22.5)
94
+ test-unit (~> 3.0)
95
+
96
+ BUNDLED WITH
97
+ 1.11.2