activerecord-oracle_enhanced-adapter 6.0.6 → 6.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +128 -4
  3. data/README.md +12 -1
  4. data/VERSION +1 -1
  5. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +2 -3
  6. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +0 -1
  7. data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +0 -9
  8. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +6 -6
  9. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +8 -9
  10. data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +0 -1
  11. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +7 -5
  12. data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +1 -2
  13. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +2 -3
  14. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +0 -1
  15. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +7 -11
  16. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +2 -3
  17. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +15 -3
  18. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +42 -39
  19. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +16 -17
  20. data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +2 -1
  21. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +52 -33
  22. data/lib/active_record/type/oracle_enhanced/boolean.rb +0 -1
  23. data/lib/active_record/type/oracle_enhanced/integer.rb +0 -1
  24. data/lib/arel/visitors/oracle.rb +217 -0
  25. data/lib/arel/visitors/oracle12.rb +124 -0
  26. data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +9 -3
  27. data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +5 -0
  28. data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +0 -1
  29. data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +27 -0
  30. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +83 -0
  31. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +4 -2
  32. data/spec/spec_config.yaml.template +2 -2
  33. data/spec/spec_helper.rb +13 -2
  34. metadata +6 -4
@@ -3,9 +3,8 @@
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  module OracleEnhanced
6
- class SchemaCreation < AbstractAdapter::SchemaCreation
6
+ class SchemaCreation < SchemaCreation
7
7
  private
8
-
9
8
  def visit_ColumnDefinition(o)
10
9
  if [:blob, :clob, :nclob].include?(sql_type = type_to_sql(o.type, **o.options).downcase.to_sym)
11
10
  if (tablespace = default_tablespace_for(sql_type))
@@ -36,7 +35,7 @@ module ActiveRecord
36
35
  create_sql << " TABLESPACE #{tablespace}"
37
36
  end
38
37
  end
39
- add_table_options!(create_sql, table_options(o))
38
+ add_table_options!(create_sql, o)
40
39
  create_sql << " AS #{to_sql(o.as)}" if o.as
41
40
  create_sql
42
41
  end
@@ -4,7 +4,15 @@ module ActiveRecord #:nodoc:
4
4
  module ConnectionAdapters #:nodoc:
5
5
  module OracleEnhanced #:nodoc:
6
6
  class SchemaDumper < ConnectionAdapters::SchemaDumper #:nodoc:
7
+ DEFAULT_PRIMARY_KEY_COLUMN_SPEC = { precision: "38", null: "false" }.freeze
8
+ private_constant :DEFAULT_PRIMARY_KEY_COLUMN_SPEC
9
+
7
10
  private
11
+ def column_spec_for_primary_key(column)
12
+ spec = super
13
+ spec.except!(:precision) if prepare_column_options(column) == DEFAULT_PRIMARY_KEY_COLUMN_SPEC
14
+ spec
15
+ end
8
16
 
9
17
  def tables(stream)
10
18
  # do not include materialized views in schema dump - they should be created separately after schema creation
@@ -51,6 +59,7 @@ module ActiveRecord #:nodoc:
51
59
  else
52
60
  statement_parts = [ ("add_context_index " + remove_prefix_and_suffix(table).inspect) ]
53
61
  statement_parts << index.columns.inspect
62
+ statement_parts << ("sync: " + $1.inspect) if index.parameters =~ /SYNC\((.*?)\)/
54
63
  statement_parts << ("name: " + index.name.inspect)
55
64
  end
56
65
  else
@@ -72,7 +81,7 @@ module ActiveRecord #:nodoc:
72
81
  index_statements = indexes.map do |index|
73
82
  " t.index #{index_parts(index).join(', ')}" unless index.type == "CTXSYS.CONTEXT"
74
83
  end
75
- stream.puts index_statements.sort.join("\n")
84
+ stream.puts index_statements.compact.sort.join("\n")
76
85
  end
77
86
  end
78
87
 
@@ -107,7 +116,10 @@ module ActiveRecord #:nodoc:
107
116
  tbl.print ", primary_key: #{pk.inspect}" unless pk == "id"
108
117
  pkcol = columns.detect { |c| c.name == pk }
109
118
  pkcolspec = column_spec_for_primary_key(pkcol)
110
- if pkcolspec.present?
119
+ unless pkcolspec.empty?
120
+ if pkcolspec != pkcolspec.slice(:id, :default)
121
+ pkcolspec = { id: { type: pkcolspec.delete(:id), **pkcolspec }.compact }
122
+ end
111
123
  tbl.print ", #{format_colspec(pkcolspec)}"
112
124
  end
113
125
  when Array
@@ -168,7 +180,7 @@ module ActiveRecord #:nodoc:
168
180
 
169
181
  def extract_expression_for_virtual_column(column)
170
182
  column_name = column.name
171
- @connection.select_value(<<~SQL.squish, "Table comment", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
183
+ @connection.select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
172
184
  select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ data_default from all_tab_columns
173
185
  where owner = SYS_CONTEXT('userenv', 'current_schema')
174
186
  and table_name = :table_name
@@ -11,7 +11,7 @@ module ActiveRecord
11
11
  # see: abstract/schema_statements.rb
12
12
 
13
13
  def tables #:nodoc:
14
- select_values(<<~SQL.squish, "tables")
14
+ select_values(<<~SQL.squish, "SCHEMA")
15
15
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
16
16
  DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name)
17
17
  FROM all_tables
@@ -44,7 +44,7 @@ module ActiveRecord
44
44
  table_owner, table_name = default_owner, real_name
45
45
  end
46
46
 
47
- select_values(<<~SQL.squish, "table exists", [bind_string("owner", table_owner), bind_string("table_name", table_name)]).any?
47
+ select_values(<<~SQL.squish, "SCHEMA", [bind_string("owner", table_owner), bind_string("table_name", table_name)]).any?
48
48
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, table_name
49
49
  FROM all_tables
50
50
  WHERE owner = :owner
@@ -60,14 +60,14 @@ module ActiveRecord
60
60
  end
61
61
 
62
62
  def views # :nodoc:
63
- select_values(<<~SQL.squish, "views")
63
+ select_values(<<~SQL.squish, "SCHEMA")
64
64
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
65
65
  LOWER(view_name) FROM all_views WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
66
66
  SQL
67
67
  end
68
68
 
69
69
  def materialized_views #:nodoc:
70
- select_values(<<~SQL.squish, "materialized views")
70
+ select_values(<<~SQL.squish, "SCHEMA")
71
71
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
72
72
  LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
73
73
  SQL
@@ -75,7 +75,7 @@ module ActiveRecord
75
75
 
76
76
  # get synonyms for schema dump
77
77
  def synonyms
78
- result = select_all(<<~SQL.squish, "synonyms")
78
+ result = select_all(<<~SQL.squish, "SCHEMA")
79
79
  SELECT synonym_name, table_owner, table_name
80
80
  FROM all_synonyms where owner = SYS_CONTEXT('userenv', 'current_schema')
81
81
  SQL
@@ -90,7 +90,7 @@ module ActiveRecord
90
90
  (_owner, table_name) = @connection.describe(table_name)
91
91
  default_tablespace_name = default_tablespace
92
92
 
93
- result = select_all(<<~SQL.squish, "indexes", [bind_string("table_name", table_name)])
93
+ result = select_all(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)])
94
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,
95
95
  i.index_type, i.ityp_owner, i.ityp_name, i.parameters,
96
96
  LOWER(i.tablespace_name) AS tablespace_name,
@@ -120,7 +120,7 @@ module ActiveRecord
120
120
  statement_parameters = nil
121
121
  if row["index_type"] == "DOMAIN" && row["ityp_owner"] == "CTXSYS" && row["ityp_name"] == "CONTEXT"
122
122
  procedure_name = default_datastore_procedure(row["index_name"])
123
- source = select_values(<<~SQL.squish, "procedure", [bind_string("procedure_name", procedure_name.upcase)]).join
123
+ source = select_values(<<~SQL.squish, "SCHEMA", [bind_string("procedure_name", procedure_name.upcase)]).join
124
124
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ text
125
125
  FROM all_source
126
126
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -199,19 +199,19 @@ module ActiveRecord
199
199
  # t.string :last_name, :comment => “Surname”
200
200
  # end
201
201
 
202
- def create_table(table_name, **options)
203
- create_sequence = options[:id] != false
204
- td = create_table_definition table_name, **options
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
+ )
205
207
 
206
- if options[:id] != false && !options[:as]
207
- pk = options.fetch(:primary_key) do
208
- Base.get_primary_key table_name.to_s.singularize
209
- end
208
+ if id && !td.as
209
+ pk = primary_key || Base.get_primary_key(table_name.to_s.singularize)
210
210
 
211
211
  if pk.is_a?(Array)
212
212
  td.primary_keys pk
213
213
  else
214
- td.primary_key pk, options.fetch(:id, :primary_key), **options
214
+ td.primary_key pk, id, **options
215
215
  end
216
216
  end
217
217
 
@@ -229,8 +229,10 @@ module ActiveRecord
229
229
  yield td if block_given?
230
230
  create_sequence = create_sequence || td.create_sequence
231
231
 
232
- if options[:force] && data_source_exists?(table_name)
233
- drop_table(table_name, options)
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)
234
236
  end
235
237
 
236
238
  execute schema_creation.accept td
@@ -238,14 +240,14 @@ module ActiveRecord
238
240
  create_sequence_and_trigger(table_name, options) if create_sequence
239
241
 
240
242
  if supports_comments? && !supports_comments_in_create?
241
- if table_comment = options[:comment].presence
243
+ if table_comment = td.comment.presence
242
244
  change_table_comment(table_name, table_comment)
243
245
  end
244
246
  td.columns.each do |column|
245
247
  change_column_comment(table_name, column.name, column.comment) if column.comment.present?
246
248
  end
247
249
  end
248
- td.indexes.each { |c, o| add_index table_name, c, o }
250
+ td.indexes.each { |c, o| add_index table_name, c, **o }
249
251
 
250
252
  rebuild_primary_key_index_to_default_tablespace(table_name, options)
251
253
  end
@@ -254,13 +256,16 @@ module ActiveRecord
254
256
  if new_name.to_s.length > DatabaseLimits::IDENTIFIER_MAX_LENGTH
255
257
  raise ArgumentError, "New table name '#{new_name}' is too long; the limit is #{DatabaseLimits::IDENTIFIER_MAX_LENGTH} characters"
256
258
  end
259
+ schema_cache.clear_data_source_cache!(table_name.to_s)
260
+ schema_cache.clear_data_source_cache!(new_name.to_s)
257
261
  execute "RENAME #{quote_table_name(table_name)} TO #{quote_table_name(new_name)}"
258
262
  execute "RENAME #{quote_table_name("#{table_name}_seq")} TO #{default_sequence_name(new_name)}" rescue nil
259
263
 
260
264
  rename_table_indexes(table_name, new_name)
261
265
  end
262
266
 
263
- def drop_table(table_name, options = {}) #:nodoc:
267
+ def drop_table(table_name, **options) #:nodoc:
268
+ schema_cache.clear_data_source_cache!(table_name.to_s)
264
269
  execute "DROP TABLE #{quote_table_name(table_name)}#{' CASCADE CONSTRAINTS' if options[:force] == :cascade}"
265
270
  seq_name = options[:sequence_name] || default_sequence_name(table_name)
266
271
  execute "DROP SEQUENCE #{quote_table_name(seq_name)}" rescue nil
@@ -290,7 +295,7 @@ module ActiveRecord
290
295
  end
291
296
  end
292
297
 
293
- def add_index(table_name, column_name, options = {}) #:nodoc:
298
+ def add_index(table_name, column_name, **options) #:nodoc:
294
299
  index_name, index_type, quoted_column_names, tablespace, index_options = add_index_options(table_name, column_name, **options)
295
300
  execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{quoted_column_names})#{tablespace} #{index_options}"
296
301
  if index_type == "UNIQUE"
@@ -309,13 +314,11 @@ module ActiveRecord
309
314
  index_type = options[:unique] ? "UNIQUE" : ""
310
315
  index_name = options[:name].to_s if options.key?(:name)
311
316
  tablespace = tablespace_for(:index, options[:tablespace])
312
- max_index_length = options.fetch(:internal, false) ? index_name_length : allowed_index_name_length
313
- # TODO: This option is used for NOLOGGING, needs better argumetn name
317
+ # TODO: This option is used for NOLOGGING, needs better argument name
314
318
  index_options = options[:options]
315
319
 
316
- if index_name.to_s.length > max_index_length
317
- raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{max_index_length} characters"
318
- end
320
+ validate_index_length!(table_name, index_name, options.fetch(:internal, false))
321
+
319
322
  if table_exists?(table_name) && index_name_exists?(table_name, index_name)
320
323
  raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
321
324
  end
@@ -326,8 +329,8 @@ module ActiveRecord
326
329
 
327
330
  # Remove the given index from the table.
328
331
  # Gives warning if index does not exist
329
- def remove_index(table_name, options = {}) #:nodoc:
330
- 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)
331
334
  # TODO: It should execute only when index_type == "UNIQUE"
332
335
  execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_column_name(index_name)}" rescue nil
333
336
  execute "DROP INDEX #{quote_column_name(index_name)}"
@@ -364,7 +367,7 @@ module ActiveRecord
364
367
  # Will always query database and not index cache.
365
368
  def index_name_exists?(table_name, index_name)
366
369
  (_owner, table_name) = @connection.describe(table_name)
367
- result = select_value(<<~SQL.squish, "index name exists")
370
+ result = select_value(<<~SQL.squish, "SCHEMA")
368
371
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ 1 FROM all_indexes i
369
372
  WHERE i.owner = SYS_CONTEXT('userenv', 'current_schema')
370
373
  AND i.table_owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -443,7 +446,7 @@ module ActiveRecord
443
446
  change_column table_name, column_name, column.sql_type, null: null
444
447
  end
445
448
 
446
- def change_column(table_name, column_name, type, options = {}) #:nodoc:
449
+ def change_column(table_name, column_name, type, **options) #:nodoc:
447
450
  column = column_for(table_name, column_name)
448
451
 
449
452
  # remove :null option if its value is the same as current column definition
@@ -497,8 +500,9 @@ module ActiveRecord
497
500
  end
498
501
 
499
502
  def table_comment(table_name) #:nodoc:
503
+ # TODO
500
504
  (_owner, table_name) = @connection.describe(table_name)
501
- select_value(<<~SQL.squish, "Table comment", [bind_string("table_name", table_name)])
505
+ select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)])
502
506
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_tab_comments
503
507
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
504
508
  AND table_name = :table_name
@@ -514,7 +518,7 @@ module ActiveRecord
514
518
  def column_comment(table_name, column_name) #:nodoc:
515
519
  # TODO: it does not exist in Abstract adapter
516
520
  (_owner, table_name) = @connection.describe(table_name)
517
- select_value(<<~SQL.squish, "Column comment", [bind_string("table_name", table_name), bind_string("column_name", column_name.upcase)])
521
+ select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name), bind_string("column_name", column_name.upcase)])
518
522
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_col_comments
519
523
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
520
524
  AND table_name = :table_name
@@ -531,7 +535,7 @@ module ActiveRecord
531
535
  end
532
536
 
533
537
  def tablespace(table_name)
534
- select_value(<<~SQL.squish, "tablespace")
538
+ select_value(<<~SQL.squish, "SCHEMA")
535
539
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ tablespace_name
536
540
  FROM all_tables
537
541
  WHERE table_name='#{table_name.to_s.upcase}'
@@ -543,7 +547,7 @@ module ActiveRecord
543
547
  def foreign_keys(table_name) #:nodoc:
544
548
  (_owner, desc_table_name) = @connection.describe(table_name)
545
549
 
546
- fk_info = select_all(<<~SQL.squish, "Foreign Keys", [bind_string("desc_table_name", desc_table_name)])
550
+ fk_info = select_all(<<~SQL.squish, "SCHEMA", [bind_string("desc_table_name", desc_table_name)])
547
551
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ r.table_name to_table
548
552
  ,rc.column_name references_column
549
553
  ,cc.column_name
@@ -585,7 +589,7 @@ module ActiveRecord
585
589
  # REFERENTIAL INTEGRITY ====================================
586
590
 
587
591
  def disable_referential_integrity(&block) #:nodoc:
588
- old_constraints = select_all(<<~SQL.squish, "Foreign Keys to disable and enable")
592
+ old_constraints = select_all(<<~SQL.squish, "SCHEMA")
589
593
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ constraint_name, owner, table_name
590
594
  FROM all_constraints
591
595
  WHERE constraint_type = 'R'
@@ -617,13 +621,12 @@ module ActiveRecord
617
621
  end
618
622
 
619
623
  private
620
-
621
624
  def schema_creation
622
625
  OracleEnhanced::SchemaCreation.new self
623
626
  end
624
627
 
625
- def create_table_definition(*args, **options)
626
- OracleEnhanced::TableDefinition.new(self, *args, **options)
628
+ def create_table_definition(name, **options)
629
+ OracleEnhanced::TableDefinition.new(self, name, **options)
627
630
  end
628
631
 
629
632
  def new_column_from_field(table_name, field)
@@ -645,7 +648,7 @@ module ActiveRecord
645
648
  # If a default contains a newline these cleanup regexes need to
646
649
  # match newlines.
647
650
  field["data_default"].sub!(/^'(.*)'$/m, '\1')
648
- field["data_default"] = nil if field["data_default"] =~ /^(null|empty_[bc]lob\(\))$/i
651
+ field["data_default"] = nil if /^(null|empty_[bc]lob\(\))$/i.match?(field["data_default"])
649
652
  # TODO: Needs better fix to fallback "N" to false
650
653
  field["data_default"] = false if field["data_default"] == "N" && OracleEnhancedAdapter.emulate_booleans_from_strings
651
654
  end
@@ -8,7 +8,7 @@ module ActiveRecord #:nodoc:
8
8
  STATEMENT_TOKEN = "\n\n/\n\n"
9
9
 
10
10
  def structure_dump #:nodoc:
11
- sequences = select(<<~SQL.squish, "sequences to dump at structure dump")
11
+ sequences = select(<<~SQL.squish, "SCHEMA")
12
12
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
13
13
  sequence_name, min_value, max_value, increment_by, order_flag, cycle_flag
14
14
  FROM all_sequences
@@ -18,7 +18,7 @@ module ActiveRecord #:nodoc:
18
18
  structure = sequences.map do |result|
19
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"}"
20
20
  end
21
- tables = select_values(<<~SQL.squish, "tables at structure dump")
21
+ tables = select_values(<<~SQL.squish, "SCHEMA")
22
22
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables t
23
23
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
24
24
  AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
@@ -30,7 +30,7 @@ module ActiveRecord #:nodoc:
30
30
  tables.each do |table_name|
31
31
  virtual_columns = virtual_columns_for(table_name) if supports_virtual_columns?
32
32
  ddl = +"CREATE#{ ' GLOBAL TEMPORARY' if temporary_table?(table_name)} TABLE \"#{table_name}\" (\n"
33
- columns = select_all(<<~SQL.squish, "columns at structure dump")
33
+ columns = select_all(<<~SQL.squish, "SCHEMA")
34
34
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_type, data_length, char_used, char_length,
35
35
  data_precision, data_scale, data_default, nullable
36
36
  FROM all_tab_columns
@@ -91,7 +91,7 @@ module ActiveRecord #:nodoc:
91
91
 
92
92
  def structure_dump_primary_key(table) #:nodoc:
93
93
  opts = { name: "", cols: [] }
94
- pks = select_all(<<~SQL.squish, "Primary Keys")
94
+ pks = select_all(<<~SQL.squish, "SCHEMA")
95
95
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position
96
96
  FROM all_cons_columns a
97
97
  JOIN all_constraints c
@@ -110,7 +110,7 @@ module ActiveRecord #:nodoc:
110
110
 
111
111
  def structure_dump_unique_keys(table) #:nodoc:
112
112
  keys = {}
113
- uks = select_all(<<~SQL.squish, "Primary Keys")
113
+ uks = select_all(<<~SQL.squish, "SCHEMA")
114
114
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position
115
115
  FROM all_cons_columns a
116
116
  JOIN all_constraints c
@@ -146,7 +146,7 @@ module ActiveRecord #:nodoc:
146
146
  end
147
147
 
148
148
  def structure_dump_fk_constraints #:nodoc:
149
- foreign_keys = select_all(<<~SQL.squish, "foreign keys at structure dump")
149
+ foreign_keys = select_all(<<~SQL.squish, "SCHEMA")
150
150
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables
151
151
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
152
152
  SQL
@@ -174,7 +174,7 @@ module ActiveRecord #:nodoc:
174
174
 
175
175
  def structure_dump_column_comments(table_name)
176
176
  comments = []
177
- columns = select_values(<<~SQL.squish, "column comments at structure dump")
177
+ columns = select_values(<<~SQL.squish, "SCHEMA")
178
178
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name FROM user_tab_columns
179
179
  WHERE table_name = '#{table_name}' ORDER BY column_id
180
180
  SQL
@@ -208,7 +208,7 @@ module ActiveRecord #:nodoc:
208
208
  # Extract all stored procedures, packages, synonyms.
209
209
  def structure_dump_db_stored_code #:nodoc:
210
210
  structure = []
211
- all_source = select_all(<<~SQL.squish, "stored program at structure dump")
211
+ all_source = select_all(<<~SQL.squish, "SCHEMA")
212
212
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ DISTINCT name, type
213
213
  FROM all_source
214
214
  WHERE type IN ('PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION', 'TRIGGER', 'TYPE')
@@ -240,7 +240,7 @@ module ActiveRecord #:nodoc:
240
240
 
241
241
  def structure_dump_views #:nodoc:
242
242
  structure = []
243
- views = select_all(<<~SQL.squish, "views at structure dump")
243
+ views = select_all(<<~SQL.squish, "SCHEMA")
244
244
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ view_name, text FROM all_views
245
245
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY view_name ASC
246
246
  SQL
@@ -252,7 +252,7 @@ module ActiveRecord #:nodoc:
252
252
 
253
253
  def structure_dump_synonyms #:nodoc:
254
254
  structure = []
255
- synonyms = select_all(<<~SQL.squish, "synonyms at structure dump")
255
+ synonyms = select_all(<<~SQL.squish, "SCHEMA")
256
256
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, synonym_name, table_name, table_owner
257
257
  FROM all_synonyms
258
258
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -265,14 +265,14 @@ module ActiveRecord #:nodoc:
265
265
  end
266
266
 
267
267
  def structure_drop #:nodoc:
268
- sequences = select_values(<<~SQL.squish, "sequences to drop at structure dump")
268
+ sequences = select_values(<<~SQL.squish, "SCHEMA")
269
269
  SELECT/*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
270
270
  sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
271
271
  SQL
272
272
  statements = sequences.map do |seq|
273
273
  "DROP SEQUENCE \"#{seq}\""
274
274
  end
275
- tables = select_values(<<~SQL.squish, "tables to drop at structure dump")
275
+ tables = select_values(<<~SQL.squish, "SCHEMA")
276
276
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name from all_tables t
277
277
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
278
278
  AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
@@ -288,7 +288,7 @@ module ActiveRecord #:nodoc:
288
288
  end
289
289
 
290
290
  def temp_table_drop #:nodoc:
291
- temporary_tables = select_values(<<~SQL.squish, "temporary tables to drop at structure dump")
291
+ temporary_tables = select_values(<<~SQL.squish, "SCHEMA")
292
292
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables
293
293
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
294
294
  AND secondary = 'N' AND temporary = 'Y' ORDER BY 1
@@ -319,11 +319,10 @@ module ActiveRecord #:nodoc:
319
319
  end
320
320
 
321
321
  private
322
-
323
322
  # Called only if `supports_virtual_columns?` returns true
324
323
  # return [{'column_name' => 'FOOS', 'data_default' => '...'}, ...]
325
324
  def virtual_columns_for(table)
326
- select_all(<<~SQL.squish, "virtual columns for")
325
+ select_all(<<~SQL.squish, "SCHEMA")
327
326
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_default
328
327
  FROM all_tab_cols
329
328
  WHERE virtual_column = 'YES'
@@ -334,7 +333,7 @@ module ActiveRecord #:nodoc:
334
333
 
335
334
  def drop_sql_for_feature(type)
336
335
  short_type = type == "materialized view" ? "mview" : type
337
- features = select_values(<<~SQL.squish, "features to drop")
336
+ features = select_values(<<~SQL.squish, "SCHEMA")
338
337
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ #{short_type}_name FROM all_#{short_type.tableize}
339
338
  where owner = SYS_CONTEXT('userenv', 'current_schema')
340
339
  SQL
@@ -345,7 +344,7 @@ module ActiveRecord #:nodoc:
345
344
  end
346
345
 
347
346
  def drop_sql_for_object(type)
348
- objects = select_values(<<~SQL.squish, "objects to drop")
347
+ objects = select_values(<<~SQL.squish, "SCHEMA")
349
348
  SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ object_name FROM all_objects
350
349
  WHERE object_type = '#{type.upcase}' and owner = SYS_CONTEXT('userenv', 'current_schema')
351
350
  SQL