activerecord-oracle_enhanced-adapter 5.2.8 → 6.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +79 -13
- data/README.md +1 -7
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +10 -13
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +7 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +4 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +7 -18
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +17 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +32 -32
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +17 -27
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +4 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +13 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +1 -13
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +55 -71
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +27 -17
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +87 -61
- data/lib/active_record/type/oracle_enhanced/character_string.rb +36 -0
- data/spec/active_record/connection_adapters/emulation/oracle_adapter_spec.rb +0 -2
- data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +25 -50
- data/spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb +5 -13
- data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +0 -2
- data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +0 -15
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +1 -31
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +71 -253
- data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +2 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +81 -81
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +0 -1
- data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +0 -2
- data/spec/active_record/oracle_enhanced/type/character_string_spec.rb +43 -0
- data/spec/active_record/oracle_enhanced/type/decimal_spec.rb +56 -0
- data/spec/active_record/oracle_enhanced/type/dirty_spec.rb +1 -1
- data/spec/active_record/oracle_enhanced/type/json_spec.rb +0 -1
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +1 -2
- data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +0 -2
- data/spec/spec_helper.rb +2 -0
- metadata +27 -23
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +0 -28
@@ -8,6 +8,8 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
8
8
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
9
9
|
@oracle11g_or_higher = !! !! ActiveRecord::Base.connection.select_value(
|
10
10
|
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
|
11
|
+
@oracle12cr2_or_higher = !! !! ActiveRecord::Base.connection.select_value(
|
12
|
+
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,4)) >= 12.2")
|
11
13
|
end
|
12
14
|
|
13
15
|
describe "option to create sequence when adding a column" do
|
@@ -30,7 +32,6 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
30
32
|
end
|
31
33
|
|
32
34
|
describe "table and sequence creation with non-default primary key" do
|
33
|
-
|
34
35
|
before(:all) do
|
35
36
|
@conn = ActiveRecord::Base.connection
|
36
37
|
schema_define do
|
@@ -69,7 +70,6 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
69
70
|
end
|
70
71
|
|
71
72
|
describe "default sequence name" do
|
72
|
-
|
73
73
|
it "should return sequence name without truncating too much" do
|
74
74
|
seq_name_length = ActiveRecord::Base.connection.sequence_name_length
|
75
75
|
tname = "#{DATABASE_USER}" + "." + "a" * (seq_name_length - DATABASE_USER.length) + "z" * (DATABASE_USER).length
|
@@ -78,7 +78,6 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
describe "sequence creation parameters" do
|
81
|
-
|
82
81
|
def create_test_employees_table(sequence_start_value = nil)
|
83
82
|
schema_define do
|
84
83
|
create_table :test_employees, sequence_start_value ? { sequence_start_value: sequence_start_value } : {} do |t|
|
@@ -113,24 +112,24 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
113
112
|
ActiveRecord::Base.clear_cache!
|
114
113
|
end
|
115
114
|
|
116
|
-
it "should use default sequence start value
|
117
|
-
expect(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value).to eq(
|
115
|
+
it "should use default sequence start value 1" do
|
116
|
+
expect(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value).to eq(1)
|
118
117
|
|
119
118
|
create_test_employees_table
|
120
119
|
class ::TestEmployee < ActiveRecord::Base; end
|
121
120
|
|
122
121
|
employee = TestEmployee.create!
|
123
|
-
expect(employee.id).to eq(
|
122
|
+
expect(employee.id).to eq(1)
|
124
123
|
end
|
125
124
|
|
126
125
|
it "should use specified default sequence start value" do
|
127
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value =
|
126
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value = 10000
|
128
127
|
|
129
128
|
create_test_employees_table
|
130
129
|
class ::TestEmployee < ActiveRecord::Base; end
|
131
130
|
|
132
131
|
employee = TestEmployee.create!
|
133
|
-
expect(employee.id).to eq(
|
132
|
+
expect(employee.id).to eq(10000)
|
134
133
|
end
|
135
134
|
|
136
135
|
it "should use sequence start value from table definition" do
|
@@ -150,177 +149,9 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
150
149
|
employee = TestEmployee.create!
|
151
150
|
expect(employee.id).to eq(110)
|
152
151
|
end
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
describe "create table with primary key trigger" do
|
157
|
-
def create_table_with_trigger(options = {})
|
158
|
-
options.merge! primary_key_trigger: true, force: true
|
159
|
-
schema_define do
|
160
|
-
create_table :test_employees, options do |t|
|
161
|
-
t.string :first_name
|
162
|
-
t.string :last_name
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def create_table_and_separately_trigger(options = {})
|
168
|
-
options.merge! force: true
|
169
|
-
schema_define do
|
170
|
-
create_table :test_employees, options do |t|
|
171
|
-
t.string :first_name
|
172
|
-
t.string :last_name
|
173
|
-
end
|
174
|
-
add_primary_key_trigger :test_employees, options
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def drop_table_with_trigger(options = {})
|
179
|
-
seq_name = options[:sequence_name]
|
180
|
-
schema_define do
|
181
|
-
drop_table :test_employees, (seq_name ? { sequence_name: seq_name } : {})
|
182
|
-
end
|
183
|
-
Object.send(:remove_const, "TestEmployee")
|
184
|
-
ActiveRecord::Base.clear_cache!
|
185
|
-
end
|
186
|
-
|
187
|
-
describe "with default primary key" do
|
188
|
-
before(:all) do
|
189
|
-
@conn = ActiveRecord::Base.connection
|
190
|
-
create_table_with_trigger
|
191
|
-
class ::TestEmployee < ActiveRecord::Base
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
after(:all) do
|
196
|
-
drop_table_with_trigger
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should populate primary key using trigger" do
|
200
|
-
expect do
|
201
|
-
@conn.execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
|
202
|
-
end.not_to raise_error
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should return new key value using connection insert method" do
|
206
|
-
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Raimonds')", nil, "id")
|
207
|
-
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(insert_id)
|
208
|
-
end
|
209
|
-
|
210
|
-
it "should create new record for model" do
|
211
|
-
e = TestEmployee.create!(first_name: "Raimonds")
|
212
|
-
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(e.id)
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should not generate NoMethodError for :returning_id:Symbol" do
|
216
|
-
set_logger
|
217
|
-
@conn.reconnect! unless @conn.active?
|
218
|
-
@conn.insert("INSERT INTO test_employees (first_name) VALUES ('Yasuo')", nil, "id")
|
219
|
-
expect(@logger.output(:error)).not_to match(/^Could not log "sql.active_record" event. NoMethodError: undefined method `name' for :returning_id:Symbol/)
|
220
|
-
clear_logger
|
221
|
-
end
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
describe "with separate creation of primary key trigger" do
|
226
|
-
before(:all) do
|
227
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
228
|
-
@conn = ActiveRecord::Base.connection
|
229
|
-
create_table_and_separately_trigger
|
230
|
-
class ::TestEmployee < ActiveRecord::Base
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
after(:all) do
|
235
|
-
drop_table_with_trigger
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should populate primary key using trigger" do
|
239
|
-
expect do
|
240
|
-
@conn.execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
|
241
|
-
end.not_to raise_error
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should return new key value using connection insert method" do
|
245
|
-
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Raimonds')", nil, "id")
|
246
|
-
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(insert_id)
|
247
|
-
end
|
248
|
-
|
249
|
-
it "should create new record for model" do
|
250
|
-
e = TestEmployee.create!(first_name: "Raimonds")
|
251
|
-
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(e.id)
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
describe "with non-default primary key and non-default sequence name" do
|
256
|
-
before(:all) do
|
257
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
258
|
-
@conn = ActiveRecord::Base.connection
|
259
|
-
@primary_key = "employee_id"
|
260
|
-
@sequence_name = "test_employees_s"
|
261
|
-
create_table_with_trigger(primary_key: @primary_key, sequence_name: @sequence_name)
|
262
|
-
class ::TestEmployee < ActiveRecord::Base
|
263
|
-
self.primary_key = "employee_id"
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
after(:all) do
|
268
|
-
drop_table_with_trigger(sequence_name: @sequence_name)
|
269
|
-
end
|
270
|
-
|
271
|
-
it "should populate primary key using trigger" do
|
272
|
-
expect do
|
273
|
-
@conn.execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
|
274
|
-
end.not_to raise_error
|
275
|
-
end
|
276
|
-
|
277
|
-
it "should return new key value using connection insert method" do
|
278
|
-
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Raimonds')", nil, @primary_key)
|
279
|
-
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(insert_id)
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should create new record for model with autogenerated sequence option" do
|
283
|
-
e = TestEmployee.create!(first_name: "Raimonds")
|
284
|
-
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(e.id)
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
describe "with non-default sequence name and non-default trigger name" do
|
289
|
-
before(:all) do
|
290
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
291
|
-
@conn = ActiveRecord::Base.connection
|
292
|
-
@sequence_name = "test_employees_s"
|
293
|
-
create_table_with_trigger(sequence_name: @sequence_name, trigger_name: "test_employees_t1")
|
294
|
-
class ::TestEmployee < ActiveRecord::Base
|
295
|
-
self.sequence_name = :autogenerated
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
after(:all) do
|
300
|
-
drop_table_with_trigger(sequence_name: @sequence_name)
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should populate primary key using trigger" do
|
304
|
-
expect do
|
305
|
-
@conn.execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
|
306
|
-
end.not_to raise_error
|
307
|
-
end
|
308
|
-
|
309
|
-
it "should return new key value using connection insert method" do
|
310
|
-
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Raimonds')", nil, "id")
|
311
|
-
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(insert_id)
|
312
|
-
end
|
313
|
-
|
314
|
-
it "should create new record for model with autogenerated sequence option" do
|
315
|
-
e = TestEmployee.create!(first_name: "Raimonds")
|
316
|
-
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(e.id)
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
152
|
end
|
321
153
|
|
322
154
|
describe "table and column comments" do
|
323
|
-
|
324
155
|
def create_test_employees_table(table_comment = nil, column_comments = {})
|
325
156
|
schema_define do
|
326
157
|
create_table :test_employees, comment: table_comment do |t|
|
@@ -390,9 +221,8 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
390
221
|
create_test_employees_table(table_comment)
|
391
222
|
class ::TestEmployee < ActiveRecord::Base; end
|
392
223
|
expect(@conn.table_comment(TestEmployee.table_name)).to eq(table_comment)
|
393
|
-
expect(@logger.logged(:debug).last).to match(/:owner/)
|
394
224
|
expect(@logger.logged(:debug).last).to match(/:table_name/)
|
395
|
-
expect(@logger.logged(:debug).last).to match(/\[
|
225
|
+
expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_EMPLOYEES"\]\]/)
|
396
226
|
end
|
397
227
|
|
398
228
|
it "should query column_comment using bind variables" do
|
@@ -401,12 +231,10 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
401
231
|
create_test_employees_table(table_comment, column_comment)
|
402
232
|
class ::TestEmployee < ActiveRecord::Base; end
|
403
233
|
expect(@conn.column_comment(TestEmployee.table_name, :first_name)).to eq(column_comment[:first_name])
|
404
|
-
expect(@logger.logged(:debug).last).to match(/:owner/)
|
405
234
|
expect(@logger.logged(:debug).last).to match(/:table_name/)
|
406
235
|
expect(@logger.logged(:debug).last).to match(/:column_name/)
|
407
|
-
expect(@logger.logged(:debug).last).to match(/\[
|
236
|
+
expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_EMPLOYEES"\], \["column_name", "FIRST_NAME"\]\]/)
|
408
237
|
end
|
409
|
-
|
410
238
|
end
|
411
239
|
|
412
240
|
describe "drop tables" do
|
@@ -471,45 +299,6 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
471
299
|
@conn.rename_table("test_employees_no_pkey", "new_test_employees_no_pkey")
|
472
300
|
end.not_to raise_error
|
473
301
|
end
|
474
|
-
|
475
|
-
end
|
476
|
-
|
477
|
-
describe "create triggers" do
|
478
|
-
|
479
|
-
before(:all) do
|
480
|
-
@conn = ActiveRecord::Base.connection
|
481
|
-
schema_define do
|
482
|
-
create_table :test_employees do |t|
|
483
|
-
t.string :first_name
|
484
|
-
t.string :last_name
|
485
|
-
end
|
486
|
-
end
|
487
|
-
class ::TestEmployee < ActiveRecord::Base; end
|
488
|
-
end
|
489
|
-
|
490
|
-
after(:all) do
|
491
|
-
schema_define do
|
492
|
-
drop_table :test_employees
|
493
|
-
end
|
494
|
-
Object.send(:remove_const, "TestEmployee")
|
495
|
-
ActiveRecord::Base.clear_cache!
|
496
|
-
end
|
497
|
-
|
498
|
-
it "should create table trigger with :new reference" do
|
499
|
-
expect do
|
500
|
-
@conn.execute <<-SQL
|
501
|
-
CREATE OR REPLACE TRIGGER test_employees_pkt
|
502
|
-
BEFORE INSERT ON test_employees FOR EACH ROW
|
503
|
-
BEGIN
|
504
|
-
IF inserting THEN
|
505
|
-
IF :new.id IS NULL THEN
|
506
|
-
SELECT test_employees_seq.NEXTVAL INTO :new.id FROM dual;
|
507
|
-
END IF;
|
508
|
-
END IF;
|
509
|
-
END;
|
510
|
-
SQL
|
511
|
-
end.not_to raise_error
|
512
|
-
end
|
513
302
|
end
|
514
303
|
|
515
304
|
describe "add index" do
|
@@ -522,19 +311,31 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
522
311
|
end
|
523
312
|
|
524
313
|
it "should return shortened index name by removing 'index', 'on' and 'and' keywords" do
|
525
|
-
|
314
|
+
if @oracle12cr2_or_higher
|
315
|
+
expect(@conn.index_name("employees", column: ["first_name", "email"])).to eq("index_employees_on_first_name_and_email")
|
316
|
+
else
|
317
|
+
expect(@conn.index_name("employees", column: ["first_name", "email"])).to eq("i_employees_first_name_email")
|
318
|
+
end
|
526
319
|
end
|
527
320
|
|
528
321
|
it "should return shortened index name by shortening table and column names" do
|
529
|
-
|
322
|
+
if @oracle12cr2_or_higher
|
323
|
+
expect(@conn.index_name("employees", column: ["first_name", "last_name"])).to eq("index_employees_on_first_name_and_last_name")
|
324
|
+
else
|
325
|
+
expect(@conn.index_name("employees", column: ["first_name", "last_name"])).to eq("i_emp_fir_nam_las_nam")
|
326
|
+
end
|
530
327
|
end
|
531
328
|
|
532
329
|
it "should raise error if too large index name cannot be shortened" do
|
533
|
-
|
534
|
-
"
|
535
|
-
|
330
|
+
if @oracle12cr2_or_higher
|
331
|
+
expect(@conn.index_name("test_employees", column: ["first_name", "middle_name", "last_name"])).to eq(
|
332
|
+
("index_test_employees_on_first_name_and_middle_name_and_last_name"))
|
333
|
+
else
|
334
|
+
expect(@conn.index_name("test_employees", column: ["first_name", "middle_name", "last_name"])).to eq(
|
335
|
+
"i" + Digest::SHA1.hexdigest("index_test_employees_on_first_name_and_middle_name_and_last_name")[0, 29]
|
336
|
+
)
|
337
|
+
end
|
536
338
|
end
|
537
|
-
|
538
339
|
end
|
539
340
|
|
540
341
|
describe "rename index" do
|
@@ -565,6 +366,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
565
366
|
end
|
566
367
|
|
567
368
|
it "should raise error when new index name length is too long" do
|
369
|
+
skip if @oracle12cr2_or_higher
|
568
370
|
expect do
|
569
371
|
@conn.rename_index("test_employees", "i_test_employees_first_name", "a" * 31)
|
570
372
|
end.to raise_error(ArgumentError)
|
@@ -577,6 +379,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
577
379
|
end
|
578
380
|
|
579
381
|
it "should rename index name with new one" do
|
382
|
+
skip if @oracle12cr2_or_higher
|
580
383
|
expect do
|
581
384
|
@conn.rename_index("test_employees", "i_test_employees_first_name", "new_index_name")
|
582
385
|
end.not_to raise_error
|
@@ -609,7 +412,6 @@ end
|
|
609
412
|
end
|
610
413
|
end.not_to raise_error
|
611
414
|
end
|
612
|
-
|
613
415
|
end
|
614
416
|
|
615
417
|
describe "foreign key constraints" do
|
@@ -737,11 +539,9 @@ end
|
|
737
539
|
add_foreign_key :test_comments, :test_posts
|
738
540
|
end
|
739
541
|
ActiveRecord::Base.connection.foreign_keys(:test_comments)
|
740
|
-
expect(@logger.logged(:debug).last).to match(/:owner/)
|
741
542
|
expect(@logger.logged(:debug).last).to match(/:desc_table_name/)
|
742
|
-
expect(@logger.logged(:debug).last).to match(/\[
|
543
|
+
expect(@logger.logged(:debug).last).to match(/\["desc_table_name", "TEST_COMMENTS"\]\]/)
|
743
544
|
end
|
744
|
-
|
745
545
|
end
|
746
546
|
|
747
547
|
describe "lob in table definition" do
|
@@ -930,7 +730,6 @@ end
|
|
930
730
|
TestComment.create(body: "test", test_post_id: 1)
|
931
731
|
end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
|
932
732
|
end
|
933
|
-
|
934
733
|
end
|
935
734
|
|
936
735
|
describe "disable referential integrity" do
|
@@ -977,18 +776,12 @@ end
|
|
977
776
|
@conn.execute "INSERT INTO test_comments (id, body, test_post_id) VALUES (3, 'test', 3)"
|
978
777
|
end.to raise_error(ActiveRecord::InvalidForeignKey)
|
979
778
|
end
|
980
|
-
|
981
779
|
end
|
982
780
|
|
983
781
|
describe "synonyms" do
|
984
782
|
before(:all) do
|
985
783
|
@conn = ActiveRecord::Base.connection
|
986
|
-
@
|
987
|
-
@username = @db_link_username = CONNECTION_PARAMS[:username]
|
988
|
-
@db_link_password = CONNECTION_PARAMS[:password]
|
989
|
-
@db_link_database = CONNECTION_PARAMS[:database]
|
990
|
-
@conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
|
991
|
-
@conn.execute "CREATE DATABASE LINK #{@db_link} CONNECT TO #{@db_link_username} IDENTIFIED BY \"#{@db_link_password}\" USING '#{@db_link_database}'"
|
784
|
+
@username = CONNECTION_PARAMS[:username]
|
992
785
|
schema_define do
|
993
786
|
create_table :test_posts, force: true do |t|
|
994
787
|
t.string :title
|
@@ -1000,7 +793,6 @@ end
|
|
1000
793
|
schema_define do
|
1001
794
|
drop_table :test_posts
|
1002
795
|
end
|
1003
|
-
@conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
|
1004
796
|
end
|
1005
797
|
|
1006
798
|
before(:each) do
|
@@ -1028,18 +820,6 @@ end
|
|
1028
820
|
TestPost.create(title: "test")
|
1029
821
|
end.not_to raise_error
|
1030
822
|
end
|
1031
|
-
|
1032
|
-
it "should create synonym to table over database link" do
|
1033
|
-
db_link = @db_link
|
1034
|
-
schema_define do
|
1035
|
-
add_synonym :synonym_to_posts, "test_posts@#{db_link}", force: true
|
1036
|
-
add_synonym :synonym_to_posts_seq, "test_posts_seq@#{db_link}", force: true
|
1037
|
-
end
|
1038
|
-
expect do
|
1039
|
-
TestPost.create(title: "test")
|
1040
|
-
end.not_to raise_error
|
1041
|
-
end
|
1042
|
-
|
1043
823
|
end
|
1044
824
|
|
1045
825
|
describe "alter columns with column cache" do
|
@@ -1090,6 +870,15 @@ end
|
|
1090
870
|
expect(TestPost.columns_hash["body"]).not_to be_nil
|
1091
871
|
end
|
1092
872
|
|
873
|
+
it "should add longer column" do
|
874
|
+
skip unless @oracle12cr2_or_higher
|
875
|
+
schema_define do
|
876
|
+
add_column :test_posts, "a" * 128, :string
|
877
|
+
end
|
878
|
+
TestPost.reset_column_information
|
879
|
+
expect(TestPost.columns_hash["a" * 128]).not_to be_nil
|
880
|
+
end
|
881
|
+
|
1093
882
|
it "should add lob column with non_default tablespace" do
|
1094
883
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = DATABASE_NON_DEFAULT_TABLESPACE
|
1095
884
|
schema_define do
|
@@ -1295,13 +1084,43 @@ end
|
|
1295
1084
|
end
|
1296
1085
|
end
|
1297
1086
|
|
1087
|
+
describe "materialized views" do
|
1088
|
+
before(:all) do
|
1089
|
+
@conn = ActiveRecord::Base.connection
|
1090
|
+
schema_define do
|
1091
|
+
create_table :test_employees, force: true do |t|
|
1092
|
+
t.string :first_name
|
1093
|
+
t.string :last_name
|
1094
|
+
end
|
1095
|
+
end
|
1096
|
+
@conn.execute("create materialized view sum_test_employees as select first_name, count(*) from test_employees group by first_name")
|
1097
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
after(:all) do
|
1101
|
+
@conn.execute("drop materialized view sum_test_employees") rescue nil
|
1102
|
+
schema_define do
|
1103
|
+
drop_table :sum_test_employees, if_exists: true
|
1104
|
+
drop_table :test_employees, if_exists: true
|
1105
|
+
end
|
1106
|
+
end
|
1107
|
+
|
1108
|
+
it "tables should not return materialized views" do
|
1109
|
+
expect(@conn.tables).not_to include("sum_test_employees")
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
it "materialized_views should return materialized views" do
|
1113
|
+
expect(@conn.materialized_views).to include("sum_test_employees")
|
1114
|
+
end
|
1115
|
+
end
|
1116
|
+
|
1298
1117
|
describe "miscellaneous options" do
|
1299
1118
|
before(:all) do
|
1300
1119
|
@conn = ActiveRecord::Base.connection
|
1301
1120
|
end
|
1302
1121
|
|
1303
1122
|
before(:each) do
|
1304
|
-
@conn.instance_variable_set :@would_execute_sql, @would_execute_sql = ""
|
1123
|
+
@conn.instance_variable_set :@would_execute_sql, @would_execute_sql = +""
|
1305
1124
|
class <<@conn
|
1306
1125
|
def execute(sql, name = nil); @would_execute_sql << sql << ";\n"; end
|
1307
1126
|
end
|
@@ -1388,7 +1207,6 @@ end
|
|
1388
1207
|
end
|
1389
1208
|
expect(@would_execute_sql).not_to match(/ALTER +TABLE .* ADD CONSTRAINT .* UNIQUE \(.*\(.*\)\)/)
|
1390
1209
|
end
|
1391
|
-
|
1392
1210
|
end
|
1393
1211
|
|
1394
1212
|
describe "load schema" do
|