activerecord-oracle_enhanced-adapter 6.0.4 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +108 -0
- data/README.md +12 -1
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +2 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +0 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +0 -9
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +9 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +4 -5
- data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +0 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +3 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +1 -2
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +2 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +0 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +2 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +2 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +16 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +58 -52
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +38 -36
- data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +2 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +64 -21
- data/lib/active_record/type/oracle_enhanced/boolean.rb +0 -1
- data/lib/active_record/type/oracle_enhanced/integer.rb +0 -1
- data/lib/arel/visitors/oracle.rb +217 -0
- data/lib/arel/visitors/oracle12.rb +124 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +9 -3
- data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +6 -1
- data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +0 -1
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +27 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +161 -0
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +4 -2
- data/spec/spec_config.yaml.template +2 -2
- data/spec/spec_helper.rb +13 -2
- metadata +25 -23
@@ -11,8 +11,9 @@ module ActiveRecord
|
|
11
11
|
# see: abstract/schema_statements.rb
|
12
12
|
|
13
13
|
def tables #:nodoc:
|
14
|
-
select_values(<<~SQL.squish, "
|
15
|
-
SELECT
|
14
|
+
select_values(<<~SQL.squish, "SCHEMA")
|
15
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
|
16
|
+
DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name)
|
16
17
|
FROM all_tables
|
17
18
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
18
19
|
AND secondary = 'N'
|
@@ -43,8 +44,8 @@ module ActiveRecord
|
|
43
44
|
table_owner, table_name = default_owner, real_name
|
44
45
|
end
|
45
46
|
|
46
|
-
select_values(<<~SQL.squish, "
|
47
|
-
SELECT owner, table_name
|
47
|
+
select_values(<<~SQL.squish, "SCHEMA", [bind_string("owner", table_owner), bind_string("table_name", table_name)]).any?
|
48
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, table_name
|
48
49
|
FROM all_tables
|
49
50
|
WHERE owner = :owner
|
50
51
|
AND table_name = :table_name
|
@@ -59,20 +60,22 @@ module ActiveRecord
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def views # :nodoc:
|
62
|
-
select_values(<<~SQL.squish, "
|
63
|
-
SELECT
|
63
|
+
select_values(<<~SQL.squish, "SCHEMA")
|
64
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
|
65
|
+
LOWER(view_name) FROM all_views WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
64
66
|
SQL
|
65
67
|
end
|
66
68
|
|
67
69
|
def materialized_views #:nodoc:
|
68
|
-
select_values(<<~SQL.squish, "
|
69
|
-
SELECT
|
70
|
+
select_values(<<~SQL.squish, "SCHEMA")
|
71
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
|
72
|
+
LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
70
73
|
SQL
|
71
74
|
end
|
72
75
|
|
73
76
|
# get synonyms for schema dump
|
74
77
|
def synonyms
|
75
|
-
result = select_all(<<~SQL.squish, "
|
78
|
+
result = select_all(<<~SQL.squish, "SCHEMA")
|
76
79
|
SELECT synonym_name, table_owner, table_name
|
77
80
|
FROM all_synonyms where owner = SYS_CONTEXT('userenv', 'current_schema')
|
78
81
|
SQL
|
@@ -87,8 +90,8 @@ module ActiveRecord
|
|
87
90
|
(_owner, table_name) = @connection.describe(table_name)
|
88
91
|
default_tablespace_name = default_tablespace
|
89
92
|
|
90
|
-
result = select_all(<<~SQL.squish, "
|
91
|
-
SELECT LOWER(i.table_name) AS table_name, LOWER(i.index_name) AS index_name, i.uniqueness,
|
93
|
+
result = select_all(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)])
|
94
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ LOWER(i.table_name) AS table_name, LOWER(i.index_name) AS index_name, i.uniqueness,
|
92
95
|
i.index_type, i.ityp_owner, i.ityp_name, i.parameters,
|
93
96
|
LOWER(i.tablespace_name) AS tablespace_name,
|
94
97
|
LOWER(c.column_name) AS column_name, e.column_expression,
|
@@ -117,8 +120,8 @@ module ActiveRecord
|
|
117
120
|
statement_parameters = nil
|
118
121
|
if row["index_type"] == "DOMAIN" && row["ityp_owner"] == "CTXSYS" && row["ityp_name"] == "CONTEXT"
|
119
122
|
procedure_name = default_datastore_procedure(row["index_name"])
|
120
|
-
source = select_values(<<~SQL.squish, "
|
121
|
-
SELECT text
|
123
|
+
source = select_values(<<~SQL.squish, "SCHEMA", [bind_string("procedure_name", procedure_name.upcase)]).join
|
124
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ text
|
122
125
|
FROM all_source
|
123
126
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
124
127
|
AND name = :procedure_name
|
@@ -196,19 +199,19 @@ module ActiveRecord
|
|
196
199
|
# t.string :last_name, :comment => “Surname”
|
197
200
|
# end
|
198
201
|
|
199
|
-
def create_table(table_name, **options)
|
200
|
-
create_sequence =
|
201
|
-
td = create_table_definition
|
202
|
+
def create_table(table_name, id: :primary_key, primary_key: nil, force: nil, **options)
|
203
|
+
create_sequence = id != false
|
204
|
+
td = create_table_definition(
|
205
|
+
table_name, **options.extract!(:temporary, :options, :as, :comment, :tablespace, :organization)
|
206
|
+
)
|
202
207
|
|
203
|
-
if
|
204
|
-
pk =
|
205
|
-
Base.get_primary_key table_name.to_s.singularize
|
206
|
-
end
|
208
|
+
if id && !td.as
|
209
|
+
pk = primary_key || Base.get_primary_key(table_name.to_s.singularize)
|
207
210
|
|
208
211
|
if pk.is_a?(Array)
|
209
212
|
td.primary_keys pk
|
210
213
|
else
|
211
|
-
td.primary_key pk,
|
214
|
+
td.primary_key pk, id, **options
|
212
215
|
end
|
213
216
|
end
|
214
217
|
|
@@ -226,8 +229,10 @@ module ActiveRecord
|
|
226
229
|
yield td if block_given?
|
227
230
|
create_sequence = create_sequence || td.create_sequence
|
228
231
|
|
229
|
-
if
|
230
|
-
drop_table(table_name,
|
232
|
+
if force && data_source_exists?(table_name)
|
233
|
+
drop_table(table_name, force: force, if_exists: true)
|
234
|
+
else
|
235
|
+
schema_cache.clear_data_source_cache!(table_name.to_s)
|
231
236
|
end
|
232
237
|
|
233
238
|
execute schema_creation.accept td
|
@@ -235,14 +240,14 @@ module ActiveRecord
|
|
235
240
|
create_sequence_and_trigger(table_name, options) if create_sequence
|
236
241
|
|
237
242
|
if supports_comments? && !supports_comments_in_create?
|
238
|
-
if table_comment =
|
243
|
+
if table_comment = td.comment.presence
|
239
244
|
change_table_comment(table_name, table_comment)
|
240
245
|
end
|
241
246
|
td.columns.each do |column|
|
242
247
|
change_column_comment(table_name, column.name, column.comment) if column.comment.present?
|
243
248
|
end
|
244
249
|
end
|
245
|
-
td.indexes.each { |c, o| add_index table_name, c, o }
|
250
|
+
td.indexes.each { |c, o| add_index table_name, c, **o }
|
246
251
|
|
247
252
|
rebuild_primary_key_index_to_default_tablespace(table_name, options)
|
248
253
|
end
|
@@ -251,13 +256,16 @@ module ActiveRecord
|
|
251
256
|
if new_name.to_s.length > DatabaseLimits::IDENTIFIER_MAX_LENGTH
|
252
257
|
raise ArgumentError, "New table name '#{new_name}' is too long; the limit is #{DatabaseLimits::IDENTIFIER_MAX_LENGTH} characters"
|
253
258
|
end
|
259
|
+
schema_cache.clear_data_source_cache!(table_name.to_s)
|
260
|
+
schema_cache.clear_data_source_cache!(new_name.to_s)
|
254
261
|
execute "RENAME #{quote_table_name(table_name)} TO #{quote_table_name(new_name)}"
|
255
262
|
execute "RENAME #{quote_table_name("#{table_name}_seq")} TO #{default_sequence_name(new_name)}" rescue nil
|
256
263
|
|
257
264
|
rename_table_indexes(table_name, new_name)
|
258
265
|
end
|
259
266
|
|
260
|
-
def drop_table(table_name, options
|
267
|
+
def drop_table(table_name, **options) #:nodoc:
|
268
|
+
schema_cache.clear_data_source_cache!(table_name.to_s)
|
261
269
|
execute "DROP TABLE #{quote_table_name(table_name)}#{' CASCADE CONSTRAINTS' if options[:force] == :cascade}"
|
262
270
|
seq_name = options[:sequence_name] || default_sequence_name(table_name)
|
263
271
|
execute "DROP SEQUENCE #{quote_table_name(seq_name)}" rescue nil
|
@@ -287,7 +295,7 @@ module ActiveRecord
|
|
287
295
|
end
|
288
296
|
end
|
289
297
|
|
290
|
-
def add_index(table_name, column_name, options
|
298
|
+
def add_index(table_name, column_name, **options) #:nodoc:
|
291
299
|
index_name, index_type, quoted_column_names, tablespace, index_options = add_index_options(table_name, column_name, **options)
|
292
300
|
execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{quoted_column_names})#{tablespace} #{index_options}"
|
293
301
|
if index_type == "UNIQUE"
|
@@ -306,13 +314,11 @@ module ActiveRecord
|
|
306
314
|
index_type = options[:unique] ? "UNIQUE" : ""
|
307
315
|
index_name = options[:name].to_s if options.key?(:name)
|
308
316
|
tablespace = tablespace_for(:index, options[:tablespace])
|
309
|
-
|
310
|
-
# TODO: This option is used for NOLOGGING, needs better argumetn name
|
317
|
+
# TODO: This option is used for NOLOGGING, needs better argument name
|
311
318
|
index_options = options[:options]
|
312
319
|
|
313
|
-
|
314
|
-
|
315
|
-
end
|
320
|
+
validate_index_length!(table_name, index_name, options.fetch(:internal, false))
|
321
|
+
|
316
322
|
if table_exists?(table_name) && index_name_exists?(table_name, index_name)
|
317
323
|
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
|
318
324
|
end
|
@@ -323,8 +329,8 @@ module ActiveRecord
|
|
323
329
|
|
324
330
|
# Remove the given index from the table.
|
325
331
|
# Gives warning if index does not exist
|
326
|
-
def remove_index(table_name,
|
327
|
-
index_name = index_name_for_remove(table_name, options)
|
332
|
+
def remove_index(table_name, column_name = nil, **options) #:nodoc:
|
333
|
+
index_name = index_name_for_remove(table_name, column_name, options)
|
328
334
|
# TODO: It should execute only when index_type == "UNIQUE"
|
329
335
|
execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_column_name(index_name)}" rescue nil
|
330
336
|
execute "DROP INDEX #{quote_column_name(index_name)}"
|
@@ -361,8 +367,8 @@ module ActiveRecord
|
|
361
367
|
# Will always query database and not index cache.
|
362
368
|
def index_name_exists?(table_name, index_name)
|
363
369
|
(_owner, table_name) = @connection.describe(table_name)
|
364
|
-
result = select_value(<<~SQL.squish, "
|
365
|
-
SELECT 1 FROM all_indexes i
|
370
|
+
result = select_value(<<~SQL.squish, "SCHEMA")
|
371
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ 1 FROM all_indexes i
|
366
372
|
WHERE i.owner = SYS_CONTEXT('userenv', 'current_schema')
|
367
373
|
AND i.table_owner = SYS_CONTEXT('userenv', 'current_schema')
|
368
374
|
AND i.table_name = '#{table_name}'
|
@@ -440,7 +446,7 @@ module ActiveRecord
|
|
440
446
|
change_column table_name, column_name, column.sql_type, null: null
|
441
447
|
end
|
442
448
|
|
443
|
-
def change_column(table_name, column_name, type, options
|
449
|
+
def change_column(table_name, column_name, type, **options) #:nodoc:
|
444
450
|
column = column_for(table_name, column_name)
|
445
451
|
|
446
452
|
# remove :null option if its value is the same as current column definition
|
@@ -494,9 +500,10 @@ module ActiveRecord
|
|
494
500
|
end
|
495
501
|
|
496
502
|
def table_comment(table_name) #:nodoc:
|
503
|
+
# TODO
|
497
504
|
(_owner, table_name) = @connection.describe(table_name)
|
498
|
-
select_value(<<~SQL.squish, "
|
499
|
-
SELECT comments FROM all_tab_comments
|
505
|
+
select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)])
|
506
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_tab_comments
|
500
507
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
501
508
|
AND table_name = :table_name
|
502
509
|
SQL
|
@@ -511,8 +518,8 @@ module ActiveRecord
|
|
511
518
|
def column_comment(table_name, column_name) #:nodoc:
|
512
519
|
# TODO: it does not exist in Abstract adapter
|
513
520
|
(_owner, table_name) = @connection.describe(table_name)
|
514
|
-
select_value(<<~SQL.squish, "
|
515
|
-
SELECT comments FROM all_col_comments
|
521
|
+
select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name), bind_string("column_name", column_name.upcase)])
|
522
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_col_comments
|
516
523
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
517
524
|
AND table_name = :table_name
|
518
525
|
AND column_name = :column_name
|
@@ -528,8 +535,8 @@ module ActiveRecord
|
|
528
535
|
end
|
529
536
|
|
530
537
|
def tablespace(table_name)
|
531
|
-
select_value(<<~SQL.squish, "
|
532
|
-
SELECT tablespace_name
|
538
|
+
select_value(<<~SQL.squish, "SCHEMA")
|
539
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ tablespace_name
|
533
540
|
FROM all_tables
|
534
541
|
WHERE table_name='#{table_name.to_s.upcase}'
|
535
542
|
AND owner = SYS_CONTEXT('userenv', 'current_schema')
|
@@ -540,8 +547,8 @@ module ActiveRecord
|
|
540
547
|
def foreign_keys(table_name) #:nodoc:
|
541
548
|
(_owner, desc_table_name) = @connection.describe(table_name)
|
542
549
|
|
543
|
-
fk_info = select_all(<<~SQL.squish, "
|
544
|
-
SELECT r.table_name to_table
|
550
|
+
fk_info = select_all(<<~SQL.squish, "SCHEMA", [bind_string("desc_table_name", desc_table_name)])
|
551
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ r.table_name to_table
|
545
552
|
,rc.column_name references_column
|
546
553
|
,cc.column_name
|
547
554
|
,c.constraint_name name
|
@@ -582,8 +589,8 @@ module ActiveRecord
|
|
582
589
|
# REFERENTIAL INTEGRITY ====================================
|
583
590
|
|
584
591
|
def disable_referential_integrity(&block) #:nodoc:
|
585
|
-
old_constraints = select_all(<<~SQL.squish, "
|
586
|
-
SELECT constraint_name, owner, table_name
|
592
|
+
old_constraints = select_all(<<~SQL.squish, "SCHEMA")
|
593
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ constraint_name, owner, table_name
|
587
594
|
FROM all_constraints
|
588
595
|
WHERE constraint_type = 'R'
|
589
596
|
AND status = 'ENABLED'
|
@@ -614,13 +621,12 @@ module ActiveRecord
|
|
614
621
|
end
|
615
622
|
|
616
623
|
private
|
617
|
-
|
618
624
|
def schema_creation
|
619
625
|
OracleEnhanced::SchemaCreation.new self
|
620
626
|
end
|
621
627
|
|
622
|
-
def create_table_definition(
|
623
|
-
OracleEnhanced::TableDefinition.new(self,
|
628
|
+
def create_table_definition(name, **options)
|
629
|
+
OracleEnhanced::TableDefinition.new(self, name, **options)
|
624
630
|
end
|
625
631
|
|
626
632
|
def new_column_from_field(table_name, field)
|
@@ -642,7 +648,7 @@ module ActiveRecord
|
|
642
648
|
# If a default contains a newline these cleanup regexes need to
|
643
649
|
# match newlines.
|
644
650
|
field["data_default"].sub!(/^'(.*)'$/m, '\1')
|
645
|
-
field["data_default"] = nil if
|
651
|
+
field["data_default"] = nil if /^(null|empty_[bc]lob\(\))$/i.match?(field["data_default"])
|
646
652
|
# TODO: Needs better fix to fallback "N" to false
|
647
653
|
field["data_default"] = false if field["data_default"] == "N" && OracleEnhancedAdapter.emulate_booleans_from_strings
|
648
654
|
end
|
@@ -699,7 +705,7 @@ module ActiveRecord
|
|
699
705
|
return unless tablespace
|
700
706
|
|
701
707
|
index_name = select_value(<<~SQL.squish, "Index name for primary key", [bind_string("table_name", table_name.upcase)])
|
702
|
-
SELECT index_name FROM all_constraints
|
708
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ index_name FROM all_constraints
|
703
709
|
WHERE table_name = :table_name
|
704
710
|
AND constraint_type = 'P'
|
705
711
|
AND owner = SYS_CONTEXT('userenv', 'current_schema')
|
@@ -8,8 +8,9 @@ module ActiveRecord #:nodoc:
|
|
8
8
|
STATEMENT_TOKEN = "\n\n/\n\n"
|
9
9
|
|
10
10
|
def structure_dump #:nodoc:
|
11
|
-
sequences = select(<<~SQL.squish, "
|
12
|
-
SELECT
|
11
|
+
sequences = select(<<~SQL.squish, "SCHEMA")
|
12
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
|
13
|
+
sequence_name, min_value, max_value, increment_by, order_flag, cycle_flag
|
13
14
|
FROM all_sequences
|
14
15
|
where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
|
15
16
|
SQL
|
@@ -17,8 +18,8 @@ module ActiveRecord #:nodoc:
|
|
17
18
|
structure = sequences.map do |result|
|
18
19
|
"CREATE SEQUENCE #{quote_table_name(result["sequence_name"])} MINVALUE #{result["min_value"]} MAXVALUE #{result["max_value"]} INCREMENT BY #{result["increment_by"]} #{result["order_flag"] == 'Y' ? "ORDER" : "NOORDER"} #{result["cycle_flag"] == 'Y' ? "CYCLE" : "NOCYCLE"}"
|
19
20
|
end
|
20
|
-
tables = select_values(<<~SQL.squish, "
|
21
|
-
SELECT table_name FROM all_tables t
|
21
|
+
tables = select_values(<<~SQL.squish, "SCHEMA")
|
22
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables t
|
22
23
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
|
23
24
|
AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
|
24
25
|
WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
|
@@ -29,8 +30,8 @@ module ActiveRecord #:nodoc:
|
|
29
30
|
tables.each do |table_name|
|
30
31
|
virtual_columns = virtual_columns_for(table_name) if supports_virtual_columns?
|
31
32
|
ddl = +"CREATE#{ ' GLOBAL TEMPORARY' if temporary_table?(table_name)} TABLE \"#{table_name}\" (\n"
|
32
|
-
columns = select_all(<<~SQL.squish, "
|
33
|
-
SELECT column_name, data_type, data_length, char_used, char_length,
|
33
|
+
columns = select_all(<<~SQL.squish, "SCHEMA")
|
34
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_type, data_length, char_used, char_length,
|
34
35
|
data_precision, data_scale, data_default, nullable
|
35
36
|
FROM all_tab_columns
|
36
37
|
WHERE table_name = '#{table_name}'
|
@@ -54,8 +55,9 @@ module ActiveRecord #:nodoc:
|
|
54
55
|
structure << structure_dump_column_comments(table_name)
|
55
56
|
end
|
56
57
|
|
57
|
-
join_with_statement_token(structure) <<
|
58
|
-
|
58
|
+
join_with_statement_token(structure) <<
|
59
|
+
structure_dump_fk_constraints <<
|
60
|
+
structure_dump_views
|
59
61
|
end
|
60
62
|
|
61
63
|
def structure_dump_column(column) #:nodoc:
|
@@ -89,8 +91,8 @@ module ActiveRecord #:nodoc:
|
|
89
91
|
|
90
92
|
def structure_dump_primary_key(table) #:nodoc:
|
91
93
|
opts = { name: "", cols: [] }
|
92
|
-
pks = select_all(<<~SQL.squish, "
|
93
|
-
SELECT a.constraint_name, a.column_name, a.position
|
94
|
+
pks = select_all(<<~SQL.squish, "SCHEMA")
|
95
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position
|
94
96
|
FROM all_cons_columns a
|
95
97
|
JOIN all_constraints c
|
96
98
|
ON a.constraint_name = c.constraint_name
|
@@ -108,8 +110,8 @@ module ActiveRecord #:nodoc:
|
|
108
110
|
|
109
111
|
def structure_dump_unique_keys(table) #:nodoc:
|
110
112
|
keys = {}
|
111
|
-
uks = select_all(<<~SQL.squish, "
|
112
|
-
SELECT a.constraint_name, a.column_name, a.position
|
113
|
+
uks = select_all(<<~SQL.squish, "SCHEMA")
|
114
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position
|
113
115
|
FROM all_cons_columns a
|
114
116
|
JOIN all_constraints c
|
115
117
|
ON a.constraint_name = c.constraint_name
|
@@ -144,8 +146,8 @@ module ActiveRecord #:nodoc:
|
|
144
146
|
end
|
145
147
|
|
146
148
|
def structure_dump_fk_constraints #:nodoc:
|
147
|
-
foreign_keys = select_all(<<~SQL.squish, "
|
148
|
-
SELECT table_name FROM all_tables
|
149
|
+
foreign_keys = select_all(<<~SQL.squish, "SCHEMA")
|
150
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables
|
149
151
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
|
150
152
|
SQL
|
151
153
|
fks = foreign_keys.map do |table|
|
@@ -172,8 +174,8 @@ module ActiveRecord #:nodoc:
|
|
172
174
|
|
173
175
|
def structure_dump_column_comments(table_name)
|
174
176
|
comments = []
|
175
|
-
columns = select_values(<<~SQL.squish, "
|
176
|
-
SELECT column_name FROM user_tab_columns
|
177
|
+
columns = select_values(<<~SQL.squish, "SCHEMA")
|
178
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name FROM user_tab_columns
|
177
179
|
WHERE table_name = '#{table_name}' ORDER BY column_id
|
178
180
|
SQL
|
179
181
|
|
@@ -206,8 +208,8 @@ module ActiveRecord #:nodoc:
|
|
206
208
|
# Extract all stored procedures, packages, synonyms.
|
207
209
|
def structure_dump_db_stored_code #:nodoc:
|
208
210
|
structure = []
|
209
|
-
all_source = select_all(<<~SQL.squish, "
|
210
|
-
SELECT DISTINCT name, type
|
211
|
+
all_source = select_all(<<~SQL.squish, "SCHEMA")
|
212
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ DISTINCT name, type
|
211
213
|
FROM all_source
|
212
214
|
WHERE type IN ('PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION', 'TRIGGER', 'TYPE')
|
213
215
|
AND name NOT LIKE 'BIN$%'
|
@@ -216,7 +218,7 @@ module ActiveRecord #:nodoc:
|
|
216
218
|
all_source.each do |source|
|
217
219
|
ddl = +"CREATE OR REPLACE \n"
|
218
220
|
texts = select_all(<<~SQL.squish, "all source at structure dump")
|
219
|
-
SELECT text
|
221
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ text
|
220
222
|
FROM all_source
|
221
223
|
WHERE name = '#{source['name']}'
|
222
224
|
AND type = '#{source['type']}'
|
@@ -238,8 +240,8 @@ module ActiveRecord #:nodoc:
|
|
238
240
|
|
239
241
|
def structure_dump_views #:nodoc:
|
240
242
|
structure = []
|
241
|
-
views = select_all(<<~SQL.squish, "
|
242
|
-
SELECT view_name, text FROM all_views
|
243
|
+
views = select_all(<<~SQL.squish, "SCHEMA")
|
244
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ view_name, text FROM all_views
|
243
245
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY view_name ASC
|
244
246
|
SQL
|
245
247
|
views.each do |view|
|
@@ -250,8 +252,8 @@ module ActiveRecord #:nodoc:
|
|
250
252
|
|
251
253
|
def structure_dump_synonyms #:nodoc:
|
252
254
|
structure = []
|
253
|
-
synonyms = select_all(<<~SQL.squish, "
|
254
|
-
SELECT owner, synonym_name, table_name, table_owner
|
255
|
+
synonyms = select_all(<<~SQL.squish, "SCHEMA")
|
256
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, synonym_name, table_name, table_owner
|
255
257
|
FROM all_synonyms
|
256
258
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
257
259
|
SQL
|
@@ -263,14 +265,15 @@ module ActiveRecord #:nodoc:
|
|
263
265
|
end
|
264
266
|
|
265
267
|
def structure_drop #:nodoc:
|
266
|
-
sequences = select_values(<<~SQL.squish, "
|
267
|
-
SELECT
|
268
|
+
sequences = select_values(<<~SQL.squish, "SCHEMA")
|
269
|
+
SELECT/*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
|
270
|
+
sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
|
268
271
|
SQL
|
269
272
|
statements = sequences.map do |seq|
|
270
273
|
"DROP SEQUENCE \"#{seq}\""
|
271
274
|
end
|
272
|
-
tables = select_values(<<~SQL.squish, "
|
273
|
-
SELECT table_name from all_tables t
|
275
|
+
tables = select_values(<<~SQL.squish, "SCHEMA")
|
276
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name from all_tables t
|
274
277
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
|
275
278
|
AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
|
276
279
|
WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
|
@@ -285,8 +288,8 @@ module ActiveRecord #:nodoc:
|
|
285
288
|
end
|
286
289
|
|
287
290
|
def temp_table_drop #:nodoc:
|
288
|
-
temporary_tables = select_values(<<~SQL.squish, "
|
289
|
-
SELECT table_name FROM all_tables
|
291
|
+
temporary_tables = select_values(<<~SQL.squish, "SCHEMA")
|
292
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables
|
290
293
|
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
|
291
294
|
AND secondary = 'N' AND temporary = 'Y' ORDER BY 1
|
292
295
|
SQL
|
@@ -316,12 +319,11 @@ module ActiveRecord #:nodoc:
|
|
316
319
|
end
|
317
320
|
|
318
321
|
private
|
319
|
-
|
320
322
|
# Called only if `supports_virtual_columns?` returns true
|
321
323
|
# return [{'column_name' => 'FOOS', 'data_default' => '...'}, ...]
|
322
324
|
def virtual_columns_for(table)
|
323
|
-
select_all(<<~SQL.squish, "
|
324
|
-
SELECT column_name, data_default
|
325
|
+
select_all(<<~SQL.squish, "SCHEMA")
|
326
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_default
|
325
327
|
FROM all_tab_cols
|
326
328
|
WHERE virtual_column = 'YES'
|
327
329
|
AND owner = SYS_CONTEXT('userenv', 'current_schema')
|
@@ -331,8 +333,8 @@ module ActiveRecord #:nodoc:
|
|
331
333
|
|
332
334
|
def drop_sql_for_feature(type)
|
333
335
|
short_type = type == "materialized view" ? "mview" : type
|
334
|
-
features = select_values(<<~SQL.squish, "
|
335
|
-
SELECT #{short_type}_name FROM all_#{short_type.tableize}
|
336
|
+
features = select_values(<<~SQL.squish, "SCHEMA")
|
337
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ #{short_type}_name FROM all_#{short_type.tableize}
|
336
338
|
where owner = SYS_CONTEXT('userenv', 'current_schema')
|
337
339
|
SQL
|
338
340
|
statements = features.map do |name|
|
@@ -342,8 +344,8 @@ module ActiveRecord #:nodoc:
|
|
342
344
|
end
|
343
345
|
|
344
346
|
def drop_sql_for_object(type)
|
345
|
-
objects = select_values(<<~SQL.squish, "
|
346
|
-
SELECT object_name FROM all_objects
|
347
|
+
objects = select_values(<<~SQL.squish, "SCHEMA")
|
348
|
+
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ object_name FROM all_objects
|
347
349
|
WHERE object_type = '#{type.upcase}' and owner = SYS_CONTEXT('userenv', 'current_schema')
|
348
350
|
SQL
|
349
351
|
statements = objects.map do |name|
|