activerecord-oracle_enhanced-adapter 8.1.3 → 8.1.4
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +1 -1
- data/lib/arel/visitors/oracle_common.rb +29 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +22 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +77 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f69a5874a83fcb0afd6b60ae09f61e0a300201cf3a99b6aee5523dcd92a985b
|
|
4
|
+
data.tar.gz: 8eee0fdb3853c42f27d37b37726ea9c4d685cadc047d00971291b0efe36503bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8f684da4497ca2b4534744100d2c1468a7871420b127d4996816057e90d62213e5f456816c1e294920609f6f01122c778c0ff76b7479e3fa52b8f19c4694728
|
|
7
|
+
data.tar.gz: a2d729ffbcf21518d3b5a291e913c79104308d191e2ee6a54ac60b18418f4c8732e3069da2ecd5302cc6dd9f10e43d35c043fbeba204d99cb0b6e3b527cc0479
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
8.1.
|
|
1
|
+
8.1.4
|
|
@@ -259,7 +259,7 @@ module ActiveRecord
|
|
|
259
259
|
schema_cache.clear_data_source_cache!(table_name.to_s)
|
|
260
260
|
schema_cache.clear_data_source_cache!(new_name.to_s)
|
|
261
261
|
execute "RENAME #{quote_table_name(table_name)} TO #{quote_table_name(new_name)}"
|
|
262
|
-
execute "RENAME #{
|
|
262
|
+
execute "RENAME #{default_sequence_name(table_name)} TO #{default_sequence_name(new_name)}" rescue nil
|
|
263
263
|
|
|
264
264
|
rename_table_indexes(table_name, new_name, **options)
|
|
265
265
|
end
|
|
@@ -46,6 +46,35 @@ module Arel # :nodoc: all
|
|
|
46
46
|
def schema_cache
|
|
47
47
|
@connection.schema_cache
|
|
48
48
|
end
|
|
49
|
+
|
|
50
|
+
def visit_Arel_Nodes_In(o, collector)
|
|
51
|
+
attr, values = o.left, o.right
|
|
52
|
+
return super unless values.is_a?(Array)
|
|
53
|
+
|
|
54
|
+
in_clause_length = @connection.in_clause_length
|
|
55
|
+
return super if values.length <= in_clause_length
|
|
56
|
+
|
|
57
|
+
# Split into multiple IN nodes and combine with OR
|
|
58
|
+
in_nodes = values.each_slice(in_clause_length).map do |slice|
|
|
59
|
+
Arel::Nodes::In.new(attr, slice)
|
|
60
|
+
end
|
|
61
|
+
or_node = Arel::Nodes::Or.new(in_nodes)
|
|
62
|
+
visit(Arel::Nodes::Grouping.new(or_node), collector)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def visit_Arel_Nodes_NotIn(o, collector)
|
|
66
|
+
attr, values = o.left, o.right
|
|
67
|
+
return super unless values.is_a?(Array)
|
|
68
|
+
|
|
69
|
+
in_clause_length = @connection.in_clause_length
|
|
70
|
+
return super if values.length <= in_clause_length
|
|
71
|
+
|
|
72
|
+
# Split into multiple NOT IN nodes and combine with AND
|
|
73
|
+
not_in_nodes = values.each_slice(in_clause_length).map do |slice|
|
|
74
|
+
Arel::Nodes::NotIn.new(attr, slice)
|
|
75
|
+
end
|
|
76
|
+
visit(Arel::Nodes::And.new(not_in_nodes), collector)
|
|
77
|
+
end
|
|
49
78
|
end
|
|
50
79
|
end
|
|
51
80
|
end
|
|
@@ -296,6 +296,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
|
296
296
|
end
|
|
297
297
|
|
|
298
298
|
after(:each) do
|
|
299
|
+
long_name = ("a" * (@conn.sequence_name_length - 3)).to_sym
|
|
299
300
|
schema_define do
|
|
300
301
|
drop_table :test_employees_no_primary_key, if_exists: true
|
|
301
302
|
drop_table :test_employees, if_exists: true
|
|
@@ -303,6 +304,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
|
303
304
|
drop_table :test_employees_no_pkey, if_exists: true
|
|
304
305
|
drop_table :new_test_employees_no_pkey, if_exists: true
|
|
305
306
|
drop_table :aaaaaaaaaaaaaaaaaaaaaaaaaaa, if_exists: true
|
|
307
|
+
drop_table long_name, if_exists: true
|
|
306
308
|
end
|
|
307
309
|
end
|
|
308
310
|
|
|
@@ -329,6 +331,26 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
|
329
331
|
@conn.rename_table("test_employees_no_pkey", "new_test_employees_no_pkey")
|
|
330
332
|
end.not_to raise_error
|
|
331
333
|
end
|
|
334
|
+
|
|
335
|
+
it "renames the auto-generated sequence when the source table name is long enough to truncate it" do
|
|
336
|
+
long_source = "a" * (@conn.sequence_name_length - 3)
|
|
337
|
+
schema_define do
|
|
338
|
+
create_table long_source.to_sym, force: true do |t|
|
|
339
|
+
t.string :first_name
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
expected_old_seq = @conn.default_sequence_name(long_source).upcase
|
|
344
|
+
expected_new_seq = @conn.default_sequence_name("new_test_employees").upcase
|
|
345
|
+
|
|
346
|
+
@conn.rename_table(long_source, "new_test_employees")
|
|
347
|
+
|
|
348
|
+
sequences = @conn.select_values(
|
|
349
|
+
"SELECT sequence_name FROM user_sequences WHERE sequence_name IN ('#{expected_old_seq}', '#{expected_new_seq}')"
|
|
350
|
+
)
|
|
351
|
+
expect(sequences).to include(expected_new_seq)
|
|
352
|
+
expect(sequences).not_to include(expected_old_seq)
|
|
353
|
+
end
|
|
332
354
|
end
|
|
333
355
|
|
|
334
356
|
describe "add index" do
|
|
@@ -244,7 +244,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
244
244
|
class ::TestPost < ActiveRecord::Base
|
|
245
245
|
has_many :test_comments
|
|
246
246
|
end
|
|
247
|
-
@ids = (1..
|
|
247
|
+
@ids = (1..2010).to_a
|
|
248
248
|
TestPost.transaction do
|
|
249
249
|
@ids.each do |id|
|
|
250
250
|
TestPost.create!(id: id, title: "Title #{id}")
|
|
@@ -272,6 +272,38 @@ describe "OracleEnhancedAdapter" do
|
|
|
272
272
|
posts = TestPost.where(id: [*@ids, nil]).to_a
|
|
273
273
|
expect(posts.size).to eq(@ids.size)
|
|
274
274
|
end
|
|
275
|
+
|
|
276
|
+
# some frameworks like baby_squeel construct Arel objects directly
|
|
277
|
+
it "should allow more than 1000 items using Arel::Nodes::In" do
|
|
278
|
+
table = TestPost.arel_table
|
|
279
|
+
in_node = Arel::Nodes::In.new(table[:id], @ids)
|
|
280
|
+
query = table.where(in_node).project(Arel.star)
|
|
281
|
+
|
|
282
|
+
sql = query.to_sql
|
|
283
|
+
posts = TestPost.connection.select_all(sql).to_a
|
|
284
|
+
expect(posts.size).to eq(@ids.size)
|
|
285
|
+
|
|
286
|
+
# SQL contains multiple IN clauses (split due to 1000 limit)
|
|
287
|
+
expect(sql.scan(/IN \(/).size).to be > 1
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
it "should allow more than 1000 items using Arel::Nodes::NotIn" do
|
|
291
|
+
ids = @ids.dup
|
|
292
|
+
non_not_in = ids.pop
|
|
293
|
+
|
|
294
|
+
table = TestPost.arel_table
|
|
295
|
+
not_in_node = Arel::Nodes::NotIn.new(table[:id], ids)
|
|
296
|
+
query = table.where(not_in_node).project(Arel.star)
|
|
297
|
+
|
|
298
|
+
sql = query.to_sql
|
|
299
|
+
posts = TestPost.connection.select_all(sql).to_a
|
|
300
|
+
|
|
301
|
+
expect(posts.size).to eq(1)
|
|
302
|
+
expect(posts.first["id"]).to eq(non_not_in)
|
|
303
|
+
|
|
304
|
+
# SQL contains multiple NOT IN clauses (split due to 1000 limit)
|
|
305
|
+
expect(sql.scan(/NOT IN \(/).size).to be > 1
|
|
306
|
+
end
|
|
275
307
|
end
|
|
276
308
|
|
|
277
309
|
describe "with statement pool" do
|
|
@@ -806,10 +838,54 @@ describe "OracleEnhancedAdapter" do
|
|
|
806
838
|
ActiveRecord::Base.clear_cache!
|
|
807
839
|
end
|
|
808
840
|
|
|
841
|
+
before(:each) do
|
|
842
|
+
TestPost.delete_all
|
|
843
|
+
TestComment.delete_all
|
|
844
|
+
end
|
|
845
|
+
|
|
809
846
|
it "should not raise undefined method length" do
|
|
810
847
|
post = TestPost.create!
|
|
811
848
|
post.test_comments << TestComment.create!
|
|
812
849
|
expect(TestComment.where(test_post_id: TestPost.select(:id)).size).to eq(1)
|
|
813
850
|
end
|
|
851
|
+
|
|
852
|
+
it "should handle IN with subquery using Arel::Nodes::In" do
|
|
853
|
+
post = TestPost.create!
|
|
854
|
+
post.test_comments << TestComment.create!
|
|
855
|
+
|
|
856
|
+
table = TestComment.arel_table
|
|
857
|
+
subquery = TestPost.select(:id).arel
|
|
858
|
+
in_node = Arel::Nodes::In.new(table[:test_post_id], subquery)
|
|
859
|
+
query = table.where(in_node).project(Arel.star)
|
|
860
|
+
|
|
861
|
+
sql = query.to_sql
|
|
862
|
+
comments = TestComment.connection.select_all(sql).to_a
|
|
863
|
+
expect(comments.size).to eq(1)
|
|
864
|
+
|
|
865
|
+
# SQL should contain IN with subquery, not split into multiple IN clauses
|
|
866
|
+
expect(sql).to match(/IN \(+SELECT/)
|
|
867
|
+
expect(sql.scan(/IN \(/).size).to eq(1)
|
|
868
|
+
end
|
|
869
|
+
|
|
870
|
+
it "should handle NOT IN with subquery using Arel::Nodes::NotIn" do
|
|
871
|
+
post = TestPost.create!
|
|
872
|
+
TestComment.create!(test_post_id: post.id)
|
|
873
|
+
orphan_comment = TestComment.create!(test_post_id: post.id + 1)
|
|
874
|
+
|
|
875
|
+
table = TestComment.arel_table
|
|
876
|
+
subquery = TestPost.select(:id).arel
|
|
877
|
+
not_in_node = Arel::Nodes::NotIn.new(table[:test_post_id], subquery)
|
|
878
|
+
query = table.where(not_in_node).project(Arel.star)
|
|
879
|
+
|
|
880
|
+
sql = query.to_sql
|
|
881
|
+
comments = TestComment.connection.select_all(sql).to_a
|
|
882
|
+
|
|
883
|
+
expect(comments.size).to eq(1)
|
|
884
|
+
expect(comments.first["id"]).to eq(orphan_comment.id)
|
|
885
|
+
|
|
886
|
+
# SQL should contain NOT IN with subquery, not split into multiple NOT IN clauses
|
|
887
|
+
expect(sql).to match(/NOT IN \(+SELECT/)
|
|
888
|
+
expect(sql.scan(/NOT IN \(/).size).to eq(1)
|
|
889
|
+
end
|
|
814
890
|
end
|
|
815
891
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-oracle_enhanced-adapter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 8.1.
|
|
4
|
+
version: 8.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Raimonds Simanovskis
|
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
156
156
|
- !ruby/object:Gem::Version
|
|
157
157
|
version: 1.8.11
|
|
158
158
|
requirements: []
|
|
159
|
-
rubygems_version: 4.0.
|
|
159
|
+
rubygems_version: 4.0.11
|
|
160
160
|
specification_version: 4
|
|
161
161
|
summary: Oracle enhanced adapter for ActiveRecord
|
|
162
162
|
test_files:
|