multitenant-mysql 1.2.1 → 1.2.2
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.
- data/CHANGELOG.rdoc +3 -0
- data/lib/multitenant-mysql/active_record_extension.rb +40 -33
- data/lib/multitenant-mysql/version.rb +1 -1
- data/spec/conf/database.yml +1 -1
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
|
@@ -1,45 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
ActiveRecord::Base.class_eval do
|
|
2
|
+
|
|
3
|
+
class << self
|
|
4
|
+
|
|
5
|
+
def acts_as_tenants_bucket
|
|
6
|
+
after_create do
|
|
7
|
+
password = Multitenant::Mysql::DB.configs['password']
|
|
8
|
+
tenant_name = self.send(Multitenant::Mysql.configs.bucket_field)
|
|
9
|
+
connection = Multitenant::Mysql::DB.connection
|
|
10
|
+
connection.execute "GRANT ALL PRIVILEGES ON *.* TO '#{tenant_name}'@'localhost' IDENTIFIED BY '#{password}' WITH GRANT OPTION;"
|
|
11
|
+
connection.execute "flush privileges;"
|
|
12
|
+
end
|
|
9
13
|
end
|
|
10
|
-
end
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
def acts_as_tenant
|
|
16
|
+
view_name = model_name.to_s.downcase.pluralize + "_view"
|
|
17
|
+
# check whether the view exists in db
|
|
18
|
+
if ActiveRecord::Base.connection.table_exists? view_name
|
|
19
|
+
self.class_eval do
|
|
20
|
+
cattr_accessor :original_table_name
|
|
21
|
+
|
|
22
|
+
self.original_table_name = self.table_name
|
|
23
|
+
self.table_name = view_name
|
|
24
|
+
self.primary_key = :id
|
|
25
|
+
|
|
26
|
+
def self.new(*args)
|
|
27
|
+
object = super(*args)
|
|
28
|
+
object.id = nil # workaround for https://github.com/rails/rails/issues/5982
|
|
29
|
+
object
|
|
30
|
+
end
|
|
27
31
|
end
|
|
28
32
|
end
|
|
29
33
|
end
|
|
30
|
-
end
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
super
|
|
35
|
+
alias_method :multitenant_mysql_chained_inherited, :inherited
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
def inherited(child)
|
|
38
|
+
multitenant_mysql_chained_inherited(child)
|
|
39
|
+
|
|
40
|
+
model_name = child.to_s
|
|
41
|
+
if Multitenant::Mysql.configs.models.include? model_name
|
|
42
|
+
child.send :acts_as_tenant
|
|
43
|
+
end
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
if Multitenant::Mysql.configs.tenant? child
|
|
46
|
+
child.send :acts_as_tenants_bucket
|
|
47
|
+
end
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
end
|
|
51
|
+
|
|
45
52
|
end
|
data/spec/conf/database.yml
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: multitenant-mysql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rspec
|
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
106
106
|
version: '0'
|
|
107
107
|
requirements: []
|
|
108
108
|
rubyforge_project:
|
|
109
|
-
rubygems_version: 1.8.
|
|
109
|
+
rubygems_version: 1.8.21
|
|
110
110
|
signing_key:
|
|
111
111
|
specification_version: 3
|
|
112
112
|
summary: Add multi-tenancy to Rails application using MySql views
|