sequel 3.32.0 → 3.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/CHANGELOG +42 -0
  2. data/Rakefile +3 -2
  3. data/doc/migration.rdoc +41 -14
  4. data/doc/opening_databases.rdoc +2 -0
  5. data/doc/release_notes/3.29.0.txt +1 -1
  6. data/doc/release_notes/3.33.0.txt +157 -0
  7. data/doc/sharding.rdoc +93 -7
  8. data/doc/testing.rdoc +1 -1
  9. data/lib/sequel/adapters/do.rb +1 -0
  10. data/lib/sequel/adapters/do/mysql.rb +6 -0
  11. data/lib/sequel/adapters/jdbc.rb +1 -0
  12. data/lib/sequel/adapters/jdbc/mysql.rb +0 -5
  13. data/lib/sequel/adapters/mock.rb +10 -5
  14. data/lib/sequel/adapters/mysql.rb +23 -1
  15. data/lib/sequel/adapters/mysql2.rb +16 -2
  16. data/lib/sequel/adapters/postgres.rb +22 -4
  17. data/lib/sequel/adapters/shared/mysql.rb +51 -10
  18. data/lib/sequel/adapters/shared/postgres.rb +101 -63
  19. data/lib/sequel/adapters/shared/sqlite.rb +19 -0
  20. data/lib/sequel/adapters/sqlite.rb +71 -16
  21. data/lib/sequel/adapters/swift.rb +1 -0
  22. data/lib/sequel/connection_pool.rb +1 -1
  23. data/lib/sequel/connection_pool/sharded_single.rb +6 -1
  24. data/lib/sequel/connection_pool/sharded_threaded.rb +6 -1
  25. data/lib/sequel/connection_pool/threaded.rb +12 -11
  26. data/lib/sequel/database/connecting.rb +2 -0
  27. data/lib/sequel/database/misc.rb +6 -0
  28. data/lib/sequel/database/query.rb +1 -1
  29. data/lib/sequel/extensions/arbitrary_servers.rb +108 -0
  30. data/lib/sequel/extensions/migration.rb +45 -7
  31. data/lib/sequel/extensions/server_block.rb +139 -0
  32. data/lib/sequel/model/associations.rb +9 -9
  33. data/lib/sequel/model/inflections.rb +1 -1
  34. data/lib/sequel/plugins/instance_hooks.rb +1 -1
  35. data/lib/sequel/plugins/json_serializer.rb +1 -1
  36. data/lib/sequel/plugins/list.rb +12 -2
  37. data/lib/sequel/version.rb +1 -1
  38. data/spec/adapters/mysql_spec.rb +64 -8
  39. data/spec/adapters/postgres_spec.rb +139 -78
  40. data/spec/adapters/sqlite_spec.rb +87 -0
  41. data/spec/core/connection_pool_spec.rb +14 -0
  42. data/spec/core/database_spec.rb +5 -0
  43. data/spec/core/mock_adapter_spec.rb +21 -9
  44. data/spec/extensions/arbitrary_servers_spec.rb +114 -0
  45. data/spec/extensions/instance_hooks_spec.rb +19 -0
  46. data/spec/extensions/list_spec.rb +31 -0
  47. data/spec/extensions/migration_spec.rb +61 -4
  48. data/spec/extensions/server_block_spec.rb +90 -0
  49. data/spec/extensions/spec_helper.rb +1 -1
  50. data/spec/files/transaction_migrations/001_create_alt_basic.rb +3 -0
  51. data/spec/files/transaction_migrations/002_create_basic.rb +3 -0
  52. data/spec/files/transactionless_migrations/001_create_alt_basic.rb +4 -0
  53. data/spec/files/transactionless_migrations/002_create_basic.rb +4 -0
  54. data/spec/integration/dataset_test.rb +2 -2
  55. data/spec/integration/plugin_test.rb +9 -9
  56. data/spec/integration/schema_test.rb +3 -1
  57. data/spec/integration/transaction_test.rb +2 -2
  58. metadata +12 -2
@@ -0,0 +1,90 @@
1
+ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
+
3
+ shared_examples_for "Database#with_server" do
4
+ specify "should set the default server to use in the block" do
5
+ @db.with_server(:a){@db[:t].all}
6
+ @db.sqls.should == ["SELECT * FROM t -- a"]
7
+ @db.with_server(:b){@db[:t].all}
8
+ @db.sqls.should == ["SELECT * FROM t -- b"]
9
+ end
10
+
11
+ specify "should have no affect after the block" do
12
+ @db.with_server(:a){@db[:t].all}
13
+ @db.sqls.should == ["SELECT * FROM t -- a"]
14
+ @db[:t].all
15
+ @db.sqls.should == ["SELECT * FROM t"]
16
+ end
17
+
18
+ specify "should not override specific server inside the block" do
19
+ @db.with_server(:a){@db[:t].server(:b).all}
20
+ @db.sqls.should == ["SELECT * FROM t -- b"]
21
+ end
22
+
23
+ specify "should work correctly when blocks are nested" do
24
+ @db[:t].all
25
+ @db.with_server(:a) do
26
+ @db[:t].all
27
+ @db.with_server(:b){@db[:t].all}
28
+ @db[:t].all
29
+ end
30
+ @db[:t].all
31
+ @db.sqls.should == ["SELECT * FROM t", "SELECT * FROM t -- a", "SELECT * FROM t -- b", "SELECT * FROM t -- a", "SELECT * FROM t"]
32
+ end
33
+
34
+ specify "should work correctly for inserts/updates/deletes" do
35
+ @db.with_server(:a) do
36
+ @db[:t].insert
37
+ @db[:t].update(:a=>1)
38
+ @db[:t].delete
39
+ end
40
+ @db.sqls.should == ["INSERT INTO t DEFAULT VALUES -- a", "UPDATE t SET a = 1 -- a", "DELETE FROM t -- a"]
41
+ end
42
+ end
43
+
44
+ describe "Database#with_server single threaded" do
45
+ before do
46
+ @db = Sequel.mock(:single_threaded=>true, :servers=>{:a=>{}, :b=>{}})
47
+ @db.extend Sequel::ServerBlock
48
+ end
49
+
50
+ it_should_behave_like "Database#with_server"
51
+ end
52
+
53
+ describe "Database#with_server multi threaded" do
54
+ before do
55
+ @db = Sequel.mock(:servers=>{:a=>{}, :b=>{}, :c=>{}, :d=>{}})
56
+ @db.extend Sequel::ServerBlock
57
+ end
58
+
59
+ it_should_behave_like "Database#with_server"
60
+
61
+ specify "should respect multithreaded access" do
62
+ q, q1 = Queue.new, Queue.new
63
+
64
+ t = nil
65
+ @db[:t].all
66
+ @db.with_server(:a) do
67
+ @db[:t].all
68
+ t = Thread.new do
69
+ @db[:t].all
70
+ @db.with_server(:c) do
71
+ @db[:t].all
72
+ @db.with_server(:d){@db[:t].all}
73
+ q.push nil
74
+ q1.pop
75
+ @db[:t].all
76
+ end
77
+ @db[:t].all
78
+ end
79
+ q.pop
80
+ @db.with_server(:b){@db[:t].all}
81
+ @db[:t].all
82
+ end
83
+ @db[:t].all
84
+ q1.push nil
85
+ t.join
86
+ @db.sqls.should == ["SELECT * FROM t", "SELECT * FROM t -- a", "SELECT * FROM t", "SELECT * FROM t -- c", "SELECT * FROM t -- d",
87
+ "SELECT * FROM t -- b", "SELECT * FROM t -- a", "SELECT * FROM t", "SELECT * FROM t -- c", "SELECT * FROM t"]
88
+ end
89
+ end
90
+
@@ -8,7 +8,7 @@ unless Sequel.const_defined?('Model')
8
8
  require 'sequel/model'
9
9
  end
10
10
 
11
- Sequel.extension(*%w'string_date_time inflector pagination query pretty_table blank migration schema_dumper looser_typecasting sql_expr thread_local_timezones to_dot columns_introspection')
11
+ Sequel.extension(*%w'string_date_time inflector pagination query pretty_table blank migration schema_dumper looser_typecasting sql_expr thread_local_timezones to_dot columns_introspection server_block arbitrary_servers')
12
12
  {:hook_class_methods=>[], :schema=>[], :validation_class_methods=>[]}.each{|p, opts| Sequel::Model.plugin(p, *opts)}
13
13
 
14
14
  Sequel::Dataset.introspect_all_columns if ENV['SEQUEL_COLUMNS_INTROSPECTION']
@@ -0,0 +1,3 @@
1
+ Sequel.migration do
2
+ change{create_table(:sm11111){Integer :smc1}}
3
+ end
@@ -0,0 +1,3 @@
1
+ Sequel.migration do
2
+ change{create_table(:sm){Integer :smc1}}
3
+ end
@@ -0,0 +1,4 @@
1
+ Sequel.migration do
2
+ no_transaction
3
+ change{create_table(:sm11111){Integer :smc1}}
4
+ end
@@ -0,0 +1,4 @@
1
+ Sequel.migration do
2
+ no_transaction
3
+ change{create_table(:sm){Integer :smc1}}
4
+ end
@@ -81,7 +81,7 @@ describe "Simple Dataset operations" do
81
81
  @ds.all.should == [{:id=>1, :number=>11}]
82
82
  end
83
83
 
84
- cspecify "should have update return the number of matched rows", [:mysql, :mysql], [:do, :mysql], [:mysql2], [:ado] do
84
+ cspecify "should have update return the number of matched rows", [:do, :mysql], [:ado] do
85
85
  @ds.update(:number=>:number).should == 1
86
86
  @ds.filter(:id=>1).update(:number=>:number).should == 1
87
87
  @ds.filter(:id=>2).update(:number=>:number).should == 0
@@ -1357,7 +1357,7 @@ describe "Dataset identifier methods" do
1357
1357
  @db.drop_table(:a)
1358
1358
  end
1359
1359
 
1360
- cspecify "#identifier_output_method should change how identifiers are output", [:mysql2], [:swift] do
1360
+ cspecify "#identifier_output_method should change how identifiers are output", [:swift] do
1361
1361
  @ds.identifier_output_method = :upcase
1362
1362
  @ds.first.should == {:AB=>1}
1363
1363
  @ds.identifier_output_method = :uprev
@@ -1179,9 +1179,9 @@ describe "List plugin without a scope" do
1179
1179
  end
1180
1180
  before do
1181
1181
  @c.delete
1182
- @c.create :name => "hig", :position => 3
1183
- @c.create :name => "def", :position => 2
1184
- @c.create :name => "abc", :position => 1
1182
+ @c.create :name => "abc"
1183
+ @c.create :name => "def"
1184
+ @c.create :name => "hig"
1185
1185
  end
1186
1186
  after(:all) do
1187
1187
  @db.drop_table(:sites)
@@ -1254,12 +1254,12 @@ describe "List plugin with a scope" do
1254
1254
  end
1255
1255
  before do
1256
1256
  @c.delete
1257
- p1 = @c.create :name => "Hm", :pos => 1, :parent_id => 0
1258
- p2 = @c.create :name => "Ps", :pos => 1, :parent_id => p1.id
1259
- @c.create :name => "P1", :pos => 1, :parent_id => p2.id
1260
- @c.create :name => "P2", :pos => 2, :parent_id => p2.id
1261
- @c.create :name => "P3", :pos => 3, :parent_id => p2.id
1262
- @c.create :name => "Au", :pos => 2, :parent_id => p1.id
1257
+ p1 = @c.create :name => "Hm", :parent_id => 0
1258
+ p2 = @c.create :name => "Ps", :parent_id => p1.id
1259
+ @c.create :name => "P1", :parent_id => p2.id
1260
+ @c.create :name => "P2", :parent_id => p2.id
1261
+ @c.create :name => "P3", :parent_id => p2.id
1262
+ @c.create :name => "Au", :parent_id => p1.id
1263
1263
  end
1264
1264
  after(:all) do
1265
1265
  @db.drop_table(:pages)
@@ -441,7 +441,9 @@ describe "Database schema modifiers" do
441
441
  end
442
442
 
443
443
  cspecify "should remove columns from tables correctly", :h2, :mssql, [:jdbc, :db2], :hsqldb do
444
- @db.create_table!(:items) do
444
+ # MySQL with InnoDB cannot drop foreign key columns unless you know the
445
+ # name of the constraint, see Bug #14347
446
+ @db.create_table!(:items, :engine=>:MyISAM) do
445
447
  primary_key :id
446
448
  String :name
447
449
  Integer :number
@@ -156,7 +156,7 @@ describe "Database transactions" do
156
156
  @d.select_order_map(:name).should == []
157
157
  end
158
158
 
159
- if INTEGRATION_DB.supports_savepoints?
159
+ if INTEGRATION_DB.supports_savepoints_in_prepared_transactions?
160
160
  specify "should support savepoints when using prepared transactions" do
161
161
  @db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@d << {:name => '1'}}}
162
162
  @db.commit_prepared_transaction('XYZ')
@@ -252,7 +252,7 @@ describe "Database transactions" do
252
252
  proc{@db.transaction(:prepare=>'XYZ'){@db.after_rollback{}}}.should raise_error(Sequel::Error)
253
253
  end
254
254
 
255
- if INTEGRATION_DB.supports_savepoints?
255
+ if INTEGRATION_DB.supports_savepoints_in_prepared_transactions?
256
256
  specify "should raise an error if you attempt to use after_commit or after rollback inside a savepoint in a prepared transaction" do
257
257
  proc{@db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@db.after_commit{}}}}.should raise_error(Sequel::Error)
258
258
  proc{@db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@db.after_rollback{}}}}.should raise_error(Sequel::Error)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.32.0
4
+ version: 3.33.0
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: 2012-02-01 00:00:00.000000000 Z
12
+ date: 2012-03-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: The Database Toolkit for Ruby
15
15
  email: code@jeremyevans.net
@@ -91,6 +91,7 @@ extra_rdoc_files:
91
91
  - doc/release_notes/3.30.0.txt
92
92
  - doc/release_notes/3.31.0.txt
93
93
  - doc/release_notes/3.32.0.txt
94
+ - doc/release_notes/3.33.0.txt
94
95
  files:
95
96
  - MIT-LICENSE
96
97
  - CHANGELOG
@@ -160,6 +161,7 @@ files:
160
161
  - doc/release_notes/3.30.0.txt
161
162
  - doc/release_notes/3.31.0.txt
162
163
  - doc/release_notes/3.32.0.txt
164
+ - doc/release_notes/3.33.0.txt
163
165
  - doc/sharding.rdoc
164
166
  - doc/sql.rdoc
165
167
  - doc/validations.rdoc
@@ -246,6 +248,8 @@ files:
246
248
  - spec/extensions/prepared_statements_with_pk_spec.rb
247
249
  - spec/extensions/prepared_statements_associations_spec.rb
248
250
  - spec/extensions/dataset_associations_spec.rb
251
+ - spec/extensions/arbitrary_servers_spec.rb
252
+ - spec/extensions/server_block_spec.rb
249
253
  - spec/extensions/columns_introspection_spec.rb
250
254
  - spec/integration/associations_test.rb
251
255
  - spec/integration/database_test.rb
@@ -315,6 +319,10 @@ files:
315
319
  - spec/files/reversible_migrations/003_reversible.rb
316
320
  - spec/files/reversible_migrations/004_reversible.rb
317
321
  - spec/files/reversible_migrations/005_reversible.rb
322
+ - spec/files/transaction_migrations/001_create_alt_basic.rb
323
+ - spec/files/transaction_migrations/002_create_basic.rb
324
+ - spec/files/transactionless_migrations/001_create_alt_basic.rb
325
+ - spec/files/transactionless_migrations/002_create_basic.rb
318
326
  - lib/sequel.rb
319
327
  - lib/sequel/adapters/ado.rb
320
328
  - lib/sequel/adapters/ado/mssql.rb
@@ -411,6 +419,8 @@ files:
411
419
  - lib/sequel/extensions/string_date_time.rb
412
420
  - lib/sequel/extensions/thread_local_timezones.rb
413
421
  - lib/sequel/extensions/to_dot.rb
422
+ - lib/sequel/extensions/arbitrary_servers.rb
423
+ - lib/sequel/extensions/server_block.rb
414
424
  - lib/sequel/extensions/columns_introspection.rb
415
425
  - lib/sequel/metaprogramming.rb
416
426
  - lib/sequel/model.rb