multidb 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/LICENSE.md +21 -0
- data/README.md +65 -0
- data/lib/multi_db/action_controller_patches.rb +53 -0
- data/lib/multi_db/active_record_patches.rb +94 -0
- data/lib/multi_db/after_initialize_patches.rb +3 -0
- data/lib/multi_db/engine.rb +28 -0
- data/lib/multi_db/multidb.rake +360 -0
- data/lib/multi_db/organization.rb +60 -0
- data/lib/multi_db/organization_host.rb +7 -0
- data/lib/multidb.rb +10 -0
- data/multidb.gemspec +26 -0
- data/testapp_mysql2/.simplecov +3 -0
- data/testapp_mysql2/Gemfile +25 -0
- data/testapp_mysql2/Gemfile.lock +148 -0
- data/testapp_mysql2/Rakefile +7 -0
- data/testapp_mysql2/app/assets/javascripts/application.js +15 -0
- data/testapp_mysql2/app/assets/stylesheets/application.css +13 -0
- data/testapp_mysql2/app/controllers/application_controller.rb +3 -0
- data/testapp_mysql2/app/models/organization.rb +14 -0
- data/testapp_mysql2/app/views/layouts/application.html.erb +14 -0
- data/testapp_mysql2/config/application.rb +62 -0
- data/testapp_mysql2/config/boot.rb +6 -0
- data/testapp_mysql2/config/database.yml +17 -0
- data/testapp_mysql2/config/environment.rb +5 -0
- data/testapp_mysql2/config/environments/development.rb +37 -0
- data/testapp_mysql2/config/environments/production.rb +67 -0
- data/testapp_mysql2/config/environments/test.rb +37 -0
- data/testapp_mysql2/config/initializers/backtrace_silencers.rb +7 -0
- data/testapp_mysql2/config/initializers/inflections.rb +15 -0
- data/testapp_mysql2/config/initializers/mime_types.rb +5 -0
- data/testapp_mysql2/config/initializers/secret_token.rb +7 -0
- data/testapp_mysql2/config/initializers/session_store.rb +8 -0
- data/testapp_mysql2/config/initializers/wrap_parameters.rb +14 -0
- data/testapp_mysql2/config/routes.rb +58 -0
- data/testapp_mysql2/config.ru +4 -0
- data/testapp_mysql2/db/migrate/master/20140110031857_add_organizations_tables.rb +22 -0
- data/testapp_mysql2/db/migrate/sessions/20140110031856_add_sessions_table.rb +14 -0
- data/testapp_mysql2/db/schema_master.rb +35 -0
- data/testapp_mysql2/db/schema_organization.rb +16 -0
- data/testapp_mysql2/db/schema_sessions.rb +26 -0
- data/testapp_mysql2/log/.gitkeep +0 -0
- data/testapp_mysql2/script/rails +6 -0
- data/testapp_mysql2/spec/models/organization_spec.rb +61 -0
- data/testapp_mysql2/spec/spec_helper.rb +24 -0
- metadata +112 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
Testapp::Application.routes.draw do
|
2
|
+
# The priority is based upon order of creation:
|
3
|
+
# first created -> highest priority.
|
4
|
+
|
5
|
+
# Sample of regular route:
|
6
|
+
# match 'products/:id' => 'catalog#view'
|
7
|
+
# Keep in mind you can assign values other than :controller and :action
|
8
|
+
|
9
|
+
# Sample of named route:
|
10
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
+
|
13
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
+
# resources :products
|
15
|
+
|
16
|
+
# Sample resource route with options:
|
17
|
+
# resources :products do
|
18
|
+
# member do
|
19
|
+
# get 'short'
|
20
|
+
# post 'toggle'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# collection do
|
24
|
+
# get 'sold'
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Sample resource route with sub-resources:
|
29
|
+
# resources :products do
|
30
|
+
# resources :comments, :sales
|
31
|
+
# resource :seller
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Sample resource route with more complex sub-resources
|
35
|
+
# resources :products do
|
36
|
+
# resources :comments
|
37
|
+
# resources :sales do
|
38
|
+
# get 'recent', :on => :collection
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Sample resource route within a namespace:
|
43
|
+
# namespace :admin do
|
44
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
+
# # (app/controllers/admin/products_controller.rb)
|
46
|
+
# resources :products
|
47
|
+
# end
|
48
|
+
|
49
|
+
# You can have the root of your site routed with "root"
|
50
|
+
# just remember to delete public/index.html.
|
51
|
+
# root :to => 'welcome#index'
|
52
|
+
|
53
|
+
# See how all your routes lay out with "rake routes"
|
54
|
+
|
55
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
+
# match ':controller(/:action(/:id))(.:format)'
|
58
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class AddOrganizationsTables < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
create_table :organization_hosts do |t|
|
5
|
+
t.integer :organization_id, :null => false
|
6
|
+
t.string :host, :null => false
|
7
|
+
t.datetime :created_at, :null => false
|
8
|
+
t.datetime :updated_at, :null => false
|
9
|
+
end
|
10
|
+
add_index :organization_hosts, [:host], :unique => true
|
11
|
+
|
12
|
+
create_table :organizations do |t|
|
13
|
+
t.string :name
|
14
|
+
t.string :code, :null => false
|
15
|
+
t.boolean :active, :default => true, :null => false
|
16
|
+
t.datetime :created_at, :null => false
|
17
|
+
t.datetime :updated_at, :null => false
|
18
|
+
end
|
19
|
+
add_index :organizations, [:code], :unique => true
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class AddSessionsTable < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
create_table :sessions do |t|
|
5
|
+
t.string :session_id, :null => false
|
6
|
+
t.text :data
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :sessions, :session_id
|
11
|
+
add_index :sessions, :updated_at
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20140110031857) do
|
15
|
+
|
16
|
+
create_table "organization_hosts", :force => true do |t|
|
17
|
+
t.integer "organization_id", :null => false
|
18
|
+
t.string "host", :null => false
|
19
|
+
t.datetime "created_at", :null => false
|
20
|
+
t.datetime "updated_at", :null => false
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index "organization_hosts", ["host"], :name => "index_organization_hosts_on_host", :unique => true
|
24
|
+
|
25
|
+
create_table "organizations", :force => true do |t|
|
26
|
+
t.string "name"
|
27
|
+
t.string "code", :null => false
|
28
|
+
t.boolean "active", :default => true, :null => false
|
29
|
+
t.datetime "created_at", :null => false
|
30
|
+
t.datetime "updated_at", :null => false
|
31
|
+
end
|
32
|
+
|
33
|
+
add_index "organizations", ["code"], :name => "index_organizations_on_code", :unique => true
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 0) do
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20140110031856) do
|
15
|
+
|
16
|
+
create_table "sessions", :force => true do |t|
|
17
|
+
t.string "session_id", :null => false
|
18
|
+
t.text "data"
|
19
|
+
t.datetime "created_at", :null => false
|
20
|
+
t.datetime "updated_at", :null => false
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
|
24
|
+
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
|
25
|
+
|
26
|
+
end
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: organizations
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# name :string(255)
|
7
|
+
# code :string(255) not null
|
8
|
+
# active :boolean default(TRUE), not null
|
9
|
+
# created_at :datetime not null
|
10
|
+
# updated_at :datetime not null
|
11
|
+
#
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
|
15
|
+
describe Organization do
|
16
|
+
it { should have_many(:hosts) }
|
17
|
+
|
18
|
+
it { should validate_presence_of(:code) }
|
19
|
+
it { should validate_uniqueness_of(:code) }
|
20
|
+
|
21
|
+
describe "#ensure_code" do
|
22
|
+
it "creates a url-safe version of #name" do
|
23
|
+
org = Organization.new
|
24
|
+
org.name = 'Test Practice 1'
|
25
|
+
org.code = nil
|
26
|
+
expect(org.valid?).to be_true
|
27
|
+
expect(org.code).to eq 'test-practice-1'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "makes sure #code is never nil after validation (as long as name is set)" do
|
31
|
+
org = Organization.new
|
32
|
+
org.name = 'Testing 123'
|
33
|
+
org.code = nil
|
34
|
+
expect(org.code).to be_nil
|
35
|
+
expect(org.valid?).to be_true
|
36
|
+
expect(org.code).not_to be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "auto-increments generated #code (test2, test3, etc.) to work around conflicts" do
|
40
|
+
org = Organization.first
|
41
|
+
|
42
|
+
org2 = Organization.new
|
43
|
+
org2.name = org.code
|
44
|
+
org2.code = nil
|
45
|
+
expect(org2.valid?).to be_true
|
46
|
+
expect(org2.code).to eq "#{org.code}2"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "create_with_database" do
|
51
|
+
it "creates a new organization and creates database" do
|
52
|
+
org = nil
|
53
|
+
expect {
|
54
|
+
org = Organization.create_with_database('createusingdefaultstest', nil)
|
55
|
+
}.to change(Organization, :count).by(1)
|
56
|
+
org.drop_database!
|
57
|
+
org.destroy
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= 'test'
|
2
|
+
require 'simplecov'
|
3
|
+
require File.expand_path("../../config/environment", __FILE__)
|
4
|
+
|
5
|
+
require 'rspec/rails'
|
6
|
+
require 'rspec/autorun'
|
7
|
+
# require 'factory_girl_rails'
|
8
|
+
|
9
|
+
# Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.order = "random"
|
13
|
+
|
14
|
+
config.before(:suite) do
|
15
|
+
Organization.create_with_database('test', 'Developer Test Practice') unless Organization.find_by_code('test')
|
16
|
+
end
|
17
|
+
|
18
|
+
config.before(:each) do
|
19
|
+
Organization.first.connect
|
20
|
+
end
|
21
|
+
|
22
|
+
config.after(:suite) do
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multidb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Namba
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.2.16
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.2.16
|
33
|
+
description: Enables multitenant setup with one database per tenant. See README for
|
34
|
+
details.
|
35
|
+
email: aaron@biggerbird.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- ".gitignore"
|
41
|
+
- ".rspec"
|
42
|
+
- ".ruby-version"
|
43
|
+
- Gemfile
|
44
|
+
- LICENSE.md
|
45
|
+
- README.md
|
46
|
+
- lib/multi_db/action_controller_patches.rb
|
47
|
+
- lib/multi_db/active_record_patches.rb
|
48
|
+
- lib/multi_db/after_initialize_patches.rb
|
49
|
+
- lib/multi_db/engine.rb
|
50
|
+
- lib/multi_db/multidb.rake
|
51
|
+
- lib/multi_db/organization.rb
|
52
|
+
- lib/multi_db/organization_host.rb
|
53
|
+
- lib/multidb.rb
|
54
|
+
- multidb.gemspec
|
55
|
+
- testapp_mysql2/.simplecov
|
56
|
+
- testapp_mysql2/Gemfile
|
57
|
+
- testapp_mysql2/Gemfile.lock
|
58
|
+
- testapp_mysql2/Rakefile
|
59
|
+
- testapp_mysql2/app/assets/javascripts/application.js
|
60
|
+
- testapp_mysql2/app/assets/stylesheets/application.css
|
61
|
+
- testapp_mysql2/app/controllers/application_controller.rb
|
62
|
+
- testapp_mysql2/app/models/organization.rb
|
63
|
+
- testapp_mysql2/app/views/layouts/application.html.erb
|
64
|
+
- testapp_mysql2/config.ru
|
65
|
+
- testapp_mysql2/config/application.rb
|
66
|
+
- testapp_mysql2/config/boot.rb
|
67
|
+
- testapp_mysql2/config/database.yml
|
68
|
+
- testapp_mysql2/config/environment.rb
|
69
|
+
- testapp_mysql2/config/environments/development.rb
|
70
|
+
- testapp_mysql2/config/environments/production.rb
|
71
|
+
- testapp_mysql2/config/environments/test.rb
|
72
|
+
- testapp_mysql2/config/initializers/backtrace_silencers.rb
|
73
|
+
- testapp_mysql2/config/initializers/inflections.rb
|
74
|
+
- testapp_mysql2/config/initializers/mime_types.rb
|
75
|
+
- testapp_mysql2/config/initializers/secret_token.rb
|
76
|
+
- testapp_mysql2/config/initializers/session_store.rb
|
77
|
+
- testapp_mysql2/config/initializers/wrap_parameters.rb
|
78
|
+
- testapp_mysql2/config/routes.rb
|
79
|
+
- testapp_mysql2/db/migrate/master/20140110031857_add_organizations_tables.rb
|
80
|
+
- testapp_mysql2/db/migrate/sessions/20140110031856_add_sessions_table.rb
|
81
|
+
- testapp_mysql2/db/schema_master.rb
|
82
|
+
- testapp_mysql2/db/schema_organization.rb
|
83
|
+
- testapp_mysql2/db/schema_sessions.rb
|
84
|
+
- testapp_mysql2/log/.gitkeep
|
85
|
+
- testapp_mysql2/script/rails
|
86
|
+
- testapp_mysql2/spec/models/organization_spec.rb
|
87
|
+
- testapp_mysql2/spec/spec_helper.rb
|
88
|
+
homepage: https://github.com/anamba/imagine_cms
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.9.3
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 1.8.11
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.0.rc.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: MultiDB for ActiveRecord
|
112
|
+
test_files: []
|