activerecord-oracle_enhanced-adapter 5.2.8 → 7.0.3
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/History.md +390 -21
- data/README.md +35 -8
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +42 -37
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +59 -60
- data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +5 -10
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +86 -81
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +9 -10
- data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +1 -2
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +37 -16
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +5 -6
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +58 -49
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +6 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +75 -51
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +13 -14
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +14 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +27 -24
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +156 -155
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +103 -90
- data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +3 -2
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +261 -161
- data/lib/active_record/type/oracle_enhanced/boolean.rb +0 -1
- data/lib/active_record/type/oracle_enhanced/character_string.rb +36 -0
- data/lib/active_record/type/oracle_enhanced/integer.rb +0 -1
- data/lib/arel/visitors/oracle.rb +221 -0
- data/lib/arel/visitors/oracle12.rb +128 -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 +78 -26
- data/spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb +7 -15
- data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +5 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/dbms_output_spec.rb +17 -17
- data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +7 -10
- 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 +33 -36
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +77 -258
- data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +38 -39
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +273 -85
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +7 -8
- data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +2 -4
- data/spec/active_record/oracle_enhanced/type/character_string_spec.rb +43 -0
- data/spec/active_record/oracle_enhanced/type/custom_spec.rb +90 -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/integer_spec.rb +2 -2
- data/spec/active_record/oracle_enhanced/type/json_spec.rb +0 -1
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +6 -5
- data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +2 -4
- data/spec/spec_config.yaml.template +2 -2
- data/spec/spec_helper.rb +13 -2
- metadata +52 -30
- 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,10 +78,10 @@ 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
|
+
options = sequence_start_value ? { sequence_start_value: sequence_start_value } : {}
|
84
|
+
create_table :test_employees, **options do |t|
|
85
85
|
t.string :first_name
|
86
86
|
t.string :last_name
|
87
87
|
end
|
@@ -113,24 +113,24 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
113
113
|
ActiveRecord::Base.clear_cache!
|
114
114
|
end
|
115
115
|
|
116
|
-
it "should use default sequence start value
|
117
|
-
expect(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value).to eq(
|
116
|
+
it "should use default sequence start value 1" do
|
117
|
+
expect(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value).to eq(1)
|
118
118
|
|
119
119
|
create_test_employees_table
|
120
120
|
class ::TestEmployee < ActiveRecord::Base; end
|
121
121
|
|
122
122
|
employee = TestEmployee.create!
|
123
|
-
expect(employee.id).to eq(
|
123
|
+
expect(employee.id).to eq(1)
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should use specified default sequence start value" do
|
127
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value =
|
127
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value = 10000
|
128
128
|
|
129
129
|
create_test_employees_table
|
130
130
|
class ::TestEmployee < ActiveRecord::Base; end
|
131
131
|
|
132
132
|
employee = TestEmployee.create!
|
133
|
-
expect(employee.id).to eq(
|
133
|
+
expect(employee.id).to eq(10000)
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should use sequence start value from table definition" do
|
@@ -150,177 +150,9 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
150
150
|
employee = TestEmployee.create!
|
151
151
|
expect(employee.id).to eq(110)
|
152
152
|
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
153
|
end
|
321
154
|
|
322
155
|
describe "table and column comments" do
|
323
|
-
|
324
156
|
def create_test_employees_table(table_comment = nil, column_comments = {})
|
325
157
|
schema_define do
|
326
158
|
create_table :test_employees, comment: table_comment do |t|
|
@@ -390,9 +222,8 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
390
222
|
create_test_employees_table(table_comment)
|
391
223
|
class ::TestEmployee < ActiveRecord::Base; end
|
392
224
|
expect(@conn.table_comment(TestEmployee.table_name)).to eq(table_comment)
|
393
|
-
expect(@logger.logged(:debug).last).to match(/:owner/)
|
394
225
|
expect(@logger.logged(:debug).last).to match(/:table_name/)
|
395
|
-
expect(@logger.logged(:debug).last).to match(/\[
|
226
|
+
expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_EMPLOYEES"\]\]/)
|
396
227
|
end
|
397
228
|
|
398
229
|
it "should query column_comment using bind variables" do
|
@@ -401,12 +232,10 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
401
232
|
create_test_employees_table(table_comment, column_comment)
|
402
233
|
class ::TestEmployee < ActiveRecord::Base; end
|
403
234
|
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
235
|
expect(@logger.logged(:debug).last).to match(/:table_name/)
|
406
236
|
expect(@logger.logged(:debug).last).to match(/:column_name/)
|
407
|
-
expect(@logger.logged(:debug).last).to match(/\[
|
237
|
+
expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_EMPLOYEES"\], \["column_name", "FIRST_NAME"\]\]/)
|
408
238
|
end
|
409
|
-
|
410
239
|
end
|
411
240
|
|
412
241
|
describe "drop tables" do
|
@@ -471,45 +300,6 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
471
300
|
@conn.rename_table("test_employees_no_pkey", "new_test_employees_no_pkey")
|
472
301
|
end.not_to raise_error
|
473
302
|
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
303
|
end
|
514
304
|
|
515
305
|
describe "add index" do
|
@@ -522,19 +312,31 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
522
312
|
end
|
523
313
|
|
524
314
|
it "should return shortened index name by removing 'index', 'on' and 'and' keywords" do
|
525
|
-
|
315
|
+
if @oracle12cr2_or_higher
|
316
|
+
expect(@conn.index_name("employees", column: ["first_name", "email"])).to eq("index_employees_on_first_name_and_email")
|
317
|
+
else
|
318
|
+
expect(@conn.index_name("employees", column: ["first_name", "email"])).to eq("i_employees_first_name_email")
|
319
|
+
end
|
526
320
|
end
|
527
321
|
|
528
322
|
it "should return shortened index name by shortening table and column names" do
|
529
|
-
|
323
|
+
if @oracle12cr2_or_higher
|
324
|
+
expect(@conn.index_name("employees", column: ["first_name", "last_name"])).to eq("index_employees_on_first_name_and_last_name")
|
325
|
+
else
|
326
|
+
expect(@conn.index_name("employees", column: ["first_name", "last_name"])).to eq("i_emp_fir_nam_las_nam")
|
327
|
+
end
|
530
328
|
end
|
531
329
|
|
532
330
|
it "should raise error if too large index name cannot be shortened" do
|
533
|
-
|
534
|
-
"
|
535
|
-
|
331
|
+
if @oracle12cr2_or_higher
|
332
|
+
expect(@conn.index_name("test_employees", column: ["first_name", "middle_name", "last_name"])).to eq(
|
333
|
+
("index_test_employees_on_first_name_and_middle_name_and_last_name"))
|
334
|
+
else
|
335
|
+
expect(@conn.index_name("test_employees", column: ["first_name", "middle_name", "last_name"])).to eq(
|
336
|
+
"i" + OpenSSL::Digest::SHA1.hexdigest("index_test_employees_on_first_name_and_middle_name_and_last_name")[0, 29]
|
337
|
+
)
|
338
|
+
end
|
536
339
|
end
|
537
|
-
|
538
340
|
end
|
539
341
|
|
540
342
|
describe "rename index" do
|
@@ -565,6 +367,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
565
367
|
end
|
566
368
|
|
567
369
|
it "should raise error when new index name length is too long" do
|
370
|
+
skip if @oracle12cr2_or_higher
|
568
371
|
expect do
|
569
372
|
@conn.rename_index("test_employees", "i_test_employees_first_name", "a" * 31)
|
570
373
|
end.to raise_error(ArgumentError)
|
@@ -577,6 +380,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
577
380
|
end
|
578
381
|
|
579
382
|
it "should rename index name with new one" do
|
383
|
+
skip if @oracle12cr2_or_higher
|
580
384
|
expect do
|
581
385
|
@conn.rename_index("test_employees", "i_test_employees_first_name", "new_index_name")
|
582
386
|
end.not_to raise_error
|
@@ -609,7 +413,6 @@ end
|
|
609
413
|
end
|
610
414
|
end.not_to raise_error
|
611
415
|
end
|
612
|
-
|
613
416
|
end
|
614
417
|
|
615
418
|
describe "foreign key constraints" do
|
@@ -652,7 +455,7 @@ end
|
|
652
455
|
end
|
653
456
|
|
654
457
|
it "should add foreign key" do
|
655
|
-
fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_test_post_id_fk").first(10)}"
|
458
|
+
fk_name = "fk_rails_#{OpenSSL::Digest::SHA256.hexdigest("test_comments_test_post_id_fk").first(10)}"
|
656
459
|
|
657
460
|
schema_define do
|
658
461
|
add_foreign_key :test_comments, :test_posts
|
@@ -672,7 +475,7 @@ end
|
|
672
475
|
end
|
673
476
|
|
674
477
|
it "should add foreign key with column" do
|
675
|
-
fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_post_id_fk").first(10)}"
|
478
|
+
fk_name = "fk_rails_#{OpenSSL::Digest::SHA256.hexdigest("test_comments_post_id_fk").first(10)}"
|
676
479
|
|
677
480
|
schema_define do
|
678
481
|
add_foreign_key :test_comments, :test_posts, column: "post_id"
|
@@ -737,11 +540,9 @@ end
|
|
737
540
|
add_foreign_key :test_comments, :test_posts
|
738
541
|
end
|
739
542
|
ActiveRecord::Base.connection.foreign_keys(:test_comments)
|
740
|
-
expect(@logger.logged(:debug).last).to match(/:owner/)
|
741
543
|
expect(@logger.logged(:debug).last).to match(/:desc_table_name/)
|
742
|
-
expect(@logger.logged(:debug).last).to match(/\[
|
544
|
+
expect(@logger.logged(:debug).last).to match(/\["desc_table_name", "TEST_COMMENTS"\]\]/)
|
743
545
|
end
|
744
|
-
|
745
546
|
end
|
746
547
|
|
747
548
|
describe "lob in table definition" do
|
@@ -930,7 +731,6 @@ end
|
|
930
731
|
TestComment.create(body: "test", test_post_id: 1)
|
931
732
|
end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
|
932
733
|
end
|
933
|
-
|
934
734
|
end
|
935
735
|
|
936
736
|
describe "disable referential integrity" do
|
@@ -977,18 +777,12 @@ end
|
|
977
777
|
@conn.execute "INSERT INTO test_comments (id, body, test_post_id) VALUES (3, 'test', 3)"
|
978
778
|
end.to raise_error(ActiveRecord::InvalidForeignKey)
|
979
779
|
end
|
980
|
-
|
981
780
|
end
|
982
781
|
|
983
782
|
describe "synonyms" do
|
984
783
|
before(:all) do
|
985
784
|
@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}'"
|
785
|
+
@username = CONNECTION_PARAMS[:username]
|
992
786
|
schema_define do
|
993
787
|
create_table :test_posts, force: true do |t|
|
994
788
|
t.string :title
|
@@ -1000,7 +794,6 @@ end
|
|
1000
794
|
schema_define do
|
1001
795
|
drop_table :test_posts
|
1002
796
|
end
|
1003
|
-
@conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
|
1004
797
|
end
|
1005
798
|
|
1006
799
|
before(:each) do
|
@@ -1028,18 +821,6 @@ end
|
|
1028
821
|
TestPost.create(title: "test")
|
1029
822
|
end.not_to raise_error
|
1030
823
|
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
824
|
end
|
1044
825
|
|
1045
826
|
describe "alter columns with column cache" do
|
@@ -1090,6 +871,15 @@ end
|
|
1090
871
|
expect(TestPost.columns_hash["body"]).not_to be_nil
|
1091
872
|
end
|
1092
873
|
|
874
|
+
it "should add longer column" do
|
875
|
+
skip unless @oracle12cr2_or_higher
|
876
|
+
schema_define do
|
877
|
+
add_column :test_posts, "a" * 128, :string
|
878
|
+
end
|
879
|
+
TestPost.reset_column_information
|
880
|
+
expect(TestPost.columns_hash["a" * 128]).not_to be_nil
|
881
|
+
end
|
882
|
+
|
1093
883
|
it "should add lob column with non_default tablespace" do
|
1094
884
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = DATABASE_NON_DEFAULT_TABLESPACE
|
1095
885
|
schema_define do
|
@@ -1295,20 +1085,50 @@ end
|
|
1295
1085
|
end
|
1296
1086
|
end
|
1297
1087
|
|
1088
|
+
describe "materialized views" do
|
1089
|
+
before(:all) do
|
1090
|
+
@conn = ActiveRecord::Base.connection
|
1091
|
+
schema_define do
|
1092
|
+
create_table :test_employees, force: true do |t|
|
1093
|
+
t.string :first_name
|
1094
|
+
t.string :last_name
|
1095
|
+
end
|
1096
|
+
end
|
1097
|
+
@conn.execute("create materialized view sum_test_employees as select first_name, count(*) from test_employees group by first_name")
|
1098
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
after(:all) do
|
1102
|
+
@conn.execute("drop materialized view sum_test_employees") rescue nil
|
1103
|
+
schema_define do
|
1104
|
+
drop_table :sum_test_employees, if_exists: true
|
1105
|
+
drop_table :test_employees, if_exists: true
|
1106
|
+
end
|
1107
|
+
end
|
1108
|
+
|
1109
|
+
it "tables should not return materialized views" do
|
1110
|
+
expect(@conn.tables).not_to include("sum_test_employees")
|
1111
|
+
end
|
1112
|
+
|
1113
|
+
it "materialized_views should return materialized views" do
|
1114
|
+
expect(@conn.materialized_views).to include("sum_test_employees")
|
1115
|
+
end
|
1116
|
+
end
|
1117
|
+
|
1298
1118
|
describe "miscellaneous options" do
|
1299
1119
|
before(:all) do
|
1300
1120
|
@conn = ActiveRecord::Base.connection
|
1301
1121
|
end
|
1302
1122
|
|
1303
1123
|
before(:each) do
|
1304
|
-
@conn.instance_variable_set :@would_execute_sql, @would_execute_sql = ""
|
1305
|
-
class
|
1124
|
+
@conn.instance_variable_set :@would_execute_sql, @would_execute_sql = +""
|
1125
|
+
class << @conn
|
1306
1126
|
def execute(sql, name = nil); @would_execute_sql << sql << ";\n"; end
|
1307
1127
|
end
|
1308
1128
|
end
|
1309
1129
|
|
1310
1130
|
after(:each) do
|
1311
|
-
class
|
1131
|
+
class << @conn
|
1312
1132
|
remove_method :execute
|
1313
1133
|
end
|
1314
1134
|
@conn.instance_eval { remove_instance_variable :@would_execute_sql }
|
@@ -1388,7 +1208,6 @@ end
|
|
1388
1208
|
end
|
1389
1209
|
expect(@would_execute_sql).not_to match(/ALTER +TABLE .* ADD CONSTRAINT .* UNIQUE \(.*\(.*\)\)/)
|
1390
1210
|
end
|
1391
|
-
|
1392
1211
|
end
|
1393
1212
|
|
1394
1213
|
describe "load schema" do
|