activerecord-oracle_enhanced-adapter 1.4.3 → 5.2.0
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 +5 -5
- data/History.md +1162 -2
- data/README.md +567 -155
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +3 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +19 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +132 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +345 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +52 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +280 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +64 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +59 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +538 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +38 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +46 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +435 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +44 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +196 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +164 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +95 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +79 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +194 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +709 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +28 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +353 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +33 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +3 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +385 -1083
- data/lib/active_record/type/oracle_enhanced/boolean.rb +20 -0
- data/lib/active_record/type/oracle_enhanced/integer.rb +15 -0
- data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
- data/lib/active_record/type/oracle_enhanced/national_character_string.rb +26 -0
- data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
- data/lib/active_record/type/oracle_enhanced/raw.rb +25 -0
- data/lib/active_record/type/oracle_enhanced/string.rb +29 -0
- data/lib/active_record/type/oracle_enhanced/text.rb +32 -0
- data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
- data/lib/active_record/type/oracle_enhanced/timestamptz.rb +25 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +5 -13
- data/spec/active_record/connection_adapters/{oracle_enhanced_emulate_oracle_adapter_spec.rb → emulation/oracle_adapter_spec.rb} +5 -4
- data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +469 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_context_index_spec.rb → oracle_enhanced/context_index_spec.rb} +140 -128
- data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +112 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_dbms_output_spec.rb → oracle_enhanced/dbms_output_spec.rb} +13 -13
- data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +365 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +196 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +492 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +1433 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +478 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +385 -550
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +92 -1249
- data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
- data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +208 -0
- data/spec/active_record/oracle_enhanced/type/dirty_spec.rb +139 -0
- data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
- data/spec/active_record/oracle_enhanced/type/integer_spec.rb +91 -0
- data/spec/active_record/oracle_enhanced/type/json_spec.rb +57 -0
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +55 -0
- data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
- data/spec/active_record/oracle_enhanced/type/raw_spec.rb +122 -0
- data/spec/active_record/oracle_enhanced/type/text_spec.rb +229 -0
- data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +75 -0
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +100 -93
- data/spec/support/alter_system_set_open_cursors.sql +1 -0
- data/spec/support/alter_system_user_password.sql +2 -0
- data/spec/support/create_oracle_enhanced_users.sql +31 -0
- metadata +105 -152
- data/.rspec +0 -2
- data/Gemfile +0 -52
- data/RUNNING_TESTS.md +0 -45
- data/Rakefile +0 -59
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -130
- data/lib/active_record/connection_adapters/oracle_enhanced.rake +0 -105
- data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +0 -41
- data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +0 -121
- data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +0 -151
- data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +0 -119
- data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -359
- data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +0 -25
- data/lib/active_record/connection_adapters/oracle_enhanced_cpk.rb +0 -21
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -46
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +0 -572
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +0 -497
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +0 -260
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -227
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +0 -260
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -428
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
- data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +0 -294
- data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +0 -17
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +0 -334
- data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +0 -19
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +0 -141
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +0 -378
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +0 -440
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +0 -1400
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +0 -339
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
#
|
|
2
|
-
require 'spec_helper'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
3
|
describe "OracleEnhancedAdapter context index" do
|
|
5
4
|
include SchemaSpecHelper
|
|
6
5
|
include LoggerSpecHelper
|
|
6
|
+
include SchemaDumpingHelper
|
|
7
7
|
|
|
8
8
|
def create_table_posts
|
|
9
9
|
schema_define do
|
|
10
|
-
create_table :posts, :
|
|
10
|
+
create_table :posts, force: true do |t|
|
|
11
11
|
t.string :title
|
|
12
12
|
t.text :body
|
|
13
13
|
t.integer :comments_count
|
|
14
|
-
t.timestamps
|
|
15
|
-
t.string :all_text, :
|
|
14
|
+
t.timestamps null: true
|
|
15
|
+
t.string :all_text, limit: 2 # will be used for multi-column index
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def create_table_comments
|
|
21
21
|
schema_define do
|
|
22
|
-
create_table :comments, :
|
|
22
|
+
create_table :comments, force: true do |t|
|
|
23
23
|
t.integer :post_id
|
|
24
24
|
t.string :author
|
|
25
25
|
t.text :body
|
|
26
|
-
t.timestamps
|
|
26
|
+
t.timestamps null: true
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -68,17 +68,21 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
68
68
|
class ::Post < ActiveRecord::Base
|
|
69
69
|
has_context_index
|
|
70
70
|
end
|
|
71
|
-
@post0 = Post.create(:
|
|
72
|
-
@post1 = Post.create(:
|
|
73
|
-
@post2 = Post.create(:
|
|
74
|
-
@post_with_null_body = Post.create(:
|
|
75
|
-
@post_with_null_title = Post.create(:
|
|
71
|
+
@post0 = Post.create(title: "dummy title", body: "dummy body")
|
|
72
|
+
@post1 = Post.create(title: @title_words.join(" "), body: @body_words.join(" "))
|
|
73
|
+
@post2 = Post.create(title: (@title_words * 2).join(" "), body: (@body_words * 2).join(" "))
|
|
74
|
+
@post_with_null_body = Post.create(title: "withnull", body: nil)
|
|
75
|
+
@post_with_null_title = Post.create(title: nil, body: "withnull")
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
after(:all) do
|
|
79
79
|
drop_table_posts
|
|
80
80
|
Object.send(:remove_const, "Post")
|
|
81
|
-
ActiveRecord::Base.clear_cache!
|
|
81
|
+
ActiveRecord::Base.clear_cache!
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
before(:each) do
|
|
85
|
+
@post = nil
|
|
82
86
|
end
|
|
83
87
|
|
|
84
88
|
after(:each) do
|
|
@@ -88,7 +92,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
88
92
|
it "should create single VARCHAR2 column index" do
|
|
89
93
|
@conn.add_context_index :posts, :title
|
|
90
94
|
@title_words.each do |word|
|
|
91
|
-
Post.contains(:title, word).
|
|
95
|
+
expect(Post.contains(:title, word).to_a).to eq([@post2, @post1])
|
|
92
96
|
end
|
|
93
97
|
@conn.remove_context_index :posts, :title
|
|
94
98
|
end
|
|
@@ -96,76 +100,84 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
96
100
|
it "should create single CLOB column index" do
|
|
97
101
|
@conn.add_context_index :posts, :body
|
|
98
102
|
@body_words.each do |word|
|
|
99
|
-
Post.contains(:body, word).
|
|
103
|
+
expect(Post.contains(:body, word).to_a).to eq([@post2, @post1])
|
|
100
104
|
end
|
|
101
105
|
@conn.remove_context_index :posts, :body
|
|
102
106
|
end
|
|
103
107
|
|
|
104
108
|
it "should not include text index secondary tables in user tables list" do
|
|
105
109
|
@conn.add_context_index :posts, :title
|
|
106
|
-
@conn.tables.any?{|t| t =~ /^dr\$/i}.
|
|
110
|
+
expect(@conn.tables.any? { |t| t =~ /^dr\$/i }).to be_falsey
|
|
107
111
|
@conn.remove_context_index :posts, :title
|
|
108
112
|
end
|
|
109
113
|
|
|
110
114
|
it "should create multiple column index" do
|
|
111
115
|
@conn.add_context_index :posts, [:title, :body]
|
|
112
|
-
(@title_words
|
|
113
|
-
Post.contains(:title, word).
|
|
116
|
+
(@title_words + @body_words).each do |word|
|
|
117
|
+
expect(Post.contains(:title, word).to_a).to eq([@post2, @post1])
|
|
114
118
|
end
|
|
115
119
|
@conn.remove_context_index :posts, [:title, :body]
|
|
116
120
|
end
|
|
117
121
|
|
|
118
122
|
it "should index records with null values" do
|
|
119
123
|
@conn.add_context_index :posts, [:title, :body]
|
|
120
|
-
Post.contains(:title, "withnull").
|
|
124
|
+
expect(Post.contains(:title, "withnull").to_a).to eq([@post_with_null_body, @post_with_null_title])
|
|
121
125
|
@conn.remove_context_index :posts, [:title, :body]
|
|
122
126
|
end
|
|
123
127
|
|
|
124
128
|
it "should create multiple column index with specified main index column" do
|
|
125
129
|
@conn.add_context_index :posts, [:title, :body],
|
|
126
|
-
:
|
|
127
|
-
@post = Post.create(:
|
|
128
|
-
Post.contains(:all_text, "abc").
|
|
129
|
-
Post.contains(:all_text, "def").
|
|
130
|
-
@post.update_attributes!(:
|
|
130
|
+
index_column: :all_text, sync: "ON COMMIT"
|
|
131
|
+
@post = Post.create(title: "abc", body: "def")
|
|
132
|
+
expect(Post.contains(:all_text, "abc").to_a).to eq([@post])
|
|
133
|
+
expect(Post.contains(:all_text, "def").to_a).to eq([@post])
|
|
134
|
+
@post.update_attributes!(title: "ghi")
|
|
131
135
|
# index will not be updated as all_text column is not changed
|
|
132
|
-
Post.contains(:all_text, "ghi").
|
|
133
|
-
@post.update_attributes!(:
|
|
136
|
+
expect(Post.contains(:all_text, "ghi").to_a).to be_empty
|
|
137
|
+
@post.update_attributes!(all_text: "1")
|
|
134
138
|
# index will be updated when all_text column is changed
|
|
135
|
-
Post.contains(:all_text, "ghi").
|
|
136
|
-
@conn.remove_context_index :posts, :
|
|
139
|
+
expect(Post.contains(:all_text, "ghi").to_a).to eq([@post])
|
|
140
|
+
@conn.remove_context_index :posts, index_column: :all_text
|
|
137
141
|
end
|
|
138
142
|
|
|
139
143
|
it "should create multiple column index with trigger updated main index column" do
|
|
140
144
|
@conn.add_context_index :posts, [:title, :body],
|
|
141
|
-
:
|
|
142
|
-
:
|
|
143
|
-
@post = Post.create(:
|
|
144
|
-
Post.contains(:all_text, "abc").
|
|
145
|
-
Post.contains(:all_text, "def").
|
|
146
|
-
@post.update_attributes!(:
|
|
145
|
+
index_column: :all_text, index_column_trigger_on: [:created_at, :updated_at],
|
|
146
|
+
sync: "ON COMMIT"
|
|
147
|
+
@post = Post.create(title: "abc", body: "def")
|
|
148
|
+
expect(Post.contains(:all_text, "abc").to_a).to eq([@post])
|
|
149
|
+
expect(Post.contains(:all_text, "def").to_a).to eq([@post])
|
|
150
|
+
@post.update_attributes!(title: "ghi")
|
|
147
151
|
# index should be updated as created_at column is changed
|
|
148
|
-
Post.contains(:all_text, "ghi").
|
|
149
|
-
@conn.remove_context_index :posts, :
|
|
152
|
+
expect(Post.contains(:all_text, "ghi").to_a).to eq([@post])
|
|
153
|
+
@conn.remove_context_index :posts, index_column: :all_text
|
|
150
154
|
end
|
|
151
155
|
|
|
152
156
|
it "should use base letter conversion with BASIC_LEXER" do
|
|
153
|
-
@post = Post.create!(:
|
|
157
|
+
@post = Post.create!(title: "āčē", body: "dummy")
|
|
154
158
|
@conn.add_context_index :posts, :title,
|
|
155
|
-
:
|
|
156
|
-
Post.contains(:title, "āčē").
|
|
157
|
-
Post.contains(:title, "ace").
|
|
158
|
-
Post.contains(:title, "ACE").
|
|
159
|
+
lexer: { type: "BASIC_LEXER", base_letter_type: "GENERIC", base_letter: true }
|
|
160
|
+
expect(Post.contains(:title, "āčē").to_a).to eq([@post])
|
|
161
|
+
expect(Post.contains(:title, "ace").to_a).to eq([@post])
|
|
162
|
+
expect(Post.contains(:title, "ACE").to_a).to eq([@post])
|
|
159
163
|
@conn.remove_context_index :posts, :title
|
|
160
164
|
end
|
|
161
165
|
|
|
162
166
|
it "should create transactional index and sync index within transaction on inserts and updates" do
|
|
163
|
-
@conn.add_context_index :posts, :title, :
|
|
167
|
+
@conn.add_context_index :posts, :title, transactional: true
|
|
164
168
|
Post.transaction do
|
|
165
|
-
@post = Post.create(:
|
|
166
|
-
Post.contains(:title, "abc").
|
|
167
|
-
@post.update_attributes!(:
|
|
168
|
-
Post.contains(:title, "ghi").
|
|
169
|
+
@post = Post.create(title: "abc")
|
|
170
|
+
expect(Post.contains(:title, "abc").to_a).to eq([@post])
|
|
171
|
+
@post.update_attributes!(title: "ghi")
|
|
172
|
+
expect(Post.contains(:title, "ghi").to_a).to eq([@post])
|
|
173
|
+
end
|
|
174
|
+
@conn.remove_context_index :posts, :title
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "should use index when contains has schema_name.table_name syntax" do
|
|
178
|
+
@conn.add_context_index :posts, :title
|
|
179
|
+
@title_words.each do |word|
|
|
180
|
+
expect(Post.contains("posts.title", word).to_a).to eq([@post2, @post1])
|
|
169
181
|
end
|
|
170
182
|
@conn.remove_context_index :posts, :title
|
|
171
183
|
end
|
|
@@ -176,11 +188,11 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
176
188
|
@conn = ActiveRecord::Base.connection
|
|
177
189
|
create_tables
|
|
178
190
|
class ::Post < ActiveRecord::Base
|
|
179
|
-
has_many :comments, :
|
|
191
|
+
has_many :comments, dependent: :destroy
|
|
180
192
|
has_context_index
|
|
181
193
|
end
|
|
182
194
|
class ::Comment < ActiveRecord::Base
|
|
183
|
-
belongs_to :post, :
|
|
195
|
+
belongs_to :post, counter_cache: true
|
|
184
196
|
end
|
|
185
197
|
end
|
|
186
198
|
|
|
@@ -188,10 +200,12 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
188
200
|
drop_tables
|
|
189
201
|
Object.send(:remove_const, "Comment")
|
|
190
202
|
Object.send(:remove_const, "Post")
|
|
191
|
-
ActiveRecord::Base.clear_cache!
|
|
203
|
+
ActiveRecord::Base.clear_cache!
|
|
192
204
|
end
|
|
193
205
|
|
|
194
206
|
after(:each) do
|
|
207
|
+
@conn.remove_context_index :posts, name: "post_and_comments_index" rescue nil
|
|
208
|
+
@conn.remove_context_index :posts, index_column: :all_text rescue nil
|
|
195
209
|
Post.destroy_all
|
|
196
210
|
end
|
|
197
211
|
|
|
@@ -201,16 +215,15 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
201
215
|
# specify aliases always with AS keyword
|
|
202
216
|
"SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
|
203
217
|
],
|
|
204
|
-
:
|
|
205
|
-
:
|
|
206
|
-
:
|
|
207
|
-
@post = Post.create!(:
|
|
208
|
-
@post.comments.create!(:
|
|
209
|
-
@post.comments.create!(:
|
|
218
|
+
name: "post_and_comments_index",
|
|
219
|
+
index_column: :all_text, index_column_trigger_on: [:updated_at, :comments_count],
|
|
220
|
+
sync: "ON COMMIT"
|
|
221
|
+
@post = Post.create!(title: "aaa", body: "bbb")
|
|
222
|
+
@post.comments.create!(author: "ccc", body: "ddd")
|
|
223
|
+
@post.comments.create!(author: "eee", body: "fff")
|
|
210
224
|
["aaa", "bbb", "ccc", "ddd", "eee", "fff"].each do |word|
|
|
211
|
-
Post.contains(:all_text, word).
|
|
225
|
+
expect(Post.contains(:all_text, word).to_a).to eq([@post])
|
|
212
226
|
end
|
|
213
|
-
@conn.remove_context_index :posts, :name => 'post_and_comments_index'
|
|
214
227
|
end
|
|
215
228
|
|
|
216
229
|
it "should create multiple table index with specified main index column (when subquery has newlines)" do
|
|
@@ -223,36 +236,34 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
223
236
|
FROM comments
|
|
224
237
|
WHERE comments.post_id = :id }
|
|
225
238
|
],
|
|
226
|
-
:
|
|
227
|
-
:
|
|
228
|
-
:
|
|
229
|
-
@post = Post.create!(:
|
|
230
|
-
@post.comments.create!(:
|
|
231
|
-
@post.comments.create!(:
|
|
239
|
+
name: "post_and_comments_index",
|
|
240
|
+
index_column: :all_text, index_column_trigger_on: [:updated_at, :comments_count],
|
|
241
|
+
sync: "ON COMMIT"
|
|
242
|
+
@post = Post.create!(title: "aaa", body: "bbb")
|
|
243
|
+
@post.comments.create!(author: "ccc", body: "ddd")
|
|
244
|
+
@post.comments.create!(author: "eee", body: "fff")
|
|
232
245
|
["aaa", "bbb", "ccc", "ddd", "eee", "fff"].each do |word|
|
|
233
|
-
Post.contains(:all_text, word).
|
|
246
|
+
expect(Post.contains(:all_text, word).to_a).to eq([@post])
|
|
234
247
|
end
|
|
235
|
-
@conn.remove_context_index :posts, :name => 'post_and_comments_index'
|
|
236
248
|
end
|
|
237
249
|
|
|
238
250
|
it "should find by search term within specified field" do
|
|
239
|
-
@post = Post.create!(:
|
|
240
|
-
@post.comments.create!(:
|
|
251
|
+
@post = Post.create!(title: "aaa", body: "bbb")
|
|
252
|
+
@post.comments.create!(author: "ccc", body: "ddd")
|
|
241
253
|
@conn.add_context_index :posts,
|
|
242
254
|
[:title, :body,
|
|
243
255
|
# specify aliases always with AS keyword
|
|
244
256
|
"SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
|
245
257
|
],
|
|
246
|
-
:
|
|
247
|
-
Post.contains(:all_text, "aaa within title").
|
|
248
|
-
Post.contains(:all_text, "aaa within body").
|
|
249
|
-
Post.contains(:all_text, "bbb within body").
|
|
250
|
-
Post.contains(:all_text, "bbb within title").
|
|
251
|
-
Post.contains(:all_text, "ccc within comment_author").
|
|
252
|
-
Post.contains(:all_text, "ccc within comment_body").
|
|
253
|
-
Post.contains(:all_text, "ddd within comment_body").
|
|
254
|
-
Post.contains(:all_text, "ddd within comment_author").
|
|
255
|
-
@conn.remove_context_index :posts, :index_column => :all_text
|
|
258
|
+
index_column: :all_text
|
|
259
|
+
expect(Post.contains(:all_text, "aaa within title").to_a).to eq([@post])
|
|
260
|
+
expect(Post.contains(:all_text, "aaa within body").to_a).to be_empty
|
|
261
|
+
expect(Post.contains(:all_text, "bbb within body").to_a).to eq([@post])
|
|
262
|
+
expect(Post.contains(:all_text, "bbb within title").to_a).to be_empty
|
|
263
|
+
expect(Post.contains(:all_text, "ccc within comment_author").to_a).to eq([@post])
|
|
264
|
+
expect(Post.contains(:all_text, "ccc within comment_body").to_a).to be_empty
|
|
265
|
+
expect(Post.contains(:all_text, "ddd within comment_body").to_a).to eq([@post])
|
|
266
|
+
expect(Post.contains(:all_text, "ddd within comment_author").to_a).to be_empty
|
|
256
267
|
end
|
|
257
268
|
|
|
258
269
|
end
|
|
@@ -264,7 +275,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
264
275
|
class ::Post < ActiveRecord::Base
|
|
265
276
|
has_context_index
|
|
266
277
|
end
|
|
267
|
-
@post = Post.create(:
|
|
278
|
+
@post = Post.create(title: "aaa", body: "bbb")
|
|
268
279
|
@tablespace = @conn.default_tablespace
|
|
269
280
|
set_logger
|
|
270
281
|
@conn = ActiveRecord::Base.connection
|
|
@@ -273,7 +284,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
273
284
|
after(:all) do
|
|
274
285
|
drop_table_posts
|
|
275
286
|
Object.send(:remove_const, "Post")
|
|
276
|
-
ActiveRecord::Base.clear_cache!
|
|
287
|
+
ActiveRecord::Base.clear_cache!
|
|
277
288
|
end
|
|
278
289
|
|
|
279
290
|
after(:each) do
|
|
@@ -281,37 +292,30 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
281
292
|
end
|
|
282
293
|
|
|
283
294
|
def verify_logged_statements
|
|
284
|
-
[
|
|
285
|
-
@logger.output(:debug).
|
|
295
|
+
["K_TABLE_CLAUSE", "R_TABLE_CLAUSE", "N_TABLE_CLAUSE", "I_INDEX_CLAUSE", "P_TABLE_CLAUSE"].each do |clause|
|
|
296
|
+
expect(@logger.output(:debug)).to match(/CTX_DDL\.SET_ATTRIBUTE\('index_posts_on_title_sto', '#{clause}', '.*TABLESPACE #{@tablespace}'\)/)
|
|
286
297
|
end
|
|
287
|
-
@logger.output(:debug).
|
|
298
|
+
expect(@logger.output(:debug)).to match(/CREATE INDEX .* PARAMETERS \('STORAGE index_posts_on_title_sto'\)/)
|
|
288
299
|
end
|
|
289
300
|
|
|
290
301
|
it "should create index on single column" do
|
|
291
|
-
@conn.add_context_index :posts, :title, :
|
|
302
|
+
@conn.add_context_index :posts, :title, tablespace: @tablespace
|
|
292
303
|
verify_logged_statements
|
|
293
|
-
Post.contains(:title,
|
|
304
|
+
expect(Post.contains(:title, "aaa").to_a).to eq([@post])
|
|
294
305
|
@conn.remove_context_index :posts, :title
|
|
295
306
|
end
|
|
296
307
|
|
|
297
308
|
it "should create index on multiple columns" do
|
|
298
|
-
@conn.add_context_index :posts, [:title, :body], :
|
|
309
|
+
@conn.add_context_index :posts, [:title, :body], name: "index_posts_text", tablespace: @conn.default_tablespace
|
|
299
310
|
verify_logged_statements
|
|
300
|
-
Post.contains(:title,
|
|
301
|
-
@conn.remove_context_index :posts, :
|
|
311
|
+
expect(Post.contains(:title, "aaa AND bbb").to_a).to eq([@post])
|
|
312
|
+
@conn.remove_context_index :posts, name: "index_posts_text"
|
|
302
313
|
end
|
|
303
314
|
|
|
304
315
|
end
|
|
305
316
|
|
|
306
317
|
describe "schema dump" do
|
|
307
318
|
|
|
308
|
-
def standard_dump
|
|
309
|
-
stream = StringIO.new
|
|
310
|
-
ActiveRecord::SchemaDumper.ignore_tables = []
|
|
311
|
-
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
|
312
|
-
stream.string
|
|
313
|
-
end
|
|
314
|
-
|
|
315
319
|
describe "without table prefixe and suffix" do
|
|
316
320
|
|
|
317
321
|
before(:all) do
|
|
@@ -325,89 +329,96 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
325
329
|
|
|
326
330
|
it "should dump definition of single column index" do
|
|
327
331
|
@conn.add_context_index :posts, :title
|
|
328
|
-
|
|
332
|
+
output = dump_table_schema "posts"
|
|
333
|
+
expect(output).to match(/add_context_index "posts", \["title"\], name: \"index_posts_on_title\"$/)
|
|
329
334
|
@conn.remove_context_index :posts, :title
|
|
330
335
|
end
|
|
331
336
|
|
|
332
337
|
it "should dump definition of multiple column index" do
|
|
333
338
|
@conn.add_context_index :posts, [:title, :body]
|
|
334
|
-
|
|
339
|
+
output = dump_table_schema "posts"
|
|
340
|
+
expect(output).to match(/add_context_index "posts", \[:title, :body\]$/)
|
|
335
341
|
@conn.remove_context_index :posts, [:title, :body]
|
|
336
342
|
end
|
|
337
343
|
|
|
338
344
|
it "should dump definition of multiple table index with options" do
|
|
339
345
|
options = {
|
|
340
|
-
:
|
|
341
|
-
:
|
|
342
|
-
:
|
|
343
|
-
:
|
|
346
|
+
name: "post_and_comments_index",
|
|
347
|
+
index_column: :all_text, index_column_trigger_on: :updated_at,
|
|
348
|
+
transactional: true,
|
|
349
|
+
sync: "ON COMMIT"
|
|
344
350
|
}
|
|
345
351
|
sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
|
346
352
|
@conn.add_context_index :posts, [:title, :body, sub_query], options
|
|
347
|
-
|
|
348
|
-
|
|
353
|
+
output = dump_table_schema "posts"
|
|
354
|
+
expect(output).to match(/add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/)
|
|
355
|
+
@conn.remove_context_index :posts, name: "post_and_comments_index"
|
|
349
356
|
end
|
|
350
357
|
|
|
351
358
|
it "should dump definition of multiple table index with options (when definition is larger than 4000 bytes)" do
|
|
352
359
|
options = {
|
|
353
|
-
:
|
|
354
|
-
:
|
|
355
|
-
:
|
|
356
|
-
:
|
|
360
|
+
name: "post_and_comments_index",
|
|
361
|
+
index_column: :all_text, index_column_trigger_on: :updated_at,
|
|
362
|
+
transactional: true,
|
|
363
|
+
sync: "ON COMMIT"
|
|
357
364
|
}
|
|
358
365
|
sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id#{' AND 1=1' * 500}"
|
|
359
366
|
@conn.add_context_index :posts, [:title, :body, sub_query], options
|
|
360
|
-
|
|
361
|
-
|
|
367
|
+
output = dump_table_schema "posts"
|
|
368
|
+
expect(output).to match(/add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/)
|
|
369
|
+
@conn.remove_context_index :posts, name: "post_and_comments_index"
|
|
362
370
|
end
|
|
363
371
|
|
|
364
372
|
it "should dump definition of multiple table index with options (when subquery has newlines)" do
|
|
365
373
|
options = {
|
|
366
|
-
:
|
|
367
|
-
:
|
|
368
|
-
:
|
|
369
|
-
:
|
|
374
|
+
name: "post_and_comments_index",
|
|
375
|
+
index_column: :all_text, index_column_trigger_on: :updated_at,
|
|
376
|
+
transactional: true,
|
|
377
|
+
sync: "ON COMMIT"
|
|
370
378
|
}
|
|
371
379
|
sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body\nFROM comments\nWHERE comments.post_id = :id"
|
|
372
380
|
@conn.add_context_index :posts, [:title, :body, sub_query], options
|
|
373
|
-
|
|
374
|
-
|
|
381
|
+
output = dump_table_schema "posts"
|
|
382
|
+
expect(output).to match(/add_context_index "posts", \[:title, :body, "#{sub_query.gsub(/\n/, ' ')}"\], #{options.inspect[1..-2]}$/)
|
|
383
|
+
@conn.remove_context_index :posts, name: "post_and_comments_index"
|
|
375
384
|
end
|
|
376
385
|
|
|
377
386
|
end
|
|
378
387
|
|
|
379
388
|
describe "with table prefix and suffix" do
|
|
380
389
|
before(:all) do
|
|
381
|
-
ActiveRecord::Base.table_name_prefix =
|
|
382
|
-
ActiveRecord::Base.table_name_suffix =
|
|
390
|
+
ActiveRecord::Base.table_name_prefix = "xxx_"
|
|
391
|
+
ActiveRecord::Base.table_name_suffix = "_xxx"
|
|
383
392
|
create_tables
|
|
384
393
|
end
|
|
385
394
|
|
|
386
395
|
after(:all) do
|
|
387
396
|
drop_tables
|
|
388
|
-
ActiveRecord::Base.table_name_prefix =
|
|
389
|
-
ActiveRecord::Base.table_name_suffix =
|
|
397
|
+
ActiveRecord::Base.table_name_prefix = ""
|
|
398
|
+
ActiveRecord::Base.table_name_suffix = ""
|
|
390
399
|
end
|
|
391
400
|
|
|
392
401
|
it "should dump definition of single column index" do
|
|
393
402
|
schema_define { add_context_index :posts, :title }
|
|
394
|
-
|
|
403
|
+
output = dump_table_schema "posts"
|
|
404
|
+
expect(output).to match(/add_context_index "posts", \["title"\], name: "i_xxx_posts_xxx_title"$/)
|
|
395
405
|
schema_define { remove_context_index :posts, :title }
|
|
396
406
|
end
|
|
397
407
|
|
|
398
408
|
it "should dump definition of multiple column index" do
|
|
399
409
|
schema_define { add_context_index :posts, [:title, :body] }
|
|
400
|
-
|
|
410
|
+
output = dump_table_schema "posts"
|
|
411
|
+
expect(output).to match(/add_context_index "posts", \[:title, :body\]$/)
|
|
401
412
|
schema_define { remove_context_index :posts, [:title, :body] }
|
|
402
413
|
end
|
|
403
414
|
|
|
404
415
|
it "should dump definition of multiple table index with options" do
|
|
405
416
|
options = {
|
|
406
|
-
:
|
|
407
|
-
:
|
|
408
|
-
:
|
|
409
|
-
:
|
|
410
|
-
:
|
|
417
|
+
name: "xxx_post_and_comments_i",
|
|
418
|
+
index_column: :all_text, index_column_trigger_on: :updated_at,
|
|
419
|
+
lexer: { type: "BASIC_LEXER", base_letter_type: "GENERIC", base_letter: true },
|
|
420
|
+
wordlist: { type: "BASIC_WORDLIST", prefix_index: true },
|
|
421
|
+
sync: "ON COMMIT"
|
|
411
422
|
}
|
|
412
423
|
schema_define do
|
|
413
424
|
add_context_index :posts,
|
|
@@ -415,9 +426,10 @@ describe "OracleEnhancedAdapter context index" do
|
|
|
415
426
|
"SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
|
416
427
|
], options
|
|
417
428
|
end
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
429
|
+
output = dump_table_schema "posts"
|
|
430
|
+
expect(output).to match(/add_context_index "posts", \[:title, :body, "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"\], #{
|
|
431
|
+
options.inspect[1..-2].gsub(/[{}]/) { |s| '\\'.dup << s }}$/)
|
|
432
|
+
schema_define { remove_context_index :posts, name: "xxx_post_and_comments_i" }
|
|
421
433
|
end
|
|
422
434
|
|
|
423
435
|
end
|