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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +108 -0
  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 +9 -7
  9. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +4 -5
  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 +3 -4
  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 +2 -3
  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 +16 -4
  18. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +58 -52
  19. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +38 -36
  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 +64 -21
  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 +6 -1
  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/structure_dump_spec.rb +2 -2
  31. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +161 -0
  32. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +4 -2
  33. data/spec/spec_config.yaml.template +2 -2
  34. data/spec/spec_helper.rb +13 -2
  35. metadata +25 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecb6a81d928e0b751feb92c6eddbf1f11ae67ff269430216611f0d8871a3de7f
4
- data.tar.gz: 345cfa5a563fdb93d59404b13177bdf39f837f3d3338956b5b242ba85d95cca0
3
+ metadata.gz: ab0a6ce6d92c52ebd933c12bca31954f9493fcdcf21c32afdc979bad671ed227
4
+ data.tar.gz: d9b2710589287953fc425a86d04421d9b0e6eb6a3879984171c959ee12db84bf
5
5
  SHA512:
6
- metadata.gz: 44789c82df86d977714f00ef4a90b08c2d554c9e9b0cd3e2f39854ed89e69c02ade149990d1c16fe0630e91f0b13960e5263340d430e182f05791cabbb82d515
7
- data.tar.gz: c1dad68beacf2a519ab0819b41c3249902f64b6ba61c440aa0cc8f566d0e9820e12a4f45d2dd52e733a076c267016cf9fa895f7774f8b36c19c756b375f55a6b
6
+ metadata.gz: 7e8ef63fe7d7adc5af906fbf9d7494889e8a06ebda0c48e2837f17ef7164f0d7d520070b585c879127fca807c01b3970c48229d3c69551e07184b49bbd4d8b3b
7
+ data.tar.gz: d009447a01baadcd254e1fc4bceb3a6733e6bd587818db8ad657594c32bf9a17635abcd64f6aec4db3a70a0c4036b0aaa29b08e7a6651745f9d09d23bf938222
data/History.md CHANGED
@@ -1,3 +1,111 @@
1
+ ## 6.1.1 / 2021-01-14
2
+
3
+ * Changes and bug fixes
4
+ * Remove /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ hint for all_synonyms [#2110, #2119]
5
+ * Fix write_lobs Invalid byte sequence in UTF-8 [#2097, #2111]
6
+ * Ensure FKs are properly included in structure dumps [#2109, #2113]
7
+
8
+ * CI
9
+ * CI against JRuby 9.2.14.0 [#2085]
10
+ * CI against Ruby 3.0.0 [#2091, #2092]
11
+ * Address Travis CI warnings and bump Ubuntu version to 20.04 [#2086]
12
+ * Exclude `ruby-head` and `ruby-debug` until minitest allows Ruby 3.1 #2094, #2095
13
+ * CI against Ruby 3.0.0 at Travis CI [#2093]
14
+
15
+ ## 6.1.0 / 2020-12-15
16
+
17
+ * Changes and bug fixes
18
+ * Support Rails 6.1.0
19
+ * Update bug report templates for Oracle enhanced adapter 6.1 [#2063]
20
+ * Use released version of rake [#2065 #2066]
21
+ * Add /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ hint to address slow SCHEMA queries [#2055, #2068]
22
+ * `build_subselect` does not have ordering [#2070]
23
+ * Remove `visit_Arel_Nodes_NotIn` and `visit_Arel_Nodes_In` visitors [#2075, #2077]
24
+ * `NOT IN` clause needs separated by `AND` [#2079, #2081]
25
+
26
+ ## 6.1.0.rc1 / 2020-11-03
27
+
28
+ * Changes and bug fixes
29
+ * Support Rails 6.1.0.rc1
30
+ * Add support to change the permissions granted when creating DB [#1885]
31
+ * Refactor `create_table`'s options separation [#1886]
32
+ * Move schema cache to pool [#1888]
33
+ * Clear schema cache when a table is created/dropped/renamed [#1891]
34
+ * Deduplicate various Active Record schema cache structures [#1897]
35
+ * Support SQLCounter change to ignore "SCHEMA" and "TRANSACTION" log [#1892]
36
+ * Share the column and table name quote cache between connections [#1901]
37
+ * Add database_exists? method to connection adapters [#1906]
38
+ * Accept columns passed with options in remove_index [#1930]
39
+ * Fix `NameError` for `SchemaCreation` [#1933]
40
+ * Add `supports_common_table_expressions?` for CTE testing [#1946]
41
+ * create_table_definition and add_column take keyword arguments [#1942]
42
+ * Address `uninitialized constant ActiveRecord::ConnectionAdapters::AbstractAdapter::Quoting (NameError) [#1950]
43
+ * Fix an error when writing lobs [#1962]
44
+ * Uninstall SimpleCov [#1968]
45
+ * fix: Auto retry only works for connection.exec() [#1976]
46
+ * Fix keyword arguments errors for Ruby 2.8.0-dev [#1977]
47
+ * Fix a build errors when using Ruby 2.8.0-dev [#1983]
48
+ * Include sync option when dumping a context index [#1988]
49
+ * Use `build_result` instead of `ActiveRecord::Result.new` [#1994]
50
+ * Use the new API for build_results [#1995]
51
+ * Merge Arel visitors [#2002]
52
+ * Enable `Rails/IndexBy` and `Rails/IndexWith` cops [#2006]
53
+ * Don't refer `allowed_index_name_length` directly [#2009]
54
+ * Should not rely on the global `Arel::Table.engine` in the framework [#2010]
55
+ * Suppress `warning: already initialized constant` [#2011]
56
+ * Deprecate passing a column to `type_cast` [#2012]
57
+ * Limit number of expressions in a list during a "homogenous in" operation [#2013]
58
+ * Allow column name with function (e.g. `length(title)`) as safe SQL string [#2017]
59
+ * Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic [#2019]
60
+ * Separate primary key column options from table options [#2019]
61
+ * Make index options to kwargs [#2022]
62
+ * Make remaining migration options to kwargs [#2024]
63
+ * Allow TruffleRuby RUBY_ENGINE [#2046]
64
+ * Restore Schema Dumper behavior changed by #2019 [#2047]
65
+ * Support JDBC service name syntax [#2035]
66
+ * Use Rake 13.0.0.pre.1 [#1924]
67
+ * Bump RuboCop version to 0.71 [#1887]
68
+ * Bump RuboCop to 0.74.0 [#1914]
69
+ * Bump RuboCop to 0.76.0 [#1947]
70
+ * Use RuboCop 0.77 [#1959]
71
+ * Bump RuboCop to 0.82.0 [#2005]
72
+ * Suppress RuboCop's offenses [#2020]
73
+ * Enable `Layout/EmptyLinesAroundAccessModifier` cop [#1890]
74
+ * Disable `Style/BracesAroundHashParameters` cop [#1923]
75
+ * Enable `Layout/ClosingHeredocIndentation` cop [#1958]
76
+ * Unlock RuboCop gem versions [#1926]
77
+ * Enable `Rails/IndexBy` and `Rails/IndexWith` cops [#2006]
78
+ * Enable `Performance/DeletePrefix` and `Performance/DeleteSuffix` cops [#2021]
79
+ * Enable `Layout/SpaceAroundOperators` cop [#2057]
80
+ * Fix links to rails-dev-box running on docker [#1883]
81
+ * Fix spec config template copy instructions [#1884]
82
+ * Update UPGRADE section for Rails 5.2 [#1993]
83
+
84
+ * CI
85
+ * Enable GitHub Actions and run RuboCop [#1925]
86
+ * Run CI with GitHub Actions [#2015]
87
+ * Enabled Dependabot by creating .dependabot/config.yml [#1931]
88
+ * Disable Code Climate #1938
89
+ * CI against JRuby 9.2.8.0 [#1911]
90
+ * CI against JRuby 9.2.9.0 #1948
91
+ * CI against Ruby 2.6.4 and Ruby 2.5.6 [#1921]
92
+ * CI against Ruby 2.5.7 and Ruby 2.6.5 [#1949]
93
+ * CI against Ruby 2.7.0 [#1975]
94
+ * CI against JRuby 9.2.10.0 [#1989]
95
+ * CI against JRuby 9.2.11.0 [#1992]
96
+ * CI against JRuby 9.2.11.1 [#1997]
97
+ * CI againt Ruby 2.7.1, 2.6.6 and 2.5.8 #1998
98
+ * CI against JRuby 9.2.12.0 [#2034]
99
+ * Use Oracle Instant Client 18.5 [#2036]
100
+ * Support `jruby-head` again [#2037]
101
+ * CI against JRuby 9.2.13.0 [#2041]
102
+ * CI against Ruby 2.7.2 [#2052]
103
+ * Remove unnecessary PATH and LD_LIBRARY_PATH environment variables [#1927]
104
+ * Use Ubuntu 18.04 (Bionic Beaver) at Travis CI [#1937]
105
+ * Run bug report template at CI [#1936]
106
+ * Skip known failures until #1943 is resolved [#1961]
107
+ * Migrate to `ruby/setup-ruby` to use Ruby 2.7 [#2026]
108
+
1
109
  ## 6.0.4 / 2020-08-18
2
110
 
3
111
  * Changes and bug fixes
data/README.md CHANGED
@@ -10,6 +10,17 @@ Oracle enhanced ActiveRecord adapter provides Oracle database access from Ruby o
10
10
 
11
11
  INSTALLATION
12
12
  ------------
13
+ ### Rails 6.1
14
+
15
+ Oracle enhanced adapter version 6.1 supports Rails 6.1.
16
+ When using Ruby on Rails version 6.1 then in Gemfile include
17
+
18
+ ```ruby
19
+ # Use oracle as the database for Active Record
20
+ gem 'activerecord-oracle_enhanced-adapter', '~> 6.1.0'
21
+ gem 'ruby-oci8' # only for CRuby users
22
+ ```
23
+
13
24
  ### Rails 6.0
14
25
 
15
26
  Oracle enhanced adapter version 6.0 supports Rails 6.0.
@@ -663,7 +674,7 @@ if any database structure changed by migrations, execute `rails db:schema:cache:
663
674
 
664
675
  UPGRADE
665
676
  ---------------
666
- ### Upgrade Rails 5.0 or older version to Rails 5.2
677
+ ### Upgrade Rails 5.1 or older version to Rails 5.2
667
678
 
668
679
  * `emulate_booleans_from_strings = true` change
669
680
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.0.4
1
+ 6.1.1
@@ -19,7 +19,6 @@ module ActiveRecord
19
19
  attr_reader :raw_connection
20
20
 
21
21
  private
22
-
23
22
  # Used always by JDBC connection as well by OCI connection when describing tables over database link
24
23
  def describe(name)
25
24
  name = name.to_s
@@ -116,8 +115,8 @@ module ActiveRecord
116
115
  end
117
116
  end
118
117
 
119
- # if MRI or YARV
120
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
118
+ # if MRI or YARV or TruffleRuby
119
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "truffleruby"
121
120
  ORACLE_ENHANCED_CONNECTION = :oci
122
121
  require "active_record/connection_adapters/oracle_enhanced/oci_connection"
123
122
  # if JRuby
@@ -142,7 +142,6 @@ module ActiveRecord
142
142
  end
143
143
 
144
144
  private
145
-
146
145
  def create_datastore_procedure(table_name, procedure_name, column_names, options)
147
146
  quoted_table_name = quote_table_name(table_name)
148
147
  select_queries, column_names = column_names.partition { |c| c.to_s =~ /^\s*SELECT\s+/i }
@@ -25,15 +25,6 @@ module ActiveRecord
25
25
  end
26
26
  deprecate :column_name_length
27
27
 
28
- # Returns the maximum allowed length for an index name. This
29
- # limit is enforced by rails and Is less than or equal to
30
- # <tt>index_name_length</tt>. The gap between
31
- # <tt>index_name_length</tt> is to allow internal rails
32
- # opreations to use prefixes in temporary opreations.
33
- def allowed_index_name_length
34
- index_name_length
35
- end
36
-
37
28
  # the maximum length of an index name
38
29
  # supported by this database
39
30
  def index_name_length
@@ -42,7 +42,7 @@ module ActiveRecord
42
42
  cursor.exec
43
43
  end
44
44
 
45
- if (name == "EXPLAIN") && sql =~ /^EXPLAIN/
45
+ if (name == "EXPLAIN") && sql.start_with?("EXPLAIN")
46
46
  res = true
47
47
  else
48
48
  columns = cursor.get_col_names.map do |col_name|
@@ -53,7 +53,7 @@ module ActiveRecord
53
53
  while row = cursor.fetch(fetch_options)
54
54
  rows << row
55
55
  end
56
- res = ActiveRecord::Result.new(columns, rows)
56
+ res = build_result(columns: columns, rows: rows)
57
57
  end
58
58
 
59
59
  cursor.close unless cached
@@ -67,7 +67,7 @@ module ActiveRecord
67
67
 
68
68
  def explain(arel, binds = [])
69
69
  sql = "EXPLAIN PLAN FOR #{to_sql(arel, binds)}"
70
- return if sql =~ /FROM all_/
70
+ return if /FROM all_/.match?(sql)
71
71
  if ORACLE_ENHANCED_CONNECTION == :jdbc
72
72
  exec_query(sql, "EXPLAIN", binds)
73
73
  else
@@ -130,7 +130,7 @@ module ActiveRecord
130
130
  rows << [returning_id]
131
131
  end
132
132
  cursor.close unless cached
133
- ActiveRecord::Result.new(returning_id_col || [], rows)
133
+ build_result(columns: returning_id_col || [], rows: rows)
134
134
  end
135
135
  end
136
136
 
@@ -196,11 +196,11 @@ module ActiveRecord
196
196
  end
197
197
 
198
198
  def create_savepoint(name = current_savepoint_name) #:nodoc:
199
- execute("SAVEPOINT #{name}")
199
+ execute("SAVEPOINT #{name}", "TRANSACTION")
200
200
  end
201
201
 
202
202
  def exec_rollback_to_savepoint(name = current_savepoint_name) #:nodoc:
203
- execute("ROLLBACK TO #{name}")
203
+ execute("ROLLBACK TO #{name}", "TRANSACTION")
204
204
  end
205
205
 
206
206
  def release_savepoint(name = current_savepoint_name) #:nodoc:
@@ -254,9 +254,11 @@ module ActiveRecord
254
254
  columns.each do |col|
255
255
  value = attributes[col.name]
256
256
  # changed sequence of next two lines - should check if value is nil before converting to yaml
257
- next if value.blank?
257
+ next unless value
258
258
  if klass.attribute_types[col.name].is_a? Type::Serialized
259
259
  value = klass.attribute_types[col.name].serialize(value)
260
+ # value can be nil after serialization because ActiveRecord serializes [] and {} as nil
261
+ next unless value
260
262
  end
261
263
  uncached do
262
264
  unless lob_record = select_one(sql = <<~SQL.squish, "Writable Large Object")
@@ -27,11 +27,10 @@ module ActiveRecord
27
27
  raise e
28
28
  end
29
29
  end
30
- connection.execute "GRANT unlimited tablespace TO #{@config['username']}"
31
- connection.execute "GRANT create session TO #{@config['username']}"
32
- connection.execute "GRANT create table TO #{@config['username']}"
33
- connection.execute "GRANT create view TO #{@config['username']}"
34
- connection.execute "GRANT create sequence TO #{@config['username']}"
30
+
31
+ OracleEnhancedAdapter.permissions.each do |permission|
32
+ connection.execute "GRANT #{permission} TO #{@config['username']}"
33
+ end
35
34
  end
36
35
 
37
36
  def drop
@@ -31,7 +31,6 @@ module ActiveRecord
31
31
  end
32
32
 
33
33
  private
34
-
35
34
  def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil)
36
35
  super
37
36
  ensure
@@ -115,9 +115,9 @@ module ActiveRecord
115
115
  else
116
116
  unless database.match?(/^(\:|\/)/)
117
117
  # assume database is a SID if no colon or slash are supplied (backward-compatibility)
118
- database = ":#{database}"
118
+ database = "/#{database}"
119
119
  end
120
- url = config[:url] || "jdbc:oracle:thin:@#{host || 'localhost'}:#{port || 1521}#{database}"
120
+ url = config[:url] || "jdbc:oracle:thin:@//#{host || 'localhost'}:#{port || 1521}#{database}"
121
121
  end
122
122
 
123
123
  prefetch_rows = config[:prefetch_rows] || 100
@@ -238,7 +238,7 @@ module ActiveRecord
238
238
  begin
239
239
  yield if block_given?
240
240
  rescue Java::JavaSql::SQLException => e
241
- raise unless e.message =~ /^(Closed Connection|Io exception:|No more data to read from socket|IO Error:)/
241
+ raise unless /^(Closed Connection|Io exception:|No more data to read from socket|IO Error:)/.match?(e.message)
242
242
  @active = false
243
243
  raise unless should_retry
244
244
  should_retry = false
@@ -512,7 +512,6 @@ module ActiveRecord
512
512
  end
513
513
 
514
514
  private
515
-
516
515
  def lob_to_ruby_value(val)
517
516
  case val
518
517
  when ::Java::OracleSql::CLOB
@@ -18,13 +18,12 @@ module ActiveRecord #:nodoc:
18
18
  module ClassMethods
19
19
  def lob_columns
20
20
  columns.select do |column|
21
- column.sql_type_metadata.sql_type =~ /LOB$/
21
+ column.sql_type_metadata.sql_type.end_with?("LOB")
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
26
  private
27
-
28
27
  def enhanced_write_lobs
29
28
  if self.class.connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) &&
30
29
  !(self.class.custom_create_method || self.class.custom_update_method)
@@ -269,7 +269,6 @@ module ActiveRecord
269
269
  end
270
270
 
271
271
  private
272
-
273
272
  def date_without_time?(value)
274
273
  case value
275
274
  when OraDate
@@ -323,9 +322,9 @@ module ActiveRecord
323
322
  # connection using host, port and database name
324
323
  elsif host || port
325
324
  host ||= "localhost"
326
- host = "[#{host}]" if host =~ /^[^\[].*:/ # IPv6
325
+ host = "[#{host}]" if /^[^\[].*:/.match?(host) # IPv6
327
326
  port ||= 1521
328
- database = "/#{database}" unless database.match(/^\//)
327
+ database = "/#{database}" unless database.start_with?("/")
329
328
  "//#{host}:#{port}#{database}"
330
329
  # if no host is specified then assume that
331
330
  # database parameter is TNS alias or TNS connection string
@@ -97,7 +97,6 @@ module ActiveRecord #:nodoc:
97
97
  end
98
98
 
99
99
  private
100
-
101
100
  # Creates a record with custom create method
102
101
  # and returns its id.
103
102
  def _create_record
@@ -169,7 +169,6 @@ module ActiveRecord
169
169
  private_constant :COLUMN_NAME, :COLUMN_NAME_WITH_ORDER
170
170
 
171
171
  private
172
-
173
172
  def oracle_downcase(column_name)
174
173
  return nil if column_name.nil?
175
174
  /[a-z]/.match?(column_name) ? column_name : column_name.downcase
@@ -179,8 +178,8 @@ module ActiveRecord
179
178
  end
180
179
  end
181
180
 
182
- # if MRI or YARV
183
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
181
+ # if MRI or YARV or TruffleRuby
182
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "truffleruby"
184
183
  require "active_record/connection_adapters/oracle_enhanced/oci_quoting"
185
184
  # if JRuby
186
185
  elsif RUBY_ENGINE == "jruby"
@@ -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,8 +180,8 @@ 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
172
- select data_default from all_tab_columns
183
+ @connection.select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
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
175
187
  and column_name = :column_name