data_fabric 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,12 @@
1
1
  DataFabric changelog
2
2
 
3
+ v1.3.3 - 2011-10-29
4
+
5
+ - Added ConnectionProxy#respond_to? which delegates to underlying connection
6
+ (Paul Gross and Dan Manges)
7
+ - Remove specific handling of nested transactions and let the underlying
8
+ connection handle it (Paul Gross and Dan Manges)
9
+
3
10
  v1.3.2 - 2011-06-02
4
11
 
5
12
  - Fix problem fetching spec for connection pool.
@@ -0,0 +1,29 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 20080702154820) do
14
+
15
+ create_table "accounts", :force => true do |t|
16
+ t.string "name"
17
+ t.string "shard"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
20
+ end
21
+
22
+ create_table "figments", :force => true do |t|
23
+ t.integer "account_id"
24
+ t.integer "value"
25
+ t.datetime "created_at"
26
+ t.datetime "updated_at"
27
+ end
28
+
29
+ end
Binary file
@@ -0,0 +1,66 @@
1
+ SQL (0.4ms)  SELECT name
2
+ FROM sqlite_master
3
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
4
+ 
5
+ SQL (0.1ms) select sqlite_version(*)
6
+ SQL (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
7
+ SQL (0.0ms) PRAGMA index_list("schema_migrations")
8
+ SQL (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
9
+ SQL (0.1ms) SELECT name
10
+ FROM sqlite_master
11
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
12
+ SQL (0.1ms)  SELECT name
13
+ FROM sqlite_master
14
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
15
+ 
16
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
17
+ Migrating to CreateAccounts (20080702154628)
18
+ SQL (0.5ms) CREATE TABLE "accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "shard" varchar(255), "created_at" datetime, "updated_at" datetime) 
19
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20080702154628')
20
+ Migrating to CreateFigments (20080702154820)
21
+ SQL (0.5ms) CREATE TABLE "figments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "account_id" integer, "value" integer, "created_at" datetime, "updated_at" datetime) 
22
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20080702154820')
23
+ SQL (0.2ms)  SELECT name
24
+ FROM sqlite_master
25
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
26
+ 
27
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
28
+ SQL (0.1ms)  SELECT name
29
+ FROM sqlite_master
30
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
31
+ 
32
+ SQL (0.0ms) PRAGMA index_list("accounts")
33
+ SQL (0.0ms) PRAGMA index_list("figments")
34
+ SQL (0.5ms)  SELECT name
35
+ FROM sqlite_master
36
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
37
+ 
38
+ SQL (0.1ms) SELECT name
39
+ FROM sqlite_master
40
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
41
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
42
+ SQL (0.2ms) select sqlite_version(*)
43
+ SQL (0.1ms)  SELECT name
44
+ FROM sqlite_master
45
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
46
+ 
47
+ SQL (1.9ms) CREATE TABLE "accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "shard" varchar(255), "created_at" datetime, "updated_at" datetime)
48
+ SQL (0.3ms)  SELECT name
49
+ FROM sqlite_master
50
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
51
+ 
52
+ SQL (1.4ms) CREATE TABLE "figments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "account_id" integer, "value" integer, "created_at" datetime, "updated_at" datetime)
53
+ SQL (0.1ms)  SELECT name
54
+ FROM sqlite_master
55
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
56
+ 
57
+ SQL (1.9ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
58
+ SQL (0.0ms) PRAGMA index_list("schema_migrations")
59
+ SQL (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
60
+ SQL (0.1ms)  SELECT name
61
+ FROM sqlite_master
62
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
63
+ 
64
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
65
+ SQL (1.3ms) INSERT INTO "schema_migrations" (version) VALUES ('20080702154820')
66
+ SQL (0.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20080702154628')
@@ -0,0 +1,170 @@
1
+ SQL (0.4ms)  SELECT name
2
+ FROM sqlite_master
3
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
4
+ 
5
+ SQL (0.1ms) select sqlite_version(*)
6
+ SQL (1.6ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
7
+ SQL (0.0ms) PRAGMA index_list("schema_migrations")
8
+ SQL (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
9
+ SQL (0.1ms) SELECT name
10
+ FROM sqlite_master
11
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
12
+ SQL (0.1ms)  SELECT name
13
+ FROM sqlite_master
14
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
15
+ 
16
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
17
+ Migrating to CreateAccounts (20080702154628)
18
+ SQL (0.4ms) CREATE TABLE "accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "shard" varchar(255), "created_at" datetime, "updated_at" datetime) 
19
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20080702154628')
20
+ Migrating to CreateFigments (20080702154820)
21
+ SQL (0.4ms) CREATE TABLE "figments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "account_id" integer, "value" integer, "created_at" datetime, "updated_at" datetime) 
22
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20080702154820')
23
+ SQL (0.2ms)  SELECT name
24
+ FROM sqlite_master
25
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
26
+ 
27
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
28
+ SQL (0.1ms)  SELECT name
29
+ FROM sqlite_master
30
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
31
+ 
32
+ SQL (0.0ms) PRAGMA index_list("accounts")
33
+ SQL (0.0ms) PRAGMA index_list("figments")
34
+ Processing by AccountsController#index as HTML
35
+ Account Load (0.3ms) SELECT "accounts".* FROM "accounts"
36
+ Rendered accounts/index.html.erb within layouts/application (7.1ms)
37
+ Completed 200 OK in 40ms (Views: 11.3ms | ActiveRecord: 0.9ms)
38
+ SQL (1.0ms) delete from figments
39
+ SQL (1.0ms) delete from figments
40
+ SQL (0.1ms) select count(*) as c from figments
41
+ SQL (0.1ms) select count(*) as c from figments
42
+
43
+
44
+ Started GET "/accounts" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
45
+ Processing by AccountsController#index as HTML
46
+ Account Load (0.3ms) SELECT "accounts".* FROM "accounts"
47
+ Rendered accounts/index.html.erb within layouts/application (33.1ms)
48
+ Completed 200 OK in 64ms (Views: 35.3ms | ActiveRecord: 3.2ms)
49
+
50
+
51
+ Started POST "/accounts" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
52
+ Processing by AccountsController#create as HTML
53
+ Parameters: {"acct"=>{"name"=>"mike", "shard"=>"0"}}
54
+ SQL (0.2ms) SELECT name
55
+ FROM sqlite_master
56
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
57
+ AREL (0.3ms) INSERT INTO "accounts" ("name", "shard", "created_at", "updated_at") VALUES ('mike', '0', '2011-10-30 00:25:50.668938', '2011-10-30 00:25:50.668938')
58
+ Redirected to http://www.example.com/
59
+ Completed 302 Found in 9ms
60
+
61
+
62
+ Started GET "/" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
63
+ Processing by AccountsController#index as HTML
64
+ Account Load (0.2ms) SELECT "accounts".* FROM "accounts"
65
+ Rendered accounts/index.html.erb within layouts/application (1.8ms)
66
+ Completed 200 OK in 3ms (Views: 2.3ms | ActiveRecord: 0.7ms)
67
+ Account Load (0.2ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."name" = 'mike') LIMIT 1
68
+
69
+
70
+ Started GET "/accounts/1033447817/choose" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
71
+ Processing by AccountsController#choose as HTML
72
+ Parameters: {"id"=>"1033447817"}
73
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447817) LIMIT 1
74
+ Redirected to http://www.example.com/
75
+ Completed 302 Found in 1ms
76
+
77
+
78
+ Started GET "/" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
79
+ Processing by AccountsController#index as HTML
80
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447817) LIMIT 1
81
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts"
82
+ Figment Load (0.4ms) SELECT "figments".* FROM "figments" WHERE ("figments".account_id = 1033447817)
83
+ Rendered accounts/index.html.erb within layouts/application (10.2ms)
84
+ Completed 200 OK in 12ms (Views: 10.4ms | ActiveRecord: 0.9ms)
85
+ SQL (0.2ms) SELECT COUNT(*) FROM "figments" WHERE ("figments".account_id = 1033447817)
86
+
87
+
88
+ Started POST "/figments" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
89
+ Processing by FigmentsController#create as HTML
90
+ Parameters: {"figment"=>{"value"=>"14"}}
91
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447817) LIMIT 1
92
+ AREL (0.4ms) INSERT INTO "figments" ("account_id", "value", "created_at", "updated_at") VALUES (1033447817, 14, '2011-10-30 00:25:50.718857', '2011-10-30 00:25:50.718857')
93
+ Redirected to http://www.example.com/
94
+ Completed 302 Found in 45ms
95
+
96
+
97
+ Started GET "/" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
98
+ Processing by AccountsController#index as HTML
99
+ Account Load (0.2ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447817) LIMIT 1
100
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts"
101
+ Figment Load (0.2ms) SELECT "figments".* FROM "figments" WHERE ("figments".account_id = 1033447817)
102
+ CACHE (0.0ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447817) LIMIT 1
103
+ Rendered accounts/index.html.erb within layouts/application (8.1ms)
104
+ Completed 200 OK in 10ms (Views: 8.4ms | ActiveRecord: 1.2ms)
105
+ Figment Load (0.2ms) SELECT "figments".* FROM "figments" WHERE ("figments".account_id = 1033447817)
106
+ SQL (0.1ms) select count(*) as c from figments
107
+ SQL (0.1ms) select count(*) as c from figments
108
+
109
+
110
+ Started GET "/accounts" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
111
+ Processing by AccountsController#index as HTML
112
+ Account Load (0.2ms) SELECT "accounts".* FROM "accounts"
113
+ Rendered accounts/index.html.erb within layouts/application (1.8ms)
114
+ Completed 200 OK in 3ms (Views: 2.3ms | ActiveRecord: 0.6ms)
115
+
116
+
117
+ Started POST "/accounts" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
118
+ Processing by AccountsController#create as HTML
119
+ Parameters: {"acct"=>{"name"=>"bob", "shard"=>"1"}}
120
+ AREL (0.1ms) INSERT INTO "accounts" ("name", "shard", "created_at", "updated_at") VALUES ('bob', '1', '2011-10-30 00:25:50.780179', '2011-10-30 00:25:50.780179')
121
+ Redirected to http://www.example.com/
122
+ Completed 302 Found in 1ms
123
+
124
+
125
+ Started GET "/" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
126
+ Processing by AccountsController#index as HTML
127
+ Account Load (0.2ms) SELECT "accounts".* FROM "accounts"
128
+ Rendered accounts/index.html.erb within layouts/application (1.8ms)
129
+ Completed 200 OK in 3ms (Views: 2.2ms | ActiveRecord: 0.3ms)
130
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."name" = 'bob') LIMIT 1
131
+
132
+
133
+ Started GET "/accounts/1033447818/choose" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
134
+ Processing by AccountsController#choose as HTML
135
+ Parameters: {"id"=>"1033447818"}
136
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447818) LIMIT 1
137
+ Redirected to http://www.example.com/
138
+ Completed 302 Found in 1ms
139
+
140
+
141
+ Started GET "/" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
142
+ Processing by AccountsController#index as HTML
143
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447818) LIMIT 1
144
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts"
145
+ Figment Load (0.3ms) SELECT "figments".* FROM "figments" WHERE ("figments".account_id = 1033447818)
146
+ Rendered accounts/index.html.erb within layouts/application (4.4ms)
147
+ Completed 200 OK in 6ms (Views: 4.5ms | ActiveRecord: 0.7ms)
148
+ SQL (0.1ms) SELECT COUNT(*) FROM "figments" WHERE ("figments".account_id = 1033447818)
149
+
150
+
151
+ Started POST "/figments" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
152
+ Processing by FigmentsController#create as HTML
153
+ Parameters: {"figment"=>{"value"=>"66"}}
154
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447818) LIMIT 1
155
+ AREL (0.3ms) INSERT INTO "figments" ("account_id", "value", "created_at", "updated_at") VALUES (1033447818, 66, '2011-10-30 00:25:50.801327', '2011-10-30 00:25:50.801327')
156
+ Redirected to http://www.example.com/
157
+ Completed 302 Found in 4ms
158
+
159
+
160
+ Started GET "/" for 127.0.0.1 at 2011-10-29 17:25:50 -0700
161
+ Processing by AccountsController#index as HTML
162
+ Account Load (0.2ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447818) LIMIT 1
163
+ Account Load (0.1ms) SELECT "accounts".* FROM "accounts"
164
+ Figment Load (0.2ms) SELECT "figments".* FROM "figments" WHERE ("figments".account_id = 1033447818)
165
+ CACHE (0.0ms) SELECT "accounts".* FROM "accounts" WHERE ("accounts"."id" = 1033447818) LIMIT 1
166
+ Rendered accounts/index.html.erb within layouts/application (3.4ms)
167
+ Completed 200 OK in 5ms (Views: 3.6ms | ActiveRecord: 1.1ms)
168
+ Figment Load (0.2ms) SELECT "figments".* FROM "figments" WHERE ("figments".account_id = 1033447818)
169
+ SQL (0.1ms) select count(*) as c from figments
170
+ SQL (0.1ms) select count(*) as c from figments
@@ -41,7 +41,8 @@ require 'data_fabric/version'
41
41
  module DataFabric
42
42
 
43
43
  def self.logger
44
- @logger ||= ActiveRecord::Base.logger || Logger.new('/dev/null')
44
+ devnull = RUBY_PLATFORM =~ /w32/ ? 'nul' : '/dev/null'
45
+ @logger ||= ActiveRecord::Base.logger || Logger.new(devnull)
45
46
  end
46
47
 
47
48
  def self.logger=(log)
@@ -17,7 +17,7 @@ module DataFabric
17
17
  @proc.call
18
18
  end
19
19
  end
20
-
20
+
21
21
  class PoolProxy
22
22
  def initialize(proxy)
23
23
  @proxy = proxy
@@ -47,7 +47,7 @@ module DataFabric
47
47
  end
48
48
  end
49
49
 
50
- %w(columns columns_hash table_exists? primary_keys).each do |name|
50
+ %w(columns column_defaults columns_hash table_exists? primary_keys).each do |name|
51
51
  define_method(name.to_sym) do |*args|
52
52
  @proxy.current_pool.send(name.to_sym, *args)
53
53
  end
@@ -61,7 +61,7 @@ module DataFabric
61
61
 
62
62
  class ConnectionProxy
63
63
  cattr_accessor :shard_pools
64
-
64
+
65
65
  def initialize(model_class, options)
66
66
  @model_class = model_class
67
67
  @replicated = options[:replicated]
@@ -79,16 +79,15 @@ module DataFabric
79
79
  delegate :insert_many, :to => :master # ar-extensions bulk insert support
80
80
 
81
81
  def transaction(start_db_transaction = true, &block)
82
- # Transaction is not re-entrant in SQLite 3 so we
83
- # need to track if we've already started an XA to avoid
84
- # calling it twice.
85
- return yield if in_transaction?
86
-
87
82
  with_master do
88
- connection.transaction(start_db_transaction, &block)
83
+ connection.transaction(start_db_transaction, &block)
89
84
  end
90
85
  end
91
86
 
87
+ def respond_to?(method)
88
+ super || connection.respond_to?(method)
89
+ end
90
+
92
91
  def method_missing(method, *args, &block)
93
92
  DataFabric.logger.debug { "Calling #{method} on #{connection}" }
94
93
  connection.send(method, *args, &block)
@@ -106,7 +105,7 @@ module DataFabric
106
105
  ensure
107
106
  set_role(old_role)
108
107
  end
109
-
108
+
110
109
  def connected?
111
110
  current_pool.connected?
112
111
  end
@@ -123,21 +122,16 @@ module DataFabric
123
122
  ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec_for(config))
124
123
  end
125
124
  end
126
-
127
- private
128
125
 
129
- def in_transaction?
130
- current_role == 'master'
131
- end
126
+ private
132
127
 
133
128
  def spec_for(config)
134
- # XXX This looks pretty fragile. Will break if AR changes how it initializes connections and adapters.
135
129
  config = config.symbolize_keys
136
130
  adapter_method = "#{config[:adapter]}_connection"
137
131
  initialize_adapter(config[:adapter])
138
132
  ActiveRecord::Base::ConnectionSpecification.new(config, adapter_method)
139
133
  end
140
-
134
+
141
135
  def initialize_adapter(adapter)
142
136
  begin
143
137
  require 'rubygems'
@@ -150,7 +144,7 @@ module DataFabric
150
144
  raise "Please install the #{adapter} adapter: `gem install activerecord-#{adapter}-adapter` (#{$!})"
151
145
  end
152
146
  end
153
- end
147
+ end
154
148
 
155
149
  def connection_name_builder
156
150
  @connection_name_builder ||= begin
@@ -163,11 +157,11 @@ module DataFabric
163
157
  clauses
164
158
  end
165
159
  end
166
-
160
+
167
161
  def set_role(role)
168
162
  Thread.current[:data_fabric_role] = role
169
163
  end
170
-
164
+
171
165
  def current_role
172
166
  Thread.current[:data_fabric_role] || 'slave'
173
167
  end
@@ -177,4 +171,4 @@ module DataFabric
177
171
  end
178
172
  end
179
173
 
180
- end
174
+ end
@@ -1,5 +1,5 @@
1
1
  module DataFabric
2
2
  module Version
3
- STRING = '1.3.2'
3
+ STRING = '1.3.3'
4
4
  end
5
5
  end
@@ -1,6 +1,8 @@
1
1
  require 'test_helper'
2
2
  require 'flexmock/test_unit'
3
3
 
4
+ require 'active_record/connection_adapters/mysql_adapter'
5
+
4
6
  class PrefixModel < ActiveRecord::Base
5
7
  data_fabric :prefix => 'prefix'
6
8
  end
@@ -16,33 +18,37 @@ end
16
18
  class AdapterMock < ActiveRecord::ConnectionAdapters::AbstractAdapter
17
19
  # Minimum required to perform a find with no results.
18
20
  # Works on 2.3.10, 3.0.0 and 3.0.3.
19
- def columns(table_name, name=nil)
20
- [ActiveRecord::ConnectionAdapters::Column.new('id', 0, :integer, false)]
21
- end
22
- def primary_key(name)
23
- :id
24
- end
25
- def adapter_name
26
- 'mysql'
27
- end
28
- def select(sql, name=nil)
29
- []
30
- end
31
- def execute(sql, name=nil)
32
- []
33
- end
34
- def tables
35
- ["enchiladas", "the_whole_burritos"]
36
- end
37
- def table_exists?(name)
38
- true
39
- end
40
- def last_inserted_id(result)
41
- 1
42
- end
43
- def method_missing(name, *args)
44
- raise ArgumentError, "#{self.class.name} missing '#{name}': #{args.inspect}"
45
- end
21
+ def columns(table_name, name=nil)
22
+ [ActiveRecord::ConnectionAdapters::Column.new('id', 0, :integer, false)]
23
+ end
24
+ def primary_key(name)
25
+ :id
26
+ end
27
+ def adapter_name
28
+ 'mysql'
29
+ end
30
+ def select(sql, name=nil, bindings=nil)
31
+ []
32
+ end
33
+ def execute(sql, name=nil)
34
+ []
35
+ end
36
+ def tables
37
+ ["enchiladas", "the_whole_burritos"]
38
+ end
39
+ def table_exists?(name)
40
+ true
41
+ end
42
+ def last_inserted_id(result)
43
+ 1
44
+ end
45
+ def method_missing(name, *args)
46
+ raise ArgumentError, "#{self.class.name} missing '#{name}': #{args.inspect}"
47
+ end
48
+
49
+ def self.visitor_for(pool)
50
+ Arel::Visitors::MySQL.new(pool)
51
+ end
46
52
  end
47
53
 
48
54
  class RawConnection
@@ -58,12 +64,12 @@ class ConnectionTest < Test::Unit::TestCase
58
64
  meth = PrefixModel.methods.first.is_a?(Symbol) ? :data_fabric : 'data_fabric'
59
65
  assert PrefixModel.methods.include?(meth)
60
66
  end
61
-
67
+
62
68
  def test_prefix_connection_name
63
69
  setup_configuration_for PrefixModel, 'prefix_test'
64
70
  assert_equal 'prefix_test', PrefixModel.connection.connection_name
65
71
  end
66
-
72
+
67
73
  def test_shard_connection_name
68
74
  setup_configuration_for ShardModel, 'city_austin_test'
69
75
  # ensure unset means error
@@ -78,7 +84,24 @@ class ConnectionTest < Test::Unit::TestCase
78
84
  ShardModel.connection.connection_name
79
85
  end
80
86
  end
81
-
87
+
88
+ def test_respond_to_connection_methods
89
+ setup_configuration_for ShardModel, 'city_austin_test'
90
+ DataFabric.activate_shard(:city => 'austin', :category => 'art') do
91
+ assert ShardModel.connection.respond_to?(:columns)
92
+ assert ShardModel.connection.respond_to?(:primary_key)
93
+ assert !ShardModel.connection.respond_to?(:nonexistent_method)
94
+ end
95
+ end
96
+
97
+ def test_respond_to_connection_proxy_methods
98
+ setup_configuration_for ShardModel, 'city_austin_test'
99
+ DataFabric.activate_shard(:city => 'austin', :category => 'art') do
100
+ assert ShardModel.connection.respond_to?(:with_master)
101
+ assert !ShardModel.connection.respond_to?(:nonexistent_method)
102
+ end
103
+ end
104
+
82
105
  def test_enchilada
83
106
  setup_configuration_for TheWholeEnchilada, 'fiveruns_city_dallas_test_slave'
84
107
  setup_configuration_for TheWholeEnchilada, 'fiveruns_city_dallas_test_master'
@@ -89,7 +112,7 @@ class ConnectionTest < Test::Unit::TestCase
89
112
  assert_raises ActiveRecord::RecordNotFound do
90
113
  TheWholeEnchilada.find(1)
91
114
  end
92
-
115
+
93
116
  # Should use the master
94
117
  mmmm = TheWholeEnchilada.new
95
118
  mmmm.instance_variable_set(:@attributes, { 'id' => 1 })
@@ -98,7 +121,7 @@ class ConnectionTest < Test::Unit::TestCase
98
121
  end
99
122
  # ...but immediately set it back to default to the slave
100
123
  assert_equal 'fiveruns_city_dallas_test_slave', TheWholeEnchilada.connection.connection_name
101
-
124
+
102
125
  # Should use the master
103
126
  TheWholeEnchilada.transaction do
104
127
  mmmm.save!
@@ -114,11 +137,10 @@ class ConnectionTest < Test::Unit::TestCase
114
137
  end
115
138
 
116
139
  private
117
-
140
+
118
141
  def setup_configuration_for(clazz, name)
119
- flexmock(ActiveRecord::ConnectionAdapters::ConnectionPool).new_instances.should_receive(
120
- :new_connection).and_return(AdapterMock.new(RawConnection.new))
142
+ flexmock(ActiveRecord::Base).should_receive(:mysql_connection).and_return(AdapterMock.new(RawConnection.new))
121
143
  ActiveRecord::Base.configurations ||= HashWithIndifferentAccess.new
122
144
  ActiveRecord::Base.configurations[name] = HashWithIndifferentAccess.new({ :adapter => 'mysql', :database => name, :host => 'localhost'})
123
145
  end
124
- end
146
+ end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
  require 'erb'
3
3
 
4
4
  class ThreadTest < Test::Unit::TestCase
5
-
5
+
6
6
  MUTEX = Mutex.new
7
7
 
8
8
  def test_class_and_instance_connections
@@ -18,7 +18,7 @@ class ThreadTest < Test::Unit::TestCase
18
18
  iconn = ThreadedEnchilada.new.connection
19
19
  assert_equal cconn, iconn
20
20
  end
21
-
21
+
22
22
  def xtest_threaded_access
23
23
  clear_databases
24
24
 
@@ -48,7 +48,7 @@ class ThreadTest < Test::Unit::TestCase
48
48
  end
49
49
  end
50
50
  threads.each { |thread| thread.join }
51
-
51
+
52
52
  counts.each_pair do |city, count|
53
53
  DataFabric.activate_shard(:city => city) do
54
54
  # slave should be empty
@@ -62,9 +62,9 @@ class ThreadTest < Test::Unit::TestCase
62
62
  end
63
63
  end
64
64
  end
65
-
65
+
66
66
  private
67
-
67
+
68
68
  def clear_databases
69
69
  ActiveRecord::Base.configurations = { 'test' => { :adapter => 'mysql', :host => 'localhost', :database => 'mysql' } }
70
70
  ActiveRecord::Base.establish_connection 'test'
@@ -77,7 +77,7 @@ class ThreadTest < Test::Unit::TestCase
77
77
  end
78
78
  ActiveRecord::Base.clear_active_connections!
79
79
  end
80
-
80
+
81
81
  def using_connection(&block)
82
82
  ActiveRecord::Base.connection.instance_eval(&block)
83
83
  end
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,52 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: data_fabric
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.3
4
5
  prerelease:
5
- version: 1.3.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Mike Perham
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-03 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: flexmock
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2157070860 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: sqlite3
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2157070860
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &2157069320 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
35
33
  type: :development
36
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *2157069320
37
36
  description: Sharding and replication support for ActiveRecord
38
37
  email: mperham@gmail.com
39
38
  executables: []
40
-
41
39
  extensions: []
42
-
43
- extra_rdoc_files:
40
+ extra_rdoc_files:
44
41
  - README.rdoc
45
- files:
42
+ files:
46
43
  - lib/data_fabric/connection_proxy.rb
47
44
  - lib/data_fabric/extensions.rb
48
45
  - lib/data_fabric/version.rb
49
- - lib/data_fabric/version.rbc
50
46
  - lib/data_fabric.rb
51
47
  - example23/app/controllers/accounts_controller.rb
52
48
  - example23/app/controllers/application_controller.rb
@@ -122,11 +118,20 @@ files:
122
118
  - example30/config/locales/en.yml
123
119
  - example30/config/routes.rb
124
120
  - example30/config.ru
121
+ - example30/db/development.sqlite3
125
122
  - example30/db/migrate/20080702154628_create_accounts.rb
126
123
  - example30/db/migrate/20080702154820_create_figments.rb
124
+ - example30/db/s0_development.sqlite3
125
+ - example30/db/s0_test.sqlite3
126
+ - example30/db/s1_development.sqlite3
127
+ - example30/db/s1_test.sqlite3
128
+ - example30/db/schema.rb
127
129
  - example30/db/seeds.rb
130
+ - example30/db/test.sqlite3
128
131
  - example30/Gemfile
129
132
  - example30/Gemfile.lock
133
+ - example30/log/development.log
134
+ - example30/log/test.log
130
135
  - example30/Rakefile
131
136
  - example30/README
132
137
  - example30/script/rails
@@ -152,32 +157,29 @@ files:
152
157
  - test/vr_dallas_slave.db
153
158
  homepage: http://github.com/mperham/data_fabric
154
159
  licenses: []
155
-
156
160
  post_install_message:
157
161
  rdoc_options: []
158
-
159
- require_paths:
162
+ require_paths:
160
163
  - lib
161
- required_ruby_version: !ruby/object:Gem::Requirement
164
+ required_ruby_version: !ruby/object:Gem::Requirement
162
165
  none: false
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: "0"
167
- required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
171
  none: false
169
- requirements:
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- version: "0"
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
173
176
  requirements: []
174
-
175
177
  rubyforge_project:
176
- rubygems_version: 1.7.2
178
+ rubygems_version: 1.8.10
177
179
  signing_key:
178
180
  specification_version: 3
179
181
  summary: Sharding and replication support for ActiveRecord
180
- test_files:
182
+ test_files:
181
183
  - test/connection_test.rb
182
184
  - test/database.yml
183
185
  - test/database.yml.mysql
@@ -1,203 +0,0 @@
1
- !RBIX
2
- 17831730954501249321
3
- x
4
- M
5
- 1
6
- n
7
- n
8
- x
9
- 10
10
- __script__
11
- i
12
- 28
13
- 99
14
- 7
15
- 0
16
- 65
17
- 49
18
- 1
19
- 2
20
- 13
21
- 99
22
- 12
23
- 7
24
- 2
25
- 12
26
- 7
27
- 3
28
- 12
29
- 65
30
- 12
31
- 49
32
- 4
33
- 4
34
- 15
35
- 49
36
- 2
37
- 0
38
- 15
39
- 2
40
- 11
41
- I
42
- 6
43
- I
44
- 0
45
- I
46
- 0
47
- I
48
- 0
49
- n
50
- p
51
- 5
52
- x
53
- 10
54
- DataFabric
55
- x
56
- 11
57
- open_module
58
- x
59
- 15
60
- __module_init__
61
- M
62
- 1
63
- n
64
- n
65
- x
66
- 10
67
- DataFabric
68
- i
69
- 28
70
- 5
71
- 66
72
- 99
73
- 7
74
- 0
75
- 65
76
- 49
77
- 1
78
- 2
79
- 13
80
- 99
81
- 12
82
- 7
83
- 2
84
- 12
85
- 7
86
- 3
87
- 12
88
- 65
89
- 12
90
- 49
91
- 4
92
- 4
93
- 15
94
- 49
95
- 2
96
- 0
97
- 11
98
- I
99
- 6
100
- I
101
- 0
102
- I
103
- 0
104
- I
105
- 0
106
- n
107
- p
108
- 5
109
- x
110
- 7
111
- Version
112
- x
113
- 11
114
- open_module
115
- x
116
- 15
117
- __module_init__
118
- M
119
- 1
120
- n
121
- n
122
- x
123
- 7
124
- Version
125
- i
126
- 12
127
- 5
128
- 66
129
- 65
130
- 7
131
- 0
132
- 7
133
- 1
134
- 64
135
- 49
136
- 2
137
- 2
138
- 11
139
- I
140
- 3
141
- I
142
- 0
143
- I
144
- 0
145
- I
146
- 0
147
- n
148
- p
149
- 3
150
- x
151
- 6
152
- STRING
153
- s
154
- 5
155
- 1.3.1
156
- x
157
- 9
158
- const_set
159
- p
160
- 3
161
- I
162
- 2
163
- I
164
- 3
165
- I
166
- c
167
- x
168
- 61
169
- /Users/mperham/src/git/data_fabric/lib/data_fabric/version.rb
170
- p
171
- 0
172
- x
173
- 13
174
- attach_method
175
- p
176
- 3
177
- I
178
- 2
179
- I
180
- 2
181
- I
182
- 1c
183
- x
184
- 61
185
- /Users/mperham/src/git/data_fabric/lib/data_fabric/version.rb
186
- p
187
- 0
188
- x
189
- 13
190
- attach_method
191
- p
192
- 3
193
- I
194
- 0
195
- I
196
- 1
197
- I
198
- 1c
199
- x
200
- 61
201
- /Users/mperham/src/git/data_fabric/lib/data_fabric/version.rb
202
- p
203
- 0