activerecord-oracle_enhanced-adapter 1.7.11 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +206 -4
- data/README.md +37 -1
- 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 +7 -59
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -50
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +11 -11
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -117
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +37 -27
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +10 -10
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +56 -71
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +0 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +51 -69
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +76 -76
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +14 -43
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -64
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -47
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +150 -160
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +95 -133
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +66 -101
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +290 -533
- data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -10
- data/lib/active_record/oracle_enhanced/type/integer.rb +3 -4
- data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
- data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -1
- data/lib/active_record/oracle_enhanced/type/raw.rb +2 -3
- data/lib/active_record/oracle_enhanced/type/string.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/text.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/timestamptz.rb +23 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +55 -162
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +32 -34
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +44 -42
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +250 -357
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -6
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -5
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +115 -124
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +68 -72
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +64 -80
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +223 -329
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +18 -20
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +59 -59
- data/spec/support/alter_system_user_password.sql +2 -0
- data/spec/support/create_oracle_enhanced_users.sql +31 -0
- metadata +25 -25
- data/.rspec +0 -2
- data/Gemfile +0 -22
- data/RUNNING_TESTS.md +0 -83
- data/Rakefile +0 -45
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -94
- data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -19
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe "OracleEnhancedAdapter schema definition" do
|
4
2
|
include SchemaSpecHelper
|
5
3
|
include LoggerSpecHelper
|
@@ -10,11 +8,11 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
10
8
|
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
|
11
9
|
end
|
12
10
|
|
13
|
-
describe
|
11
|
+
describe "option to create sequence when adding a column" do
|
14
12
|
before do
|
15
13
|
@conn = ActiveRecord::Base.connection
|
16
14
|
schema_define do
|
17
|
-
create_table :keyboards, :
|
15
|
+
create_table :keyboards, force: true, id: false do |t|
|
18
16
|
t.string :name
|
19
17
|
end
|
20
18
|
add_column :keyboards, :id, :primary_key
|
@@ -22,7 +20,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
22
20
|
class ::Keyboard < ActiveRecord::Base; end
|
23
21
|
end
|
24
22
|
|
25
|
-
it
|
23
|
+
it "creates a sequence when adding a column with create_sequence = true" do
|
26
24
|
_, sequence_name = ActiveRecord::Base.connection.pk_and_sequence_for_without_cache(:keyboards)
|
27
25
|
|
28
26
|
expect(sequence_name).to eq(Keyboard.sequence_name)
|
@@ -34,11 +32,11 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
34
32
|
before(:all) do
|
35
33
|
@conn = ActiveRecord::Base.connection
|
36
34
|
schema_define do
|
37
|
-
create_table :keyboards, :
|
35
|
+
create_table :keyboards, force: true, id: false do |t|
|
38
36
|
t.primary_key :key_number
|
39
37
|
t.string :name
|
40
38
|
end
|
41
|
-
create_table :id_keyboards, :
|
39
|
+
create_table :id_keyboards, force: true do |t|
|
42
40
|
t.string :name
|
43
41
|
end
|
44
42
|
end
|
@@ -56,7 +54,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
56
54
|
end
|
57
55
|
Object.send(:remove_const, "Keyboard")
|
58
56
|
Object.send(:remove_const, "IdKeyboard")
|
59
|
-
ActiveRecord::Base.clear_cache!
|
57
|
+
ActiveRecord::Base.clear_cache!
|
60
58
|
end
|
61
59
|
|
62
60
|
it "should create sequence for non-default primary key" do
|
@@ -72,7 +70,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
72
70
|
|
73
71
|
it "should return sequence name without truncating too much" do
|
74
72
|
seq_name_length = ActiveRecord::Base.connection.sequence_name_length
|
75
|
-
tname = "#{DATABASE_USER}" + "." + "a"*(seq_name_length - DATABASE_USER.length) + "z"*(DATABASE_USER).length
|
73
|
+
tname = "#{DATABASE_USER}" + "." + "a" * (seq_name_length - DATABASE_USER.length) + "z" * (DATABASE_USER).length
|
76
74
|
expect(ActiveRecord::Base.connection.default_sequence_name(tname)).to match (/z_seq$/)
|
77
75
|
end
|
78
76
|
end
|
@@ -81,7 +79,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
81
79
|
|
82
80
|
def create_test_employees_table(sequence_start_value = nil)
|
83
81
|
schema_define do
|
84
|
-
create_table :test_employees, sequence_start_value ? {:sequence_start_value
|
82
|
+
create_table :test_employees, sequence_start_value ? { sequence_start_value: sequence_start_value } : {} do |t|
|
85
83
|
t.string :first_name
|
86
84
|
t.string :last_name
|
87
85
|
end
|
@@ -110,7 +108,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
110
108
|
drop_table :test_employees
|
111
109
|
end
|
112
110
|
Object.send(:remove_const, "TestEmployee")
|
113
|
-
ActiveRecord::Base.clear_cache!
|
111
|
+
ActiveRecord::Base.clear_cache!
|
114
112
|
end
|
115
113
|
|
116
114
|
it "should use default sequence start value 10000" do
|
@@ -155,7 +153,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
155
153
|
|
156
154
|
describe "create table with primary key trigger" do
|
157
155
|
def create_table_with_trigger(options = {})
|
158
|
-
options.merge! :
|
156
|
+
options.merge! primary_key_trigger: true, force: true
|
159
157
|
schema_define do
|
160
158
|
create_table :test_employees, options do |t|
|
161
159
|
t.string :first_name
|
@@ -165,7 +163,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
165
163
|
end
|
166
164
|
|
167
165
|
def create_table_and_separately_trigger(options = {})
|
168
|
-
options.merge! :
|
166
|
+
options.merge! force: true
|
169
167
|
schema_define do
|
170
168
|
create_table :test_employees, options do |t|
|
171
169
|
t.string :first_name
|
@@ -178,11 +176,11 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
178
176
|
def drop_table_with_trigger(options = {})
|
179
177
|
seq_name = options[:sequence_name]
|
180
178
|
schema_define do
|
181
|
-
drop_table :test_employees, (seq_name ? {:
|
179
|
+
drop_table :test_employees, (seq_name ? { sequence_name: seq_name } : {})
|
182
180
|
end
|
183
181
|
Object.send(:remove_const, "TestEmployee")
|
184
182
|
@conn.clear_prefetch_primary_key
|
185
|
-
ActiveRecord::Base.clear_cache!
|
183
|
+
ActiveRecord::Base.clear_cache!
|
186
184
|
end
|
187
185
|
|
188
186
|
describe "with default primary key" do
|
@@ -209,14 +207,14 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
209
207
|
end
|
210
208
|
|
211
209
|
it "should create new record for model" do
|
212
|
-
e = TestEmployee.create!(:
|
210
|
+
e = TestEmployee.create!(first_name: "Raimonds")
|
213
211
|
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(e.id)
|
214
212
|
end
|
215
213
|
|
216
214
|
it "should not generate NoMethodError for :returning_id:Symbol" do
|
217
215
|
set_logger
|
218
216
|
@conn.reconnect! unless @conn.active?
|
219
|
-
|
217
|
+
@conn.insert("INSERT INTO test_employees (first_name) VALUES ('Yasuo')", nil, "id")
|
220
218
|
expect(@logger.output(:error)).not_to match(/^Could not log "sql.active_record" event. NoMethodError: undefined method `name' for :returning_id:Symbol/)
|
221
219
|
clear_logger
|
222
220
|
end
|
@@ -248,7 +246,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
248
246
|
end
|
249
247
|
|
250
248
|
it "should create new record for model" do
|
251
|
-
e = TestEmployee.create!(:
|
249
|
+
e = TestEmployee.create!(first_name: "Raimonds")
|
252
250
|
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(e.id)
|
253
251
|
end
|
254
252
|
end
|
@@ -259,14 +257,14 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
259
257
|
@conn = ActiveRecord::Base.connection
|
260
258
|
@primary_key = "employee_id"
|
261
259
|
@sequence_name = "test_employees_s"
|
262
|
-
create_table_with_trigger(:
|
260
|
+
create_table_with_trigger(primary_key: @primary_key, sequence_name: @sequence_name)
|
263
261
|
class ::TestEmployee < ActiveRecord::Base
|
264
262
|
self.primary_key = "employee_id"
|
265
263
|
end
|
266
264
|
end
|
267
265
|
|
268
266
|
after(:all) do
|
269
|
-
drop_table_with_trigger(:
|
267
|
+
drop_table_with_trigger(sequence_name: @sequence_name)
|
270
268
|
end
|
271
269
|
|
272
270
|
it "should populate primary key using trigger" do
|
@@ -281,7 +279,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
281
279
|
end
|
282
280
|
|
283
281
|
it "should create new record for model with autogenerated sequence option" do
|
284
|
-
e = TestEmployee.create!(:
|
282
|
+
e = TestEmployee.create!(first_name: "Raimonds")
|
285
283
|
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(e.id)
|
286
284
|
end
|
287
285
|
end
|
@@ -291,14 +289,14 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
291
289
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
292
290
|
@conn = ActiveRecord::Base.connection
|
293
291
|
@sequence_name = "test_employees_s"
|
294
|
-
create_table_with_trigger(:
|
292
|
+
create_table_with_trigger(sequence_name: @sequence_name, trigger_name: "test_employees_t1")
|
295
293
|
class ::TestEmployee < ActiveRecord::Base
|
296
294
|
self.sequence_name = :autogenerated
|
297
295
|
end
|
298
296
|
end
|
299
297
|
|
300
298
|
after(:all) do
|
301
|
-
drop_table_with_trigger(:
|
299
|
+
drop_table_with_trigger(sequence_name: @sequence_name)
|
302
300
|
end
|
303
301
|
|
304
302
|
it "should populate primary key using trigger" do
|
@@ -313,7 +311,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
313
311
|
end
|
314
312
|
|
315
313
|
it "should create new record for model with autogenerated sequence option" do
|
316
|
-
e = TestEmployee.create!(:
|
314
|
+
e = TestEmployee.create!(first_name: "Raimonds")
|
317
315
|
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(e.id)
|
318
316
|
end
|
319
317
|
end
|
@@ -322,11 +320,11 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
322
320
|
|
323
321
|
describe "table and column comments" do
|
324
322
|
|
325
|
-
def create_test_employees_table(table_comment=nil, column_comments={})
|
323
|
+
def create_test_employees_table(table_comment = nil, column_comments = {})
|
326
324
|
schema_define do
|
327
|
-
create_table :test_employees, :
|
328
|
-
t.string :first_name, :
|
329
|
-
t.string :last_name, :
|
325
|
+
create_table :test_employees, comment: table_comment do |t|
|
326
|
+
t.string :first_name, comment: column_comments[:first_name]
|
327
|
+
t.string :last_name, comment: column_comments[:last_name]
|
330
328
|
end
|
331
329
|
end
|
332
330
|
end
|
@@ -340,8 +338,8 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
340
338
|
drop_table :test_employees
|
341
339
|
end
|
342
340
|
Object.send(:remove_const, "TestEmployee")
|
343
|
-
ActiveRecord::Base.table_name_prefix =
|
344
|
-
ActiveRecord::Base.clear_cache!
|
341
|
+
ActiveRecord::Base.table_name_prefix = ""
|
342
|
+
ActiveRecord::Base.clear_cache!
|
345
343
|
end
|
346
344
|
|
347
345
|
it "should create table with table comment" do
|
@@ -350,39 +348,35 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
350
348
|
class ::TestEmployee < ActiveRecord::Base; end
|
351
349
|
|
352
350
|
expect(@conn.table_comment("test_employees")).to eq(table_comment)
|
353
|
-
expect(TestEmployee.table_comment).to eq(table_comment)
|
354
351
|
end
|
355
352
|
|
356
353
|
it "should create table with columns comment" do
|
357
|
-
column_comments = {:
|
354
|
+
column_comments = { first_name: "Given Name", last_name: "Surname" }
|
358
355
|
create_test_employees_table(nil, column_comments)
|
359
356
|
class ::TestEmployee < ActiveRecord::Base; end
|
360
357
|
|
361
358
|
[:first_name, :last_name].each do |attr|
|
362
359
|
expect(@conn.column_comment("test_employees", attr.to_s)).to eq(column_comments[attr])
|
363
360
|
end
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
# end
|
361
|
+
[:first_name, :last_name].each do |attr|
|
362
|
+
expect(TestEmployee.columns_hash[attr.to_s].comment).to eq(column_comments[attr])
|
363
|
+
end
|
368
364
|
end
|
369
365
|
|
370
366
|
it "should create table with table and columns comment and custom table name prefix" do
|
371
367
|
ActiveRecord::Base.table_name_prefix = "xxx_"
|
372
368
|
table_comment = "Test Employees"
|
373
|
-
column_comments = {:
|
369
|
+
column_comments = { first_name: "Given Name", last_name: "Surname" }
|
374
370
|
create_test_employees_table(table_comment, column_comments)
|
375
371
|
class ::TestEmployee < ActiveRecord::Base; end
|
376
372
|
|
377
373
|
expect(@conn.table_comment(TestEmployee.table_name)).to eq(table_comment)
|
378
|
-
expect(TestEmployee.table_comment).to eq(table_comment)
|
379
374
|
[:first_name, :last_name].each do |attr|
|
380
375
|
expect(@conn.column_comment(TestEmployee.table_name, attr.to_s)).to eq(column_comments[attr])
|
381
376
|
end
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
# end
|
377
|
+
[:first_name, :last_name].each do |attr|
|
378
|
+
expect(TestEmployee.columns_hash[attr.to_s].comment).to eq(column_comments[attr])
|
379
|
+
end
|
386
380
|
end
|
387
381
|
|
388
382
|
end
|
@@ -402,21 +396,21 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
402
396
|
describe "rename tables and sequences" do
|
403
397
|
before(:each) do
|
404
398
|
@conn = ActiveRecord::Base.connection
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
399
|
+
schema_define do
|
400
|
+
drop_table :test_employees rescue nil
|
401
|
+
drop_table :new_test_employees rescue nil
|
402
|
+
drop_table :test_employees_no_primary_key rescue nil
|
409
403
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
404
|
+
create_table :test_employees do |t|
|
405
|
+
t.string :first_name
|
406
|
+
t.string :last_name
|
407
|
+
end
|
414
408
|
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
end
|
409
|
+
create_table :test_employees_no_pkey, id: false do |t|
|
410
|
+
t.string :first_name
|
411
|
+
t.string :last_name
|
419
412
|
end
|
413
|
+
end
|
420
414
|
end
|
421
415
|
|
422
416
|
after(:each) do
|
@@ -431,25 +425,25 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
431
425
|
|
432
426
|
it "should rename table name with new one" do
|
433
427
|
expect do
|
434
|
-
@conn.rename_table("test_employees","new_test_employees")
|
428
|
+
@conn.rename_table("test_employees", "new_test_employees")
|
435
429
|
end.not_to raise_error
|
436
430
|
end
|
437
431
|
|
438
432
|
it "should raise error when new table name length is too long" do
|
439
433
|
expect do
|
440
|
-
@conn.rename_table("test_employees","a"*31)
|
434
|
+
@conn.rename_table("test_employees", "a" * 31)
|
441
435
|
end.to raise_error(ArgumentError)
|
442
436
|
end
|
443
437
|
|
444
438
|
it "should not raise error when new sequence name length is too long" do
|
445
439
|
expect do
|
446
|
-
@conn.rename_table("test_employees","a"*27)
|
440
|
+
@conn.rename_table("test_employees", "a" * 27)
|
447
441
|
end.not_to raise_error
|
448
442
|
end
|
449
443
|
|
450
444
|
it "should rename table when table has no primary key and sequence" do
|
451
445
|
expect do
|
452
|
-
@conn.rename_table("test_employees_no_pkey","new_test_employees_no_pkey")
|
446
|
+
@conn.rename_table("test_employees_no_pkey", "new_test_employees_no_pkey")
|
453
447
|
end.not_to raise_error
|
454
448
|
end
|
455
449
|
|
@@ -473,7 +467,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
473
467
|
drop_table :test_employees
|
474
468
|
end
|
475
469
|
Object.send(:remove_const, "TestEmployee")
|
476
|
-
ActiveRecord::Base.clear_cache!
|
470
|
+
ActiveRecord::Base.clear_cache!
|
477
471
|
end
|
478
472
|
|
479
473
|
it "should create table trigger with :new reference" do
|
@@ -499,69 +493,69 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
499
493
|
end
|
500
494
|
|
501
495
|
it "should return default index name if it is not larger than 30 characters" do
|
502
|
-
expect(@conn.index_name("employees", :
|
496
|
+
expect(@conn.index_name("employees", column: "first_name")).to eq("index_employees_on_first_name")
|
503
497
|
end
|
504
498
|
|
505
499
|
it "should return shortened index name by removing 'index', 'on' and 'and' keywords" do
|
506
|
-
expect(@conn.index_name("employees", :
|
500
|
+
expect(@conn.index_name("employees", column: ["first_name", "email"])).to eq("i_employees_first_name_email")
|
507
501
|
end
|
508
502
|
|
509
503
|
it "should return shortened index name by shortening table and column names" do
|
510
|
-
expect(@conn.index_name("employees", :
|
504
|
+
expect(@conn.index_name("employees", column: ["first_name", "last_name"])).to eq("i_emp_fir_nam_las_nam")
|
511
505
|
end
|
512
506
|
|
513
507
|
it "should raise error if too large index name cannot be shortened" do
|
514
|
-
expect(@conn.index_name("test_employees", :
|
515
|
-
|
508
|
+
expect(@conn.index_name("test_employees", column: ["first_name", "middle_name", "last_name"])).to eq(
|
509
|
+
"i" + Digest::SHA1.hexdigest("index_test_employees_on_first_name_and_middle_name_and_last_name")[0, 29]
|
516
510
|
)
|
517
511
|
end
|
518
512
|
|
519
513
|
end
|
520
514
|
|
521
515
|
describe "rename index" do
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
end
|
529
|
-
add_index :test_employees, :first_name
|
516
|
+
before(:each) do
|
517
|
+
@conn = ActiveRecord::Base.connection
|
518
|
+
schema_define do
|
519
|
+
create_table :test_employees do |t|
|
520
|
+
t.string :first_name
|
521
|
+
t.string :last_name
|
530
522
|
end
|
531
|
-
|
523
|
+
add_index :test_employees, :first_name
|
532
524
|
end
|
525
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
526
|
+
end
|
533
527
|
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
end
|
538
|
-
Object.send(:remove_const, "TestEmployee")
|
539
|
-
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
|
528
|
+
after(:each) do
|
529
|
+
schema_define do
|
530
|
+
drop_table :test_employees
|
540
531
|
end
|
532
|
+
Object.send(:remove_const, "TestEmployee")
|
533
|
+
ActiveRecord::Base.clear_cache!
|
534
|
+
end
|
541
535
|
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
536
|
+
it "should raise error when current index name and new index name are identical" do
|
537
|
+
expect do
|
538
|
+
@conn.rename_index("test_employees", "i_test_employees_first_name", "i_test_employees_first_name")
|
539
|
+
end.to raise_error(ActiveRecord::StatementInvalid)
|
540
|
+
end
|
547
541
|
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
542
|
+
it "should raise error when new index name length is too long" do
|
543
|
+
expect do
|
544
|
+
@conn.rename_index("test_employees", "i_test_employees_first_name", "a" * 31)
|
545
|
+
end.to raise_error(ArgumentError)
|
546
|
+
end
|
553
547
|
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
548
|
+
it "should raise error when current index name does not exist" do
|
549
|
+
expect do
|
550
|
+
@conn.rename_index("test_employees", "nonexist_index_name", "new_index_name")
|
551
|
+
end.to raise_error(ActiveRecord::StatementInvalid)
|
552
|
+
end
|
559
553
|
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
554
|
+
it "should rename index name with new one" do
|
555
|
+
expect do
|
556
|
+
@conn.rename_index("test_employees", "i_test_employees_first_name", "new_index_name")
|
557
|
+
end.not_to raise_error
|
558
|
+
end
|
565
559
|
end
|
566
560
|
|
567
561
|
describe "ignore options for LOB columns" do
|
@@ -574,8 +568,8 @@ end
|
|
574
568
|
it "should ignore :limit option for :text column" do
|
575
569
|
expect do
|
576
570
|
schema_define do
|
577
|
-
create_table :test_posts, :
|
578
|
-
t.text :body, :
|
571
|
+
create_table :test_posts, force: true do |t|
|
572
|
+
t.text :body, limit: 10000
|
579
573
|
end
|
580
574
|
end
|
581
575
|
end.not_to raise_error
|
@@ -584,8 +578,8 @@ end
|
|
584
578
|
it "should ignore :limit option for :binary column" do
|
585
579
|
expect do
|
586
580
|
schema_define do
|
587
|
-
create_table :test_posts, :
|
588
|
-
t.binary :picture, :
|
581
|
+
create_table :test_posts, force: true do |t|
|
582
|
+
t.binary :picture, limit: 10000
|
589
583
|
end
|
590
584
|
end
|
591
585
|
end.not_to raise_error
|
@@ -594,18 +588,18 @@ end
|
|
594
588
|
end
|
595
589
|
|
596
590
|
describe "foreign key constraints" do
|
597
|
-
let(:table_name_prefix) {
|
598
|
-
let(:table_name_suffix) {
|
591
|
+
let(:table_name_prefix) { "" }
|
592
|
+
let(:table_name_suffix) { "" }
|
599
593
|
|
600
594
|
before(:each) do
|
601
595
|
ActiveRecord::Base.table_name_prefix = table_name_prefix
|
602
596
|
ActiveRecord::Base.table_name_suffix = table_name_suffix
|
603
597
|
schema_define do
|
604
|
-
create_table :test_posts, :
|
598
|
+
create_table :test_posts, force: true do |t|
|
605
599
|
t.string :title
|
606
600
|
end
|
607
|
-
create_table :test_comments, :
|
608
|
-
t.string :body, :
|
601
|
+
create_table :test_comments, force: true do |t|
|
602
|
+
t.string :body, limit: 4000
|
609
603
|
t.references :test_post
|
610
604
|
t.integer :post_id
|
611
605
|
end
|
@@ -625,9 +619,9 @@ end
|
|
625
619
|
drop_table :test_comments rescue nil
|
626
620
|
drop_table :test_posts rescue nil
|
627
621
|
end
|
628
|
-
ActiveRecord::Base.table_name_prefix =
|
629
|
-
ActiveRecord::Base.table_name_suffix =
|
630
|
-
ActiveRecord::Base.clear_cache!
|
622
|
+
ActiveRecord::Base.table_name_prefix = ""
|
623
|
+
ActiveRecord::Base.table_name_suffix = ""
|
624
|
+
ActiveRecord::Base.clear_cache!
|
631
625
|
end
|
632
626
|
|
633
627
|
it "should add foreign key" do
|
@@ -637,98 +631,46 @@ end
|
|
637
631
|
add_foreign_key :test_comments, :test_posts
|
638
632
|
end
|
639
633
|
expect do
|
640
|
-
TestComment.create(:
|
641
|
-
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
|
642
|
-
end
|
643
|
-
|
644
|
-
context "with table_name_prefix" do
|
645
|
-
let(:table_name_prefix) { 'xxx_' }
|
646
|
-
|
647
|
-
it "should use table_name_prefix for foreign table" do
|
648
|
-
fk_name = "fk_rails_#{Digest::SHA256.hexdigest("xxx_test_comments_test_post_id_fk").first(10)}"
|
649
|
-
schema_define do
|
650
|
-
add_foreign_key :test_comments, :test_posts
|
651
|
-
end
|
652
|
-
|
653
|
-
expect do
|
654
|
-
TestComment.create(:body => "test", :test_post_id => 1)
|
655
|
-
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
|
656
|
-
end
|
657
|
-
end
|
658
|
-
|
659
|
-
context "with table_name_suffix" do
|
660
|
-
let(:table_name_suffix) { '_xxx' }
|
661
|
-
|
662
|
-
it "should use table_name_suffix for foreign table" do
|
663
|
-
fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_xxx_test_post_id_fk").first(10)}"
|
664
|
-
schema_define do
|
665
|
-
add_foreign_key :test_comments, :test_posts
|
666
|
-
end
|
667
|
-
|
668
|
-
expect do
|
669
|
-
TestComment.create(:body => "test", :test_post_id => 1)
|
670
|
-
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
|
671
|
-
end
|
634
|
+
TestComment.create(body: "test", test_post_id: 1)
|
635
|
+
end.to raise_error() { |e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i) }
|
672
636
|
end
|
673
637
|
|
674
638
|
it "should add foreign key with name" do
|
675
639
|
schema_define do
|
676
|
-
add_foreign_key :test_comments, :test_posts, :
|
677
|
-
end
|
678
|
-
expect do
|
679
|
-
TestComment.create(:body => "test", :test_post_id => 1)
|
680
|
-
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.COMMENTS_POSTS_FK/)}
|
681
|
-
end
|
682
|
-
|
683
|
-
it "should add foreign key with long name which is shortened" do
|
684
|
-
schema_define do
|
685
|
-
add_foreign_key :test_comments, :test_posts, :name => "test_comments_test_post_id_foreign_key"
|
640
|
+
add_foreign_key :test_comments, :test_posts, name: "comments_posts_fk"
|
686
641
|
end
|
687
642
|
expect do
|
688
|
-
TestComment.create(:
|
689
|
-
end.to raise_error() {|e| expect(e.message).to match(
|
690
|
-
/ORA-02291.*\.C#{Digest::SHA1.hexdigest("test_comments_test_post_id_foreign_key")[0,29].upcase}/
|
691
|
-
)}
|
692
|
-
end
|
693
|
-
|
694
|
-
it "should add foreign key with very long name which is shortened" do
|
695
|
-
schema_define do
|
696
|
-
add_foreign_key :test_comments, :test_posts, :name => "long_prefix_test_comments_test_post_id_foreign_key"
|
697
|
-
end
|
698
|
-
expect do
|
699
|
-
TestComment.create(:body => "test", :test_post_id => 1)
|
700
|
-
end.to raise_error() {|e| expect(e.message).to match(
|
701
|
-
/ORA-02291.*\.C#{Digest::SHA1.hexdigest("long_prefix_test_comments_test_post_id_foreign_key")[0,29].upcase}/
|
702
|
-
)}
|
643
|
+
TestComment.create(body: "test", test_post_id: 1)
|
644
|
+
end.to raise_error() { |e| expect(e.message).to match(/ORA-02291.*\.COMMENTS_POSTS_FK/) }
|
703
645
|
end
|
704
646
|
|
705
647
|
it "should add foreign key with column" do
|
706
648
|
fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_post_id_fk").first(10)}"
|
707
649
|
|
708
650
|
schema_define do
|
709
|
-
add_foreign_key :test_comments, :test_posts, :
|
651
|
+
add_foreign_key :test_comments, :test_posts, column: "post_id"
|
710
652
|
end
|
711
653
|
expect do
|
712
|
-
TestComment.create(:
|
713
|
-
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
|
654
|
+
TestComment.create(body: "test", post_id: 1)
|
655
|
+
end.to raise_error() { |e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i) }
|
714
656
|
end
|
715
657
|
|
716
658
|
it "should add foreign key with delete dependency" do
|
717
659
|
schema_define do
|
718
|
-
add_foreign_key :test_comments, :test_posts, :
|
660
|
+
add_foreign_key :test_comments, :test_posts, on_delete: :cascade
|
719
661
|
end
|
720
|
-
p = TestPost.create(:
|
721
|
-
c = TestComment.create(:
|
662
|
+
p = TestPost.create(title: "test")
|
663
|
+
c = TestComment.create(body: "test", test_post: p)
|
722
664
|
TestPost.delete(p.id)
|
723
665
|
expect(TestComment.find_by_id(c.id)).to be_nil
|
724
666
|
end
|
725
667
|
|
726
668
|
it "should add foreign key with nullify dependency" do
|
727
669
|
schema_define do
|
728
|
-
add_foreign_key :test_comments, :test_posts, :
|
670
|
+
add_foreign_key :test_comments, :test_posts, on_delete: :nullify
|
729
671
|
end
|
730
|
-
p = TestPost.create(:
|
731
|
-
c = TestComment.create(:
|
672
|
+
p = TestPost.create(title: "test")
|
673
|
+
c = TestComment.create(body: "test", test_post: p)
|
732
674
|
TestPost.delete(p.id)
|
733
675
|
expect(TestComment.find_by_id(c.id).test_post_id).to be_nil
|
734
676
|
end
|
@@ -739,27 +681,27 @@ end
|
|
739
681
|
remove_foreign_key :test_comments, :test_posts
|
740
682
|
end
|
741
683
|
expect do
|
742
|
-
TestComment.create(:
|
684
|
+
TestComment.create(body: "test", test_post_id: 1)
|
743
685
|
end.not_to raise_error
|
744
686
|
end
|
745
687
|
|
746
688
|
it "should remove foreign key by constraint name" do
|
747
689
|
schema_define do
|
748
|
-
add_foreign_key :test_comments, :test_posts, :
|
749
|
-
remove_foreign_key :test_comments, :
|
690
|
+
add_foreign_key :test_comments, :test_posts, name: "comments_posts_fk"
|
691
|
+
remove_foreign_key :test_comments, name: "comments_posts_fk"
|
750
692
|
end
|
751
693
|
expect do
|
752
|
-
TestComment.create(:
|
694
|
+
TestComment.create(body: "test", test_post_id: 1)
|
753
695
|
end.not_to raise_error
|
754
696
|
end
|
755
697
|
|
756
698
|
it "should remove foreign key by column name" do
|
757
699
|
schema_define do
|
758
700
|
add_foreign_key :test_comments, :test_posts
|
759
|
-
remove_foreign_key :test_comments, :
|
701
|
+
remove_foreign_key :test_comments, column: "test_post_id"
|
760
702
|
end
|
761
703
|
expect do
|
762
|
-
TestComment.create(:
|
704
|
+
TestComment.create(body: "test", test_post_id: 1)
|
763
705
|
end.not_to raise_error
|
764
706
|
end
|
765
707
|
|
@@ -770,11 +712,11 @@ end
|
|
770
712
|
class ::TestPost < ActiveRecord::Base
|
771
713
|
end
|
772
714
|
end
|
773
|
-
it
|
715
|
+
it "should use default tablespace for clobs" do
|
774
716
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = DATABASE_NON_DEFAULT_TABLESPACE
|
775
717
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = nil
|
776
718
|
schema_define do
|
777
|
-
create_table :test_posts, :
|
719
|
+
create_table :test_posts, force: true do |t|
|
778
720
|
t.text :test_clob
|
779
721
|
t.binary :test_blob
|
780
722
|
end
|
@@ -783,11 +725,11 @@ end
|
|
783
725
|
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_BLOB'")).not_to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
784
726
|
end
|
785
727
|
|
786
|
-
it
|
728
|
+
it "should use default tablespace for blobs" do
|
787
729
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = DATABASE_NON_DEFAULT_TABLESPACE
|
788
730
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = nil
|
789
731
|
schema_define do
|
790
|
-
create_table :test_posts, :
|
732
|
+
create_table :test_posts, force: true do |t|
|
791
733
|
t.text :test_clob
|
792
734
|
t.binary :test_blob
|
793
735
|
end
|
@@ -812,10 +754,10 @@ end
|
|
812
754
|
end
|
813
755
|
end
|
814
756
|
|
815
|
-
it
|
757
|
+
it "should use default tablespace for primary key" do
|
816
758
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = nil
|
817
759
|
schema_define do
|
818
|
-
create_table :test_posts, :
|
760
|
+
create_table :test_posts, force: true
|
819
761
|
end
|
820
762
|
|
821
763
|
index_name = @conn.select_value(
|
@@ -824,13 +766,13 @@ end
|
|
824
766
|
AND constraint_type = 'P'
|
825
767
|
AND owner = SYS_CONTEXT('userenv', 'current_schema')")
|
826
768
|
|
827
|
-
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_indexes WHERE index_name = '#{index_name}'")).to eq(
|
769
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_indexes WHERE index_name = '#{index_name}'")).to eq("USERS")
|
828
770
|
end
|
829
771
|
|
830
|
-
it
|
772
|
+
it "should use non default tablespace for primary key" do
|
831
773
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = DATABASE_NON_DEFAULT_TABLESPACE
|
832
774
|
schema_define do
|
833
|
-
create_table :test_posts, :
|
775
|
+
create_table :test_posts, force: true
|
834
776
|
end
|
835
777
|
|
836
778
|
index_name = @conn.select_value(
|
@@ -854,7 +796,7 @@ end
|
|
854
796
|
describe "foreign key in table definition" do
|
855
797
|
before(:each) do
|
856
798
|
schema_define do
|
857
|
-
create_table :test_posts, :
|
799
|
+
create_table :test_posts, force: true do |t|
|
858
800
|
t.string :title
|
859
801
|
end
|
860
802
|
end
|
@@ -873,38 +815,38 @@ end
|
|
873
815
|
drop_table :test_comments rescue nil
|
874
816
|
drop_table :test_posts rescue nil
|
875
817
|
end
|
876
|
-
ActiveRecord::Base.clear_cache!
|
818
|
+
ActiveRecord::Base.clear_cache!
|
877
819
|
end
|
878
820
|
|
879
821
|
it "should add foreign key in create_table" do
|
880
822
|
schema_define do
|
881
|
-
create_table :test_comments, :
|
882
|
-
t.string :body, :
|
823
|
+
create_table :test_comments, force: true do |t|
|
824
|
+
t.string :body, limit: 4000
|
883
825
|
t.references :test_post
|
884
826
|
t.foreign_key :test_posts
|
885
827
|
end
|
886
828
|
end
|
887
829
|
expect do
|
888
|
-
TestComment.create(:
|
889
|
-
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
|
830
|
+
TestComment.create(body: "test", test_post_id: 1)
|
831
|
+
end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
|
890
832
|
end
|
891
833
|
|
892
834
|
it "should add foreign key in create_table references" do
|
893
835
|
schema_define do
|
894
|
-
create_table :test_comments, :
|
895
|
-
t.string :body, :
|
896
|
-
t.references :test_post, :
|
836
|
+
create_table :test_comments, force: true do |t|
|
837
|
+
t.string :body, limit: 4000
|
838
|
+
t.references :test_post, foreign_key: true
|
897
839
|
end
|
898
840
|
end
|
899
841
|
expect do
|
900
|
-
TestComment.create(:
|
901
|
-
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
|
842
|
+
TestComment.create(body: "test", test_post_id: 1)
|
843
|
+
end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
|
902
844
|
end
|
903
845
|
|
904
846
|
it "should add foreign key in change_table" do
|
905
847
|
schema_define do
|
906
|
-
create_table :test_comments, :
|
907
|
-
t.string :body, :
|
848
|
+
create_table :test_comments, force: true do |t|
|
849
|
+
t.string :body, limit: 4000
|
908
850
|
t.references :test_post
|
909
851
|
end
|
910
852
|
change_table :test_comments do |t|
|
@@ -912,40 +854,22 @@ end
|
|
912
854
|
end
|
913
855
|
end
|
914
856
|
expect do
|
915
|
-
TestComment.create(:
|
916
|
-
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
|
857
|
+
TestComment.create(body: "test", test_post_id: 1)
|
858
|
+
end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
|
917
859
|
end
|
918
860
|
|
919
861
|
it "should add foreign key in change_table references" do
|
920
862
|
schema_define do
|
921
|
-
create_table :test_comments, :
|
922
|
-
t.string :body, :
|
923
|
-
end
|
924
|
-
change_table :test_comments do |t|
|
925
|
-
t.references :test_post, :foreign_key => true
|
926
|
-
end
|
927
|
-
end
|
928
|
-
expect do
|
929
|
-
TestComment.create(:body => "test", :test_post_id => 1)
|
930
|
-
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
|
931
|
-
end
|
932
|
-
|
933
|
-
it "should remove foreign key by table name" do
|
934
|
-
schema_define do
|
935
|
-
create_table :test_comments, :force => true do |t|
|
936
|
-
t.string :body, :limit => 4000
|
937
|
-
t.references :test_post
|
863
|
+
create_table :test_comments, force: true do |t|
|
864
|
+
t.string :body, limit: 4000
|
938
865
|
end
|
939
866
|
change_table :test_comments do |t|
|
940
|
-
t.foreign_key
|
941
|
-
end
|
942
|
-
change_table :test_comments do |t|
|
943
|
-
t.remove_foreign_key :test_posts
|
867
|
+
t.references :test_post, foreign_key: true
|
944
868
|
end
|
945
869
|
end
|
946
870
|
expect do
|
947
|
-
TestComment.create(:
|
948
|
-
end.
|
871
|
+
TestComment.create(body: "test", test_post_id: 1)
|
872
|
+
end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
|
949
873
|
end
|
950
874
|
|
951
875
|
end
|
@@ -957,16 +881,16 @@ end
|
|
957
881
|
|
958
882
|
before(:each) do
|
959
883
|
schema_define do
|
960
|
-
create_table :test_posts, :
|
884
|
+
create_table :test_posts, force: true do |t|
|
961
885
|
t.string :title
|
962
886
|
end
|
963
|
-
create_table :test_comments, :
|
964
|
-
t.string :body, :
|
965
|
-
t.references :test_post, :
|
887
|
+
create_table :test_comments, force: true do |t|
|
888
|
+
t.string :body, limit: 4000
|
889
|
+
t.references :test_post, foreign_key: true
|
966
890
|
end
|
967
|
-
create_table "test_Mixed_Comments", :
|
968
|
-
t.string :body, :
|
969
|
-
t.references :test_post, :
|
891
|
+
create_table "test_Mixed_Comments", force: true do |t|
|
892
|
+
t.string :body, limit: 4000
|
893
|
+
t.references :test_post, foreign_key: true
|
970
894
|
end
|
971
895
|
end
|
972
896
|
end
|
@@ -1007,7 +931,7 @@ end
|
|
1007
931
|
@conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
|
1008
932
|
@conn.execute "CREATE DATABASE LINK #{@db_link} CONNECT TO #{@db_link_username} IDENTIFIED BY \"#{@db_link_password}\" USING '#{@db_link_database}'"
|
1009
933
|
schema_define do
|
1010
|
-
create_table :test_posts, :
|
934
|
+
create_table :test_posts, force: true do |t|
|
1011
935
|
t.string :title
|
1012
936
|
end
|
1013
937
|
end
|
@@ -1032,28 +956,28 @@ end
|
|
1032
956
|
remove_synonym :synonym_to_posts
|
1033
957
|
remove_synonym :synonym_to_posts_seq
|
1034
958
|
end
|
1035
|
-
ActiveRecord::Base.clear_cache!
|
959
|
+
ActiveRecord::Base.clear_cache!
|
1036
960
|
end
|
1037
961
|
|
1038
962
|
it "should create synonym to table and sequence" do
|
1039
963
|
schema_name = @username
|
1040
964
|
schema_define do
|
1041
|
-
add_synonym :synonym_to_posts, "#{schema_name}.test_posts", :
|
1042
|
-
add_synonym :synonym_to_posts_seq, "#{schema_name}.test_posts_seq", :
|
965
|
+
add_synonym :synonym_to_posts, "#{schema_name}.test_posts", force: true
|
966
|
+
add_synonym :synonym_to_posts_seq, "#{schema_name}.test_posts_seq", force: true
|
1043
967
|
end
|
1044
968
|
expect do
|
1045
|
-
TestPost.create(:
|
969
|
+
TestPost.create(title: "test")
|
1046
970
|
end.not_to raise_error
|
1047
971
|
end
|
1048
972
|
|
1049
973
|
it "should create synonym to table over database link" do
|
1050
974
|
db_link = @db_link
|
1051
975
|
schema_define do
|
1052
|
-
add_synonym :synonym_to_posts, "test_posts@#{db_link}", :
|
1053
|
-
add_synonym :synonym_to_posts_seq, "test_posts_seq@#{db_link}", :
|
976
|
+
add_synonym :synonym_to_posts, "test_posts@#{db_link}", force: true
|
977
|
+
add_synonym :synonym_to_posts_seq, "test_posts_seq@#{db_link}", force: true
|
1054
978
|
end
|
1055
979
|
expect do
|
1056
|
-
TestPost.create(:
|
980
|
+
TestPost.create(title: "test")
|
1057
981
|
end.not_to raise_error
|
1058
982
|
end
|
1059
983
|
|
@@ -1076,27 +1000,27 @@ end
|
|
1076
1000
|
|
1077
1001
|
before(:each) do
|
1078
1002
|
schema_define do
|
1079
|
-
create_table :test_posts, :
|
1080
|
-
t.string :title, :
|
1003
|
+
create_table :test_posts, force: true do |t|
|
1004
|
+
t.string :title, null: false
|
1081
1005
|
t.string :content
|
1082
1006
|
end
|
1083
1007
|
end
|
1084
1008
|
class ::TestPost < ActiveRecord::Base; end
|
1085
|
-
expect(TestPost.columns_hash[
|
1009
|
+
expect(TestPost.columns_hash["title"].null).to be_falsey
|
1086
1010
|
end
|
1087
1011
|
|
1088
1012
|
after(:each) do
|
1089
1013
|
Object.send(:remove_const, "TestPost")
|
1090
1014
|
schema_define { drop_table :test_posts }
|
1091
|
-
ActiveRecord::Base.clear_cache!
|
1015
|
+
ActiveRecord::Base.clear_cache!
|
1092
1016
|
end
|
1093
1017
|
|
1094
1018
|
it "should change column to nullable" do
|
1095
1019
|
schema_define do
|
1096
|
-
change_column :test_posts, :title, :string, :
|
1020
|
+
change_column :test_posts, :title, :string, null: true
|
1097
1021
|
end
|
1098
1022
|
TestPost.reset_column_information
|
1099
|
-
expect(TestPost.columns_hash[
|
1023
|
+
expect(TestPost.columns_hash["title"].null).to be_truthy
|
1100
1024
|
end
|
1101
1025
|
|
1102
1026
|
it "should add column" do
|
@@ -1104,7 +1028,7 @@ end
|
|
1104
1028
|
add_column :test_posts, :body, :string
|
1105
1029
|
end
|
1106
1030
|
TestPost.reset_column_information
|
1107
|
-
expect(TestPost.columns_hash[
|
1031
|
+
expect(TestPost.columns_hash["body"]).not_to be_nil
|
1108
1032
|
end
|
1109
1033
|
|
1110
1034
|
it "should add lob column with non_default tablespace" do
|
@@ -1128,8 +1052,8 @@ end
|
|
1128
1052
|
rename_column :test_posts, :title, :subject
|
1129
1053
|
end
|
1130
1054
|
TestPost.reset_column_information
|
1131
|
-
expect(TestPost.columns_hash[
|
1132
|
-
expect(TestPost.columns_hash[
|
1055
|
+
expect(TestPost.columns_hash["subject"]).not_to be_nil
|
1056
|
+
expect(TestPost.columns_hash["title"]).to be_nil
|
1133
1057
|
end
|
1134
1058
|
|
1135
1059
|
it "should remove column" do
|
@@ -1137,7 +1061,7 @@ end
|
|
1137
1061
|
remove_column :test_posts, :title
|
1138
1062
|
end
|
1139
1063
|
TestPost.reset_column_information
|
1140
|
-
expect(TestPost.columns_hash[
|
1064
|
+
expect(TestPost.columns_hash["title"]).to be_nil
|
1141
1065
|
end
|
1142
1066
|
|
1143
1067
|
it "should remove column when using change_table" do
|
@@ -1147,7 +1071,7 @@ end
|
|
1147
1071
|
end
|
1148
1072
|
end
|
1149
1073
|
TestPost.reset_column_information
|
1150
|
-
expect(TestPost.columns_hash[
|
1074
|
+
expect(TestPost.columns_hash["title"]).to be_nil
|
1151
1075
|
end
|
1152
1076
|
|
1153
1077
|
it "should remove multiple columns when using change_table" do
|
@@ -1157,8 +1081,8 @@ end
|
|
1157
1081
|
end
|
1158
1082
|
end
|
1159
1083
|
TestPost.reset_column_information
|
1160
|
-
expect(TestPost.columns_hash[
|
1161
|
-
expect(TestPost.columns_hash[
|
1084
|
+
expect(TestPost.columns_hash["title"]).to be_nil
|
1085
|
+
expect(TestPost.columns_hash["content"]).to be_nil
|
1162
1086
|
end
|
1163
1087
|
|
1164
1088
|
it "should ignore type and options parameter and remove column" do
|
@@ -1166,45 +1090,16 @@ end
|
|
1166
1090
|
remove_column :test_posts, :title, :string, {}
|
1167
1091
|
end
|
1168
1092
|
TestPost.reset_column_information
|
1169
|
-
expect(TestPost.columns_hash[
|
1093
|
+
expect(TestPost.columns_hash["title"]).to be_nil
|
1170
1094
|
end
|
1171
1095
|
end
|
1172
1096
|
|
1173
|
-
describe
|
1097
|
+
describe "virtual columns in create_table" do
|
1174
1098
|
before(:each) do
|
1175
1099
|
skip "Not supported in this database version" unless @oracle11g_or_higher
|
1176
1100
|
end
|
1177
1101
|
|
1178
|
-
it
|
1179
|
-
schema_define do
|
1180
|
-
create_table :test_fractions, :force => true do |t|
|
1181
|
-
t.integer :field1
|
1182
|
-
t.virtual :field2, :default => 'field1 + 1'
|
1183
|
-
end
|
1184
|
-
end
|
1185
|
-
class ::TestFraction < ActiveRecord::Base
|
1186
|
-
self.table_name = "test_fractions"
|
1187
|
-
end
|
1188
|
-
|
1189
|
-
TestFraction.reset_column_information
|
1190
|
-
tf = TestFraction.columns.detect { |c| c.virtual? }
|
1191
|
-
expect(tf).not_to be nil
|
1192
|
-
expect(tf.name).to eq("field2")
|
1193
|
-
expect(tf.virtual?).to be true
|
1194
|
-
expect do
|
1195
|
-
tf = TestFraction.new(:field1=>10)
|
1196
|
-
expect(tf.field2).to be nil # not whatever is in DATA_DEFAULT column
|
1197
|
-
tf.save!
|
1198
|
-
tf.reload
|
1199
|
-
end.not_to raise_error
|
1200
|
-
expect(tf.field2.to_i).to eq(11)
|
1201
|
-
|
1202
|
-
schema_define do
|
1203
|
-
drop_table :test_fractions
|
1204
|
-
end
|
1205
|
-
end
|
1206
|
-
|
1207
|
-
it 'should raise error if column expression is not provided' do
|
1102
|
+
it "should raise error if column expression is not provided" do
|
1208
1103
|
expect {
|
1209
1104
|
schema_define do
|
1210
1105
|
create_table :test_fractions do |t|
|
@@ -1212,19 +1107,19 @@ end
|
|
1212
1107
|
t.virtual :field2
|
1213
1108
|
end
|
1214
1109
|
end
|
1215
|
-
}.to raise_error
|
1110
|
+
}.to raise_error(RuntimeError, "No virtual column definition found.")
|
1216
1111
|
end
|
1217
1112
|
end
|
1218
1113
|
|
1219
|
-
describe
|
1114
|
+
describe "virtual columns" do
|
1220
1115
|
before(:each) do
|
1221
1116
|
skip "Not supported in this database version" unless @oracle11g_or_higher
|
1222
1117
|
expr = "( numerator/NULLIF(denominator,0) )*100"
|
1223
1118
|
schema_define do
|
1224
|
-
create_table :test_fractions, :
|
1225
|
-
t.integer :numerator, :
|
1226
|
-
t.integer :denominator, :
|
1227
|
-
t.virtual :percent, :
|
1119
|
+
create_table :test_fractions, force: true do |t|
|
1120
|
+
t.integer :numerator, default: 0
|
1121
|
+
t.integer :denominator, default: 0
|
1122
|
+
t.virtual :percent, as: expr
|
1228
1123
|
end
|
1229
1124
|
end
|
1230
1125
|
class ::TestFraction < ActiveRecord::Base
|
@@ -1241,13 +1136,13 @@ end
|
|
1241
1136
|
end
|
1242
1137
|
end
|
1243
1138
|
|
1244
|
-
it
|
1139
|
+
it "should include virtual columns and not try to update them" do
|
1245
1140
|
tf = TestFraction.columns.detect { |c| c.virtual? }
|
1246
1141
|
expect(tf).not_to be nil
|
1247
1142
|
expect(tf.name).to eq("percent")
|
1248
1143
|
expect(tf.virtual?).to be true
|
1249
1144
|
expect do
|
1250
|
-
tf = TestFraction.new(:
|
1145
|
+
tf = TestFraction.new(numerator: 20, denominator: 100)
|
1251
1146
|
expect(tf.percent).to be nil # not whatever is in DATA_DEFAULT column
|
1252
1147
|
tf.save!
|
1253
1148
|
tf.reload
|
@@ -1255,16 +1150,16 @@ end
|
|
1255
1150
|
expect(tf.percent.to_i).to eq(20)
|
1256
1151
|
end
|
1257
1152
|
|
1258
|
-
it
|
1153
|
+
it "should add virtual column" do
|
1259
1154
|
schema_define do
|
1260
|
-
add_column :test_fractions, :rem, :virtual, :
|
1155
|
+
add_column :test_fractions, :rem, :virtual, as: "remainder(numerator, NULLIF(denominator,0))"
|
1261
1156
|
end
|
1262
1157
|
TestFraction.reset_column_information
|
1263
|
-
tf = TestFraction.columns.detect { |c| c.name ==
|
1158
|
+
tf = TestFraction.columns.detect { |c| c.name == "rem" }
|
1264
1159
|
expect(tf).not_to be nil
|
1265
1160
|
expect(tf.virtual?).to be true
|
1266
1161
|
expect do
|
1267
|
-
tf = TestFraction.new(:
|
1162
|
+
tf = TestFraction.new(numerator: 7, denominator: 5)
|
1268
1163
|
expect(tf.rem).to be nil
|
1269
1164
|
tf.save!
|
1270
1165
|
tf.reload
|
@@ -1272,64 +1167,64 @@ end
|
|
1272
1167
|
expect(tf.rem.to_i).to eq(2)
|
1273
1168
|
end
|
1274
1169
|
|
1275
|
-
it
|
1170
|
+
it "should add virtual column with explicit type" do
|
1276
1171
|
schema_define do
|
1277
|
-
add_column :test_fractions, :expression, :virtual, :
|
1172
|
+
add_column :test_fractions, :expression, :virtual, as: "TO_CHAR(numerator) || '/' || TO_CHAR(denominator)", type: :string, limit: 100
|
1278
1173
|
end
|
1279
1174
|
TestFraction.reset_column_information
|
1280
|
-
tf = TestFraction.columns.detect { |c| c.name ==
|
1175
|
+
tf = TestFraction.columns.detect { |c| c.name == "expression" }
|
1281
1176
|
expect(tf).not_to be nil
|
1282
1177
|
expect(tf.virtual?).to be true
|
1283
1178
|
expect(tf.type).to be :string
|
1284
1179
|
expect(tf.limit).to be 100
|
1285
1180
|
expect do
|
1286
|
-
tf = TestFraction.new(:
|
1181
|
+
tf = TestFraction.new(numerator: 7, denominator: 5)
|
1287
1182
|
expect(tf.expression).to be nil
|
1288
1183
|
tf.save!
|
1289
1184
|
tf.reload
|
1290
1185
|
end.not_to raise_error
|
1291
|
-
expect(tf.expression).to eq(
|
1186
|
+
expect(tf.expression).to eq("7/5")
|
1292
1187
|
end
|
1293
1188
|
|
1294
|
-
it
|
1189
|
+
it "should change virtual column definition" do
|
1295
1190
|
schema_define do
|
1296
1191
|
change_column :test_fractions, :percent, :virtual,
|
1297
|
-
:
|
1192
|
+
as: "ROUND((numerator/NULLIF(denominator,0))*100, 2)", type: :decimal, precision: 15, scale: 2
|
1298
1193
|
end
|
1299
1194
|
TestFraction.reset_column_information
|
1300
|
-
tf = TestFraction.columns.detect { |c| c.name ==
|
1195
|
+
tf = TestFraction.columns.detect { |c| c.name == "percent" }
|
1301
1196
|
expect(tf).not_to be nil
|
1302
1197
|
expect(tf.virtual?).to be true
|
1303
1198
|
expect(tf.type).to be :decimal
|
1304
1199
|
expect(tf.precision).to be 15
|
1305
1200
|
expect(tf.scale).to be 2
|
1306
1201
|
expect do
|
1307
|
-
tf = TestFraction.new(:
|
1202
|
+
tf = TestFraction.new(numerator: 11, denominator: 17)
|
1308
1203
|
expect(tf.percent).to be nil
|
1309
1204
|
tf.save!
|
1310
1205
|
tf.reload
|
1311
1206
|
end.not_to raise_error
|
1312
|
-
expect(tf.percent).to eq(
|
1207
|
+
expect(tf.percent).to eq("64.71".to_d)
|
1313
1208
|
end
|
1314
1209
|
|
1315
|
-
it
|
1210
|
+
it "should change virtual column type" do
|
1316
1211
|
schema_define do
|
1317
|
-
change_column :test_fractions, :percent, :virtual, :
|
1212
|
+
change_column :test_fractions, :percent, :virtual, type: :decimal, precision: 12, scale: 5
|
1318
1213
|
end
|
1319
1214
|
TestFraction.reset_column_information
|
1320
|
-
tf = TestFraction.columns.detect { |c| c.name ==
|
1215
|
+
tf = TestFraction.columns.detect { |c| c.name == "percent" }
|
1321
1216
|
expect(tf).not_to be nil
|
1322
1217
|
expect(tf.virtual?).to be true
|
1323
1218
|
expect(tf.type).to be :decimal
|
1324
1219
|
expect(tf.precision).to be 12
|
1325
1220
|
expect(tf.scale).to be 5
|
1326
1221
|
expect do
|
1327
|
-
tf = TestFraction.new(:
|
1222
|
+
tf = TestFraction.new(numerator: 11, denominator: 17)
|
1328
1223
|
expect(tf.percent).to be nil
|
1329
1224
|
tf.save!
|
1330
1225
|
tf.reload
|
1331
1226
|
end.not_to raise_error
|
1332
|
-
expect(tf.percent).to eq(
|
1227
|
+
expect(tf.percent).to eq("64.70588".to_d)
|
1333
1228
|
end
|
1334
1229
|
end
|
1335
1230
|
|
@@ -1339,10 +1234,9 @@ end
|
|
1339
1234
|
end
|
1340
1235
|
|
1341
1236
|
before(:each) do
|
1342
|
-
@conn.instance_variable_set :@would_execute_sql, @would_execute_sql=
|
1237
|
+
@conn.instance_variable_set :@would_execute_sql, @would_execute_sql = ""
|
1343
1238
|
class <<@conn
|
1344
|
-
def execute(sql,name=nil); @would_execute_sql << sql << ";\n"; end
|
1345
|
-
def index_name_exists?(table_name, index_name, default); default; end
|
1239
|
+
def execute(sql, name = nil); @would_execute_sql << sql << ";\n"; end
|
1346
1240
|
end
|
1347
1241
|
end
|
1348
1242
|
|
@@ -1350,13 +1244,13 @@ end
|
|
1350
1244
|
class <<@conn
|
1351
1245
|
remove_method :execute
|
1352
1246
|
end
|
1353
|
-
@conn.instance_eval{ remove_instance_variable :@would_execute_sql }
|
1247
|
+
@conn.instance_eval { remove_instance_variable :@would_execute_sql }
|
1354
1248
|
end
|
1355
1249
|
|
1356
1250
|
it "should support the :options option to create_table" do
|
1357
1251
|
schema_define do
|
1358
|
-
create_table :test_posts, :
|
1359
|
-
t.string :title, :
|
1252
|
+
create_table :test_posts, options: "NOLOGGING", force: true do |t|
|
1253
|
+
t.string :title, null: false
|
1360
1254
|
end
|
1361
1255
|
end
|
1362
1256
|
expect(@would_execute_sql).to match(/CREATE +TABLE .* \(.*\) NOLOGGING/)
|
@@ -1364,8 +1258,8 @@ end
|
|
1364
1258
|
|
1365
1259
|
it "should support the :tablespace option to create_table" do
|
1366
1260
|
schema_define do
|
1367
|
-
create_table :test_posts, :
|
1368
|
-
t.string :title, :
|
1261
|
+
create_table :test_posts, tablespace: "bogus", force: true do |t|
|
1262
|
+
t.string :title, null: false
|
1369
1263
|
end
|
1370
1264
|
end
|
1371
1265
|
expect(@would_execute_sql).to match(/CREATE +TABLE .* \(.*\) TABLESPACE bogus/)
|
@@ -1391,7 +1285,7 @@ end
|
|
1391
1285
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:table)
|
1392
1286
|
end
|
1393
1287
|
it "should use correct tablespace" do
|
1394
|
-
@conn.create_table :tablespace_tests, :
|
1288
|
+
@conn.create_table :tablespace_tests, id: false, organization: "INDEX INITRANS 4 COMPRESS 1", tablespace: "bogus" do |t|
|
1395
1289
|
t.integer :id
|
1396
1290
|
end
|
1397
1291
|
expect(@would_execute_sql).to match(/CREATE +TABLE .*\(.*\)\s+ORGANIZATION INDEX INITRANS 4 COMPRESS 1 TABLESPACE bogus/)
|
@@ -1400,14 +1294,14 @@ end
|
|
1400
1294
|
|
1401
1295
|
it "should support the :options option to add_index" do
|
1402
1296
|
schema_define do
|
1403
|
-
add_index :keyboards, :name, :
|
1297
|
+
add_index :keyboards, :name, options: "NOLOGGING"
|
1404
1298
|
end
|
1405
1299
|
expect(@would_execute_sql).to match(/CREATE +INDEX .* ON .* \(.*\) NOLOGGING/)
|
1406
1300
|
end
|
1407
1301
|
|
1408
1302
|
it "should support the :tablespace option to add_index" do
|
1409
1303
|
schema_define do
|
1410
|
-
add_index :keyboards, :name, :
|
1304
|
+
add_index :keyboards, :name, tablespace: "bogus"
|
1411
1305
|
end
|
1412
1306
|
expect(@would_execute_sql).to match(/CREATE +INDEX .* ON .* \(.*\) TABLESPACE bogus/)
|
1413
1307
|
end
|
@@ -1423,7 +1317,7 @@ end
|
|
1423
1317
|
|
1424
1318
|
it "should create unique function index but not create unique constraints" do
|
1425
1319
|
schema_define do
|
1426
|
-
add_index :keyboards,
|
1320
|
+
add_index :keyboards, "lower(name)", unique: true, name: :index_keyboards_on_lower_name
|
1427
1321
|
end
|
1428
1322
|
expect(@would_execute_sql).not_to match(/ALTER +TABLE .* ADD CONSTRAINT .* UNIQUE \(.*\(.*\)\)/)
|
1429
1323
|
end
|