multidb 3.2.1 → 4.0.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: c2b318704dc25c750faff4197c282bfc34ce3b44
4
- data.tar.gz: a6245b07384d189337568ef08fd5fe0467f92926
3
+ metadata.gz: b0e97b0db4c85a383ec514d3d514e807048163d8
4
+ data.tar.gz: a5f83d23bd77c3e4d30a0421231c7413f4bc7eed
5
5
  SHA512:
6
- metadata.gz: 2a5928902bb85f89d26b096a663a7269dd2de47412bb2c9e61c952fe4bfce5732c83ecd37d1eb938e5169d164e3828b8a5f36af3e8adffbd1ca212324596db3f
7
- data.tar.gz: abe71fcb71c0d8e70b8ec41fbb0611b5921d3449c3e7f9e22a79dbd2e58ce58d7afe4c6b9b329cdd66a7faa221455ebe40fa195c4e959bda63fb78a883808517
6
+ metadata.gz: a978b553a48398e2970bfff3fd69bf207670131e1974ee3fcae38efc5345a3f4810e6a9bec07fa45d590395780c6a8ed69d9f616c5e78cb850824ce3e4f51ef2
7
+ data.tar.gz: 76506cbfaa83016d6b82c8a8903580d617af5716a9402c3c04742f2d33d9f1db9c34688c8a2198d979e1b116d50db7cd2e4d20ead37918be24eba9d6c2696e14
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.1.1
1
+ ruby-2.1.0
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- #About MultiDB
1
+ # About MultiDB
2
2
 
3
3
  MultiDB is a multitenant extension for Rails (or just ActiveRecord) that allows you to isolate each tenant into its own individual database without requiring major changes to your application code.
4
4
 
@@ -10,12 +10,16 @@ Internally, MultiDB refers to tenants as organizations. In addition to the organ
10
10
 
11
11
  MultiDB, when used with Rails (ActionController), determines which database to connect to at the beginning of each request by checking for `request.host`, `params[:org_code]`, then `session[:org_code]`. In a test environment, it can will also check the environment variable `RAILS_ORG`. If no organization code is found in any of those places, the sessions database is used (which is one reason it is important that no actual data be stored there).
12
12
 
13
+ ## Current Status
14
+
15
+ The present version of MultiDB is extracted from ClarityEHR, a product of [MedNexus](http://mednex.us/) scheduled for release in Fall 2014. An older version (identical concept, similar basic mechanism, but less elegant implementation) has been in production in other products since 2007.
16
+
13
17
 
14
18
  ## Versioning & Compatibility
15
19
  MultiDB follows semantic versioning, but because it is closely tied to Rails/ActiveRecord, it uses the same major/minor version numbers to make it easy to determine which version of MultiDB to use. Patch numbers may vary.
16
20
 
17
21
  ### Rails & ActiveRecord
18
- MultiDB 3.2 works with Rails 3.2. A new branch will be created to work with Rails 4.
22
+ MultiDB 4.0 works with Rails 4.0, MultiDB 3.2 works with Rails 3.2.
19
23
 
20
24
  The concept should work with just ActiveRecord (no Rails), but this use case has not been tested. (Pull requests welcome.)
21
25
 
@@ -29,7 +33,7 @@ MultiDB is known to work with [Makara](https://github.com/taskrabbit/makara) in
29
33
 
30
34
  Add it to your Gemfile:
31
35
 
32
- gem 'multidb', '~> 3.2.0' # note: MultiDB 3.2 works with Rails 3.2
36
+ gem 'multidb', '~> 4.0.0' # note: MultiDB 4.0 works with Rails 4.0
33
37
 
34
38
  Or install by hand:
35
39
 
@@ -63,4 +67,4 @@ Your table will need to have columns for `code` (string) and `active` (boolean),
63
67
 
64
68
  ## Contributing
65
69
 
66
- Pull requests welcome. Don't forget tests! When adding support for a new adapter, create a new Rails app for your adapter (e.g. `rails _3.2.16_ new testapp_postgresql`), customize database.yml and other files as needed, then add specs to that app.
70
+ Pull requests welcome. Don't forget tests! When adding support for a new adapter, create a new Rails app for your adapter (e.g. `rails _4.0.2_ new testapp_postgresql`), customize database.yml and other files as needed, then add specs to that app.
@@ -17,7 +17,7 @@ class ActionController::Base
17
17
  # try hostname if we don't already have a code in the session
18
18
  if !@org && !session[:org_code] && request && request.host
19
19
  @org ||= MultiDB::Organization.active.where(:code => $1.gsub('-', '_')).first if request.host =~ /^([-\w\d]+)/
20
- @org ||= MultiDB::Organization.active.includes(:hosts).where('organization_hosts.host = ?', request.host).first
20
+ @org ||= MultiDB::Organization.active.includes(:hosts).where('organization_hosts.host = ?', request.host).references(:organization_hosts).first
21
21
  end
22
22
 
23
23
  if @org
@@ -90,5 +90,65 @@ module ActiveRecord
90
90
  end
91
91
 
92
92
  end
93
+
94
+ end
95
+
96
+
97
+ module Tasks
98
+
99
+ module DatabaseTasks
100
+
101
+ alias :create_without_multidb :create
102
+ def create(*arguments)
103
+ create_or_drop(:create, arguments)
104
+ end
105
+
106
+ alias :drop_without_multidb :drop
107
+ def drop(*arguments)
108
+ create_or_drop(:drop, arguments)
109
+ end
110
+
111
+ def create_or_drop(*arguments)
112
+ create_or_drop = arguments[0]
113
+ arguments = arguments[1]
114
+
115
+ _config = arguments.shift
116
+ config_name = ActiveRecord::Base.configurations.invert[_config]
117
+ is_test = (config_name == 'test')
118
+ config = _config.dup
119
+
120
+ case ENV['RAILS_ORG']
121
+ when nil
122
+ # set default org database
123
+ raise "No database name specified in configuration \"#{config_name}\"" unless config['database']
124
+ config['database'] += '_org1'
125
+ when 'sessions'
126
+ # do nothing
127
+ when 'master'
128
+ config = ActiveRecord::Base.master_configuration(is_test ? 'test' : nil)
129
+ else
130
+ config['database'] += '_' + ENV['RAILS_ORG']
131
+ end
132
+
133
+ arguments.unshift config
134
+
135
+ case create_or_drop
136
+ when :create then create_without_multidb(*arguments)
137
+ when :drop then drop_without_multidb(*arguments)
138
+ end
139
+ end
140
+
141
+ end
142
+
143
+ class MySQLDatabaseTasks
144
+
145
+ def purge
146
+ establish_connection configuration
147
+ connection.recreate_database configuration['database'], creation_options
148
+ end
149
+
150
+ end
151
+
93
152
  end
153
+
94
154
  end
@@ -1,6 +1,5 @@
1
1
  #
2
- # Based on activerecord-3.2.15/lib/active_record/railties/databases.rake
3
- # Last updated 2013-11-19 by Aaron Namba
2
+ # Based on activerecord-4.0.2/lib/active_record/railties/databases.rake
4
3
  #
5
4
  # AKN: Warning! All code to support db engines other than mysql has been deleted,
6
5
  # since I know it will never receive proper testing.
@@ -250,7 +249,7 @@ db_namespace = namespace :db do
250
249
  desc 'Load a schema.rb file into the database'
251
250
  task :load => [:environment, :load_config] do
252
251
  databases_to_load = case ENV['RAILS_ORG']
253
- when nil then [ :sessions, :master, :organization ]
252
+ when nil then [ :sessions, :master ]
254
253
  when 'sessions' then [ :sessions ]
255
254
  when 'master' then [ :master ]
256
255
  else [ :organization ]
@@ -280,81 +279,8 @@ db_namespace = namespace :db do
280
279
 
281
280
  # desc "Empty the test databases"
282
281
  task :purge => [:environment, :load_config] do
283
- abcs = ActiveRecord::Base.configurations
284
-
285
- # sessions
286
- ActiveRecord::Base.connect_to_sessions
287
- ActiveRecord::Base.connection.recreate_database(abcs['test']['database'], mysql_creation_options(abcs['test']))
288
-
289
- # master
290
- ActiveRecord::Base.connect_to_master
291
- ActiveRecord::Base.connection.recreate_database(ActiveRecord::Base.master_configuration('test')['database'], mysql_creation_options(abcs['test']))
292
-
293
- # org
294
- ActiveRecord::Base.connect_to_organization
295
- ActiveRecord::Base.connection.recreate_database(abcs['test']['database'] + '_org1', mysql_creation_options(abcs['test']))
296
- end
297
- end
298
-
299
- alias :create_database_without_multidb :create_database
300
- def create_database(_config)
301
- is_test = ActiveRecord::Base.configurations.invert[_config] == 'test'
302
- config = _config.dup
303
-
304
- case ENV['RAILS_ORG']
305
- when nil
306
- # set default org database
307
- config['database'] += '_org1'
308
- when 'sessions'
309
- # do nothing
310
- when 'master'
311
- config = ActiveRecord::Base.master_configuration(is_test ? 'test' : nil)
312
- else
313
- config['database'] += '_' + ENV['RAILS_ORG']
314
- end
315
-
316
- create_database_without_multidb(config)
317
- end
318
- end
319
-
320
-
321
- alias :drop_database_without_multidb :drop_database
322
- def drop_database(_config)
323
- is_test = ActiveRecord::Base.configurations.invert[_config] == 'test'
324
- config = _config.dup
325
-
326
- case ENV['RAILS_ORG']
327
- when nil
328
- # set default org database
329
- config['database'] += '_org1'
330
- when 'sessions'
331
- # do nothing
332
- when 'master'
333
- config = ActiveRecord::Base.master_configuration(is_test ? 'test' : nil)
334
- else
335
- config['database'] += '_' + ENV['RAILS_ORG']
336
- end
337
-
338
- drop_database_without_multidb(config)
339
- end
340
-
341
- # not sure yet why environment is not loaded before running create_database/drop_database
342
- # for now, copied this in from lib/multi_db/active_record_patches.rb
343
- module ActiveRecord
344
- class Base
345
- class << self
346
-
347
- def master_configuration(env = nil)
348
- env ||= Rails.env
349
-
350
- # use master db configuration in config/database.yml if present
351
- configurations["master_#{env}"] or Proc.new {
352
- c = configurations[env].dup
353
- c['database'] += '_master'
354
- c
355
- }.call
356
- end
357
-
282
+ ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.configurations['test']
283
+ ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.master_configuration('test')
358
284
  end
359
285
  end
360
286
  end
data/multidb.gemspec CHANGED
@@ -4,7 +4,7 @@ $:.push File.expand_path("../lib", __FILE__)
4
4
  # Describe your gem and declare its dependencies:
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "multidb"
7
- s.version = '3.2.1'
7
+ s.version = '4.0.0'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.author = "Aaron Namba"
10
10
  s.email = "aaron@biggerbird.com"
@@ -22,5 +22,5 @@ Gem::Specification.new do |s|
22
22
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
23
  s.require_paths = ["lib"]
24
24
 
25
- s.add_dependency 'activerecord', '~> 3.2', '>= 3.2.16'
25
+ s.add_dependency 'activerecord', '~> 4.0', '>= 4.0.2'
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multidb
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Namba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-04 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '4.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 3.2.16
22
+ version: 4.0.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '3.2'
29
+ version: '4.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 3.2.16
32
+ version: 4.0.2
33
33
  description: Enables multitenant setup with one database per tenant. See README for
34
34
  details.
35
35
  email: aaron@biggerbird.com
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: 1.8.11
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.1.11
108
+ rubygems_version: 2.2.0.rc.1
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: MultiDB for ActiveRecord