activerecord-oracle_enhanced-adapter 1.8.2 → 5.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.md +190 -5
- data/README.md +10 -10
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +9 -71
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +84 -73
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +12 -12
- data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +52 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +35 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +59 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +379 -402
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +7 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +46 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +242 -247
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +9 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +3 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +25 -9
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +9 -6
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +10 -5
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +48 -51
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +261 -59
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +2 -34
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +267 -222
- data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +33 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +136 -547
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/boolean.rb +4 -2
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/integer.rb +4 -2
- data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/national_character_string.rb +5 -3
- data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/raw.rb +4 -2
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/string.rb +4 -2
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/text.rb +4 -2
- data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/timestamptz.rb +4 -2
- data/lib/activerecord-oracle_enhanced-adapter.rb +2 -6
- data/spec/active_record/connection_adapters/{oracle_enhanced_emulate_oracle_adapter_spec.rb → emulation/oracle_adapter_spec.rb} +2 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_connection_spec.rb → oracle_enhanced/connection_spec.rb} +82 -38
- data/spec/active_record/connection_adapters/{oracle_enhanced_context_index_spec.rb → oracle_enhanced/context_index_spec.rb} +20 -16
- data/spec/active_record/connection_adapters/{oracle_enhanced_database_tasks_spec.rb → oracle_enhanced/database_tasks_spec.rb} +17 -5
- data/spec/active_record/connection_adapters/{oracle_enhanced_dbms_output_spec.rb → oracle_enhanced/dbms_output_spec.rb} +2 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_procedures_spec.rb → oracle_enhanced/procedures_spec.rb} +26 -33
- data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +196 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_schema_dump_spec.rb → oracle_enhanced/schema_dumper_spec.rb} +61 -90
- data/spec/active_record/connection_adapters/{oracle_enhanced_schema_statements_spec.rb → oracle_enhanced/schema_statements_spec.rb} +95 -28
- data/spec/active_record/connection_adapters/{oracle_enhanced_structure_dump_spec.rb → oracle_enhanced/structure_dump_spec.rb} +48 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +202 -331
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +15 -1106
- data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
- data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +207 -0
- data/spec/active_record/{connection_adapters/oracle_enhanced_dirty_spec.rb → oracle_enhanced/type/dirty_spec.rb} +3 -1
- data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
- data/spec/active_record/oracle_enhanced/type/integer_spec.rb +91 -0
- data/spec/active_record/oracle_enhanced/type/json_spec.rb +57 -0
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +55 -0
- data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
- data/spec/active_record/oracle_enhanced/type/raw_spec.rb +122 -0
- data/spec/active_record/oracle_enhanced/type/text_spec.rb +229 -0
- data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +75 -0
- data/spec/spec_helper.rb +15 -1
- data/spec/support/alter_system_set_open_cursors.sql +1 -0
- metadata +63 -48
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +0 -28
- data/lib/active_record/oracle_enhanced/type/json.rb +0 -8
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
describe "OracleEnhancedAdapter schema dump" do
|
2
4
|
include SchemaSpecHelper
|
5
|
+
include SchemaDumpingHelper
|
3
6
|
|
4
7
|
before(:all) do
|
5
8
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
@@ -68,73 +71,49 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
68
71
|
end
|
69
72
|
|
70
73
|
it "should be able to dump default values using special characters" do
|
71
|
-
|
74
|
+
output = dump_table_schema "test_defaults"
|
75
|
+
expect(output).to match(/t.string \"special_c\", default: "\\n"/)
|
72
76
|
end
|
73
77
|
end
|
74
|
-
|
78
|
+
|
79
|
+
describe "table with non-default primary key" do
|
75
80
|
after(:each) do
|
76
81
|
drop_test_posts_table
|
77
|
-
@conn.drop_table(ActiveRecord::SchemaMigration.table_name) if @conn.table_exists?(ActiveRecord::SchemaMigration.table_name)
|
78
|
-
@conn.drop_table(ActiveRecord::InternalMetadata.table_name) if @conn.table_exists?(ActiveRecord::InternalMetadata.table_name)
|
79
|
-
ActiveRecord::Base.table_name_prefix = ""
|
80
|
-
ActiveRecord::Base.table_name_suffix = ""
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should remove table prefix in schema dump" do
|
84
|
-
ActiveRecord::Base.table_name_prefix = "xxx_"
|
85
|
-
create_test_posts_table
|
86
|
-
expect(standard_dump).to match(/create_table "test_posts"/m)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should remove table prefix with $ sign in schema dump" do
|
90
|
-
ActiveRecord::Base.table_name_prefix = "xxx$"
|
91
|
-
create_test_posts_table
|
92
|
-
expect(standard_dump).to match(/create_table "test_posts"/m)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should remove table suffix in schema dump" do
|
96
|
-
ActiveRecord::Base.table_name_suffix = "_xxx"
|
97
|
-
create_test_posts_table
|
98
|
-
expect(standard_dump).to match(/create_table "test_posts"/m)
|
99
82
|
end
|
100
83
|
|
101
|
-
it "should
|
102
|
-
|
103
|
-
|
104
|
-
expect(
|
84
|
+
it "should include non-default primary key in schema dump" do
|
85
|
+
create_test_posts_table(primary_key: "post_id")
|
86
|
+
output = dump_table_schema "test_posts"
|
87
|
+
expect(output).to match(/create_table "test_posts", primary_key: "post_id"/)
|
105
88
|
end
|
106
89
|
|
107
|
-
|
108
|
-
ActiveRecord::Base.table_name_prefix = "xxx_"
|
109
|
-
ActiveRecord::SchemaMigration.create_table
|
110
|
-
expect(standard_dump).not_to match(/schema_migrations/)
|
111
|
-
end
|
90
|
+
end
|
112
91
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
92
|
+
describe "table with ntext columns" do
|
93
|
+
before :each do
|
94
|
+
schema_define do
|
95
|
+
create_table "test_ntexts", force: true do |t|
|
96
|
+
t.ntext :ntext_column
|
97
|
+
end
|
98
|
+
end
|
117
99
|
end
|
118
100
|
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "table with non-default primary key" do
|
122
101
|
after(:each) do
|
123
|
-
|
102
|
+
schema_define do
|
103
|
+
drop_table "test_ntexts"
|
104
|
+
end
|
124
105
|
end
|
125
106
|
|
126
|
-
it "should
|
127
|
-
|
128
|
-
expect(
|
107
|
+
it "should be able to dump ntext columns" do
|
108
|
+
output = dump_table_schema "test_ntexts"
|
109
|
+
expect(output).to match(/t.ntext \"ntext_column\"/)
|
129
110
|
end
|
130
|
-
|
131
111
|
end
|
132
112
|
|
133
113
|
describe "table with primary key trigger" do
|
134
114
|
|
135
115
|
after(:each) do
|
136
116
|
drop_test_posts_table
|
137
|
-
@conn.clear_prefetch_primary_key
|
138
117
|
end
|
139
118
|
|
140
119
|
it "should include primary key trigger in schema dump" do
|
@@ -170,8 +149,8 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
170
149
|
end
|
171
150
|
after(:all) do
|
172
151
|
schema_define do
|
173
|
-
drop_table :test_comments
|
174
|
-
drop_table :test_posts
|
152
|
+
drop_table :test_comments, if_exists: true
|
153
|
+
drop_table :test_posts, if_exists: true
|
175
154
|
end
|
176
155
|
end
|
177
156
|
|
@@ -179,21 +158,24 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
179
158
|
schema_define do
|
180
159
|
add_foreign_key :test_comments, :test_posts
|
181
160
|
end
|
182
|
-
|
161
|
+
output = dump_table_schema "test_comments"
|
162
|
+
expect(output).to match(/add_foreign_key "test_comments", "test_posts"/)
|
183
163
|
end
|
184
164
|
|
185
165
|
it "should include foreign key with delete dependency in schema dump" do
|
186
166
|
schema_define do
|
187
167
|
add_foreign_key :test_comments, :test_posts, on_delete: :cascade
|
188
168
|
end
|
189
|
-
|
169
|
+
output = dump_table_schema "test_comments"
|
170
|
+
expect(output).to match(/add_foreign_key "test_comments", "test_posts", on_delete: :cascade/)
|
190
171
|
end
|
191
172
|
|
192
173
|
it "should include foreign key with nullify dependency in schema dump" do
|
193
174
|
schema_define do
|
194
175
|
add_foreign_key :test_comments, :test_posts, on_delete: :nullify
|
195
176
|
end
|
196
|
-
|
177
|
+
output = dump_table_schema "test_comments"
|
178
|
+
expect(output).to match(/add_foreign_key "test_comments", "test_posts", on_delete: :nullify/)
|
197
179
|
end
|
198
180
|
|
199
181
|
it "should not include foreign keys on ignored table names in schema dump" do
|
@@ -225,7 +207,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
225
207
|
end
|
226
208
|
|
227
209
|
it "should include foreign keys following all tables" do
|
228
|
-
# if foreign keys
|
210
|
+
# if foreign keys precede declaration of all tables
|
229
211
|
# it can cause problems when using db:test rake tasks
|
230
212
|
schema_define do
|
231
213
|
add_foreign_key :test_comments, :test_posts
|
@@ -250,7 +232,8 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
250
232
|
ADD CONSTRAINT TEST_COMMENTS_BAZ_ID_FK FOREIGN KEY (baz_id) REFERENCES test_posts(baz_id)
|
251
233
|
SQL
|
252
234
|
|
253
|
-
|
235
|
+
output = dump_table_schema "test_comments"
|
236
|
+
expect(output).to match(/add_foreign_key "test_comments", "test_posts", column: "baz_id", primary_key: "baz_id", name: "test_comments_baz_id_fk"/)
|
254
237
|
end
|
255
238
|
|
256
239
|
end
|
@@ -306,7 +289,8 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
306
289
|
|
307
290
|
it "should include temporary options" do
|
308
291
|
create_test_posts_table(temporary: true)
|
309
|
-
|
292
|
+
output = dump_table_schema "test_posts"
|
293
|
+
expect(output).to match(/create_table "test_posts", temporary: true/)
|
310
294
|
end
|
311
295
|
end
|
312
296
|
|
@@ -317,20 +301,23 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
317
301
|
|
318
302
|
it "should not specify default tablespace in add index" do
|
319
303
|
create_test_posts_table
|
320
|
-
|
304
|
+
output = dump_table_schema "test_posts"
|
305
|
+
expect(output).to match(/t\.index \["title"\], name: "index_test_posts_on_title"$/)
|
321
306
|
end
|
322
307
|
|
323
308
|
it "should specify non-default tablespace in add index" do
|
324
309
|
tablespace_name = @conn.default_tablespace
|
325
310
|
allow(@conn).to receive(:default_tablespace).and_return("dummy")
|
326
311
|
create_test_posts_table
|
327
|
-
|
312
|
+
output = dump_table_schema "test_posts"
|
313
|
+
expect(output).to match(/t\.index \["title"\], name: "index_test_posts_on_title", tablespace: "#{tablespace_name}"$/)
|
328
314
|
end
|
329
315
|
|
330
316
|
it "should create and dump function-based indexes" do
|
331
317
|
create_test_posts_table
|
332
318
|
@conn.add_index :test_posts, "NVL(created_at, updated_at)", name: "index_test_posts_cr_upd_at"
|
333
|
-
|
319
|
+
output = dump_table_schema "test_posts"
|
320
|
+
expect(output).to match(/t\.index \["NVL\(\\"CREATED_AT\\",\\"UPDATED_AT\\"\)"\], name: "index_test_posts_cr_upd_at"$/)
|
334
321
|
end
|
335
322
|
|
336
323
|
end
|
@@ -382,33 +369,13 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
382
369
|
end
|
383
370
|
|
384
371
|
it "should dump correctly" do
|
385
|
-
|
386
|
-
expect(
|
387
|
-
expect(
|
388
|
-
expect(
|
389
|
-
expect(
|
390
|
-
expect(
|
391
|
-
|
392
|
-
|
393
|
-
context "with column cache" do
|
394
|
-
before(:all) do
|
395
|
-
@old_cache = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns
|
396
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = true
|
397
|
-
end
|
398
|
-
after(:all) do
|
399
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = @old_cache
|
400
|
-
end
|
401
|
-
it "should not change column defaults after several dumps" do
|
402
|
-
col = TestName.columns.detect { |c| c.name == "full_name" }
|
403
|
-
expect(col).not_to be_nil
|
404
|
-
expect(col.virtual_column_data_default).not_to match(/:as/)
|
405
|
-
|
406
|
-
standard_dump
|
407
|
-
expect(col.virtual_column_data_default).not_to match(/:as/)
|
408
|
-
|
409
|
-
standard_dump
|
410
|
-
expect(col.virtual_column_data_default).not_to match(/:as/)
|
411
|
-
end
|
372
|
+
output = dump_table_schema "test_names"
|
373
|
+
expect(output).to match(/t\.virtual "full_name",(\s*)type: :string,(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\""/)
|
374
|
+
expect(output).to match(/t\.virtual "short_name",(\s*)type: :string,(\s*)limit: 300,(\s*)as:(.*)/)
|
375
|
+
expect(output).to match(/t\.virtual "full_name_length",(\s*)type: :integer,(\s*)precision: 38,(\s*)as:(.*)/)
|
376
|
+
expect(output).to match(/t\.virtual "name_ratio",(\s*)as:(.*)\"$/) # no :type
|
377
|
+
expect(output).to match(/t\.virtual "abbrev_name",(\s*)type: :string,(\s*)limit: 100,(\s*)as:(.*)/)
|
378
|
+
expect(output).to match(/t\.virtual "field_with_leading_space",(\s*)type: :string,(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '"/)
|
412
379
|
end
|
413
380
|
|
414
381
|
context "with index on virtual column" do
|
@@ -427,8 +394,9 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
427
394
|
end
|
428
395
|
end
|
429
396
|
it "should dump correctly" do
|
430
|
-
|
431
|
-
expect(
|
397
|
+
output = dump_table_schema "test_names"
|
398
|
+
expect(output).not_to match(/t\.index .+FIRST_NAME.+$/)
|
399
|
+
expect(output).to match(/t\.index .+field_with_leading_space.+$/)
|
432
400
|
end
|
433
401
|
end
|
434
402
|
end
|
@@ -449,7 +417,8 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
449
417
|
end
|
450
418
|
|
451
419
|
it "should dump float type correctly" do
|
452
|
-
|
420
|
+
output = dump_table_schema "test_floats"
|
421
|
+
expect(output).to match(/t\.float "hourly_rate"$/)
|
453
422
|
end
|
454
423
|
end
|
455
424
|
|
@@ -469,7 +438,8 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
469
438
|
end
|
470
439
|
|
471
440
|
it "should dump table comments" do
|
472
|
-
|
441
|
+
output = dump_table_schema "test_table_comments"
|
442
|
+
expect(output).to match(/create_table "test_table_comments", comment: "this is a \\"table comment\\"!", force: :cascade do \|t\|$/)
|
473
443
|
end
|
474
444
|
end
|
475
445
|
|
@@ -489,7 +459,8 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
489
459
|
end
|
490
460
|
|
491
461
|
it "should dump column comments" do
|
492
|
-
|
462
|
+
output = dump_table_schema "test_column_comments"
|
463
|
+
expect(output).to match(/comment: "this is a \\"column comment\\"!"/)
|
493
464
|
end
|
494
465
|
end
|
495
466
|
|
@@ -512,7 +483,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
512
483
|
|
513
484
|
after do
|
514
485
|
schema_define do
|
515
|
-
drop_table :test_comments
|
486
|
+
drop_table :test_comments, if_exists: true
|
516
487
|
end
|
517
488
|
|
518
489
|
drop_test_posts_table
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
describe "OracleEnhancedAdapter schema definition" do
|
2
4
|
include SchemaSpecHelper
|
3
5
|
include LoggerSpecHelper
|
@@ -21,7 +23,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
21
23
|
end
|
22
24
|
|
23
25
|
it "creates a sequence when adding a column with create_sequence = true" do
|
24
|
-
_, sequence_name = ActiveRecord::Base.connection.
|
26
|
+
_, sequence_name = ActiveRecord::Base.connection.pk_and_sequence_for(:keyboards)
|
25
27
|
|
26
28
|
expect(sequence_name).to eq(Keyboard.sequence_name)
|
27
29
|
end
|
@@ -179,7 +181,6 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
179
181
|
drop_table :test_employees, (seq_name ? { sequence_name: seq_name } : {})
|
180
182
|
end
|
181
183
|
Object.send(:remove_const, "TestEmployee")
|
182
|
-
@conn.clear_prefetch_primary_key
|
183
184
|
ActiveRecord::Base.clear_cache!
|
184
185
|
end
|
185
186
|
|
@@ -333,7 +334,13 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
333
334
|
@conn = ActiveRecord::Base.connection
|
334
335
|
end
|
335
336
|
|
337
|
+
before(:each) do
|
338
|
+
@conn.clear_cache!
|
339
|
+
set_logger
|
340
|
+
end
|
341
|
+
|
336
342
|
after(:each) do
|
343
|
+
clear_logger
|
337
344
|
schema_define do
|
338
345
|
drop_table :test_employees
|
339
346
|
end
|
@@ -346,7 +353,6 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
346
353
|
table_comment = "Test Employees"
|
347
354
|
create_test_employees_table(table_comment)
|
348
355
|
class ::TestEmployee < ActiveRecord::Base; end
|
349
|
-
|
350
356
|
expect(@conn.table_comment("test_employees")).to eq(table_comment)
|
351
357
|
end
|
352
358
|
|
@@ -379,6 +385,28 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
379
385
|
end
|
380
386
|
end
|
381
387
|
|
388
|
+
it "should query table_comment using bind variables" do
|
389
|
+
table_comment = "Test Employees"
|
390
|
+
create_test_employees_table(table_comment)
|
391
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
392
|
+
expect(@conn.table_comment(TestEmployee.table_name)).to eq(table_comment)
|
393
|
+
expect(@logger.logged(:debug).last).to match(/:owner/)
|
394
|
+
expect(@logger.logged(:debug).last).to match(/:table_name/)
|
395
|
+
expect(@logger.logged(:debug).last).to match(/\[\["owner", "#{DATABASE_USER.upcase}"\], \["table_name", "TEST_EMPLOYEES"\]\]/)
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should query column_comment using bind variables" do
|
399
|
+
table_comment = "Test Employees"
|
400
|
+
column_comment = { first_name: "Given Name" }
|
401
|
+
create_test_employees_table(table_comment, column_comment)
|
402
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
403
|
+
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
|
+
expect(@logger.logged(:debug).last).to match(/:table_name/)
|
406
|
+
expect(@logger.logged(:debug).last).to match(/:column_name/)
|
407
|
+
expect(@logger.logged(:debug).last).to match(/\[\["owner", "#{DATABASE_USER.upcase}"\], \["table_name", "TEST_EMPLOYEES"\], \["column_name", "FIRST_NAME"\]\]/)
|
408
|
+
end
|
409
|
+
|
382
410
|
end
|
383
411
|
|
384
412
|
describe "drop tables" do
|
@@ -397,16 +425,12 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
397
425
|
before(:each) do
|
398
426
|
@conn = ActiveRecord::Base.connection
|
399
427
|
schema_define do
|
400
|
-
|
401
|
-
drop_table :new_test_employees rescue nil
|
402
|
-
drop_table :test_employees_no_primary_key rescue nil
|
403
|
-
|
404
|
-
create_table :test_employees do |t|
|
428
|
+
create_table :test_employees, force: true do |t|
|
405
429
|
t.string :first_name
|
406
430
|
t.string :last_name
|
407
431
|
end
|
408
432
|
|
409
|
-
create_table :test_employees_no_pkey, id: false do |t|
|
433
|
+
create_table :test_employees_no_pkey, force: true, id: false do |t|
|
410
434
|
t.string :first_name
|
411
435
|
t.string :last_name
|
412
436
|
end
|
@@ -415,11 +439,12 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
415
439
|
|
416
440
|
after(:each) do
|
417
441
|
schema_define do
|
418
|
-
drop_table :
|
419
|
-
drop_table :
|
420
|
-
drop_table :
|
421
|
-
drop_table :
|
422
|
-
drop_table :
|
442
|
+
drop_table :test_employees_no_primary_key, if_exists: true
|
443
|
+
drop_table :test_employees, if_exists: true
|
444
|
+
drop_table :new_test_employees, if_exists: true
|
445
|
+
drop_table :test_employees_no_pkey, if_exists: true
|
446
|
+
drop_table :new_test_employees_no_pkey, if_exists: true
|
447
|
+
drop_table :aaaaaaaaaaaaaaaaaaaaaaaaaaa, if_exists: true
|
423
448
|
end
|
424
449
|
end
|
425
450
|
|
@@ -610,18 +635,20 @@ end
|
|
610
635
|
class ::TestComment < ActiveRecord::Base
|
611
636
|
belongs_to :test_post
|
612
637
|
end
|
638
|
+
set_logger
|
613
639
|
end
|
614
640
|
|
615
641
|
after(:each) do
|
616
642
|
Object.send(:remove_const, "TestPost")
|
617
643
|
Object.send(:remove_const, "TestComment")
|
618
644
|
schema_define do
|
619
|
-
drop_table :test_comments
|
620
|
-
drop_table :test_posts
|
645
|
+
drop_table :test_comments, if_exists: true
|
646
|
+
drop_table :test_posts, if_exists: true
|
621
647
|
end
|
622
648
|
ActiveRecord::Base.table_name_prefix = ""
|
623
649
|
ActiveRecord::Base.table_name_suffix = ""
|
624
650
|
ActiveRecord::Base.clear_cache!
|
651
|
+
clear_logger
|
625
652
|
end
|
626
653
|
|
627
654
|
it "should add foreign key" do
|
@@ -705,6 +732,16 @@ end
|
|
705
732
|
end.not_to raise_error
|
706
733
|
end
|
707
734
|
|
735
|
+
it "should query foreign_keys using bind variables" do
|
736
|
+
schema_define do
|
737
|
+
add_foreign_key :test_comments, :test_posts
|
738
|
+
end
|
739
|
+
ActiveRecord::Base.connection.foreign_keys(:test_comments)
|
740
|
+
expect(@logger.logged(:debug).last).to match(/:owner/)
|
741
|
+
expect(@logger.logged(:debug).last).to match(/:desc_table_name/)
|
742
|
+
expect(@logger.logged(:debug).last).to match(/\[\["owner", "#{DATABASE_USER.upcase}"\], \["desc_table_name", "TEST_COMMENTS"\]\]/)
|
743
|
+
end
|
744
|
+
|
708
745
|
end
|
709
746
|
|
710
747
|
describe "lob in table definition" do
|
@@ -714,34 +751,56 @@ end
|
|
714
751
|
end
|
715
752
|
it "should use default tablespace for clobs" do
|
716
753
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = DATABASE_NON_DEFAULT_TABLESPACE
|
754
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:nclob] = nil
|
717
755
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = nil
|
718
756
|
schema_define do
|
719
757
|
create_table :test_posts, force: true do |t|
|
720
758
|
t.text :test_clob
|
759
|
+
t.ntext :test_nclob
|
721
760
|
t.binary :test_blob
|
722
761
|
end
|
723
762
|
end
|
724
763
|
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_CLOB'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
764
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_NCLOB'")).not_to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
765
|
+
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)
|
766
|
+
end
|
767
|
+
|
768
|
+
it "should use default tablespace for nclobs" do
|
769
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:nclob] = DATABASE_NON_DEFAULT_TABLESPACE
|
770
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = nil
|
771
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = nil
|
772
|
+
schema_define do
|
773
|
+
create_table :test_posts, force: true do |t|
|
774
|
+
t.text :test_clob
|
775
|
+
t.ntext :test_nclob
|
776
|
+
t.binary :test_blob
|
777
|
+
end
|
778
|
+
end
|
779
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_NCLOB'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
780
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_CLOB'")).not_to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
725
781
|
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)
|
726
782
|
end
|
727
783
|
|
728
784
|
it "should use default tablespace for blobs" do
|
729
785
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = DATABASE_NON_DEFAULT_TABLESPACE
|
730
786
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = nil
|
787
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:nclob] = nil
|
731
788
|
schema_define do
|
732
789
|
create_table :test_posts, force: true do |t|
|
733
790
|
t.text :test_clob
|
791
|
+
t.ntext :test_nclob
|
734
792
|
t.binary :test_blob
|
735
793
|
end
|
736
794
|
end
|
737
795
|
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_BLOB'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
738
796
|
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_CLOB'")).not_to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
797
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_NCLOB'")).not_to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
739
798
|
end
|
740
799
|
|
741
800
|
after do
|
742
801
|
Object.send(:remove_const, "TestPost")
|
743
802
|
schema_define do
|
744
|
-
drop_table :test_posts
|
803
|
+
drop_table :test_posts, if_exists: true
|
745
804
|
end
|
746
805
|
end
|
747
806
|
end
|
@@ -787,7 +846,7 @@ end
|
|
787
846
|
after do
|
788
847
|
Object.send(:remove_const, "TestPost")
|
789
848
|
schema_define do
|
790
|
-
drop_table :test_posts
|
849
|
+
drop_table :test_posts, if_exists: true
|
791
850
|
end
|
792
851
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = nil
|
793
852
|
end
|
@@ -812,8 +871,8 @@ end
|
|
812
871
|
Object.send(:remove_const, "TestPost")
|
813
872
|
Object.send(:remove_const, "TestComment")
|
814
873
|
schema_define do
|
815
|
-
drop_table :test_comments
|
816
|
-
drop_table :test_posts
|
874
|
+
drop_table :test_comments, if_exists: true
|
875
|
+
drop_table :test_posts, if_exists: true
|
817
876
|
end
|
818
877
|
ActiveRecord::Base.clear_cache!
|
819
878
|
end
|
@@ -897,9 +956,9 @@ end
|
|
897
956
|
|
898
957
|
after(:each) do
|
899
958
|
schema_define do
|
900
|
-
drop_table "test_Mixed_Comments"
|
901
|
-
drop_table :test_comments
|
902
|
-
drop_table :test_posts
|
959
|
+
drop_table "test_Mixed_Comments", if_exists: true
|
960
|
+
drop_table :test_comments, if_exists: true
|
961
|
+
drop_table :test_posts, if_exists: true
|
903
962
|
end
|
904
963
|
end
|
905
964
|
|
@@ -987,14 +1046,14 @@ end
|
|
987
1046
|
include LoggerSpecHelper
|
988
1047
|
|
989
1048
|
before(:all) do
|
990
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = true
|
991
1049
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:clob)
|
1050
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:nclob)
|
992
1051
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:blob)
|
993
1052
|
end
|
994
1053
|
|
995
1054
|
after(:all) do
|
996
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = nil
|
997
1055
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:clob)
|
1056
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:nclob)
|
998
1057
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:blob)
|
999
1058
|
end
|
1000
1059
|
|
@@ -1039,6 +1098,14 @@ end
|
|
1039
1098
|
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'BODY'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
1040
1099
|
end
|
1041
1100
|
|
1101
|
+
it "should add lob column with non_default tablespace" do
|
1102
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:nclob] = DATABASE_NON_DEFAULT_TABLESPACE
|
1103
|
+
schema_define do
|
1104
|
+
add_column :test_posts, :body, :ntext
|
1105
|
+
end
|
1106
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'BODY'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
1107
|
+
end
|
1108
|
+
|
1042
1109
|
it "should add blob column with non_default tablespace" do
|
1043
1110
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = DATABASE_NON_DEFAULT_TABLESPACE
|
1044
1111
|
schema_define do
|
@@ -1234,7 +1301,7 @@ end
|
|
1234
1301
|
end
|
1235
1302
|
|
1236
1303
|
before(:each) do
|
1237
|
-
@conn.instance_variable_set :@would_execute_sql, @would_execute_sql = ""
|
1304
|
+
@conn.instance_variable_set :@would_execute_sql, @would_execute_sql = "".dup
|
1238
1305
|
class <<@conn
|
1239
1306
|
def execute(sql, name = nil); @would_execute_sql << sql << ";\n"; end
|
1240
1307
|
end
|
@@ -1267,7 +1334,7 @@ end
|
|
1267
1334
|
|
1268
1335
|
describe "creating a table with a tablespace defaults set" do
|
1269
1336
|
after(:each) do
|
1270
|
-
@conn.drop_table :tablespace_tests
|
1337
|
+
@conn.drop_table :tablespace_tests, if_exists: true
|
1271
1338
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:table)
|
1272
1339
|
end
|
1273
1340
|
it "should use correct tablespace" do
|
@@ -1281,7 +1348,7 @@ end
|
|
1281
1348
|
|
1282
1349
|
describe "creating an index-organized table" do
|
1283
1350
|
after(:each) do
|
1284
|
-
@conn.drop_table :tablespace_tests
|
1351
|
+
@conn.drop_table :tablespace_tests, if_exists: true
|
1285
1352
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:table)
|
1286
1353
|
end
|
1287
1354
|
it "should use correct tablespace" do
|