activerecord-oracle_enhanced-adapter 6.0.5 → 6.1.2

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 +109 -4
  3. data/README.md +12 -1
  4. data/VERSION +1 -1
  5. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +3 -4
  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 +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 +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 +15 -3
  18. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +43 -40
  19. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +19 -19
  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/structure_dump_spec.rb +2 -2
  31. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +122 -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 +22 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c17fca6feaefdeefe04446c769a721e5f26b6f2ed254bef6f3bdee85a66b222
4
- data.tar.gz: 5d975d115515ccbacb1b540dc8ece885f218213128d462536df3023b0112bbe2
3
+ metadata.gz: fe153e95c0604a0c3c4d99c15e96122be421cf0ae458508cd0177a57434afe9e
4
+ data.tar.gz: 4d0bb45de045b0a51dfdd4c7328ad64999c2b4494e10791f361ae95f7d805523
5
5
  SHA512:
6
- metadata.gz: a736592361bc80d4930bbd0a2b21680dd1458400c66832c401f164c1effe9179e5a0771c5877b70df6286ef05ec81f71d8f1a96b1479c43f1b3f9d2b7d46c55e
7
- data.tar.gz: 158dd74c1af746d0295b593ad62bedaa656374740151b4fb99342d9f33eedef8ed85f42b3e9622ab9289938f1b62c8e37a4eeca87f39a2779a42081e65d09bb4
6
+ metadata.gz: 1d692b70253c15a57353fe49cb6a576b067c00614fba6ed6f6eaef5169364c5e1899c0e69c9c8259224d9b7d6e0c1ac4299a31dad812403c51c41bbfeb90bfb3
7
+ data.tar.gz: 7f1b51e8ced3139c1a380804b772113ae3004d045de9c4b2c1632b833364b06f434b4b10446fc3a60290578f44fca2dde368227a25cfa4aefdaa101404baf252
data/History.md CHANGED
@@ -1,9 +1,114 @@
1
- ## 6.0.5 / 2020-12-17
1
+ ## 6.1.2 / 2021-02-10
2
+ * Changes and bug fixes
3
+ * Fixed ORA-01935: missing user or role name with config read issue [#1943 #2135, #2142]
4
+
5
+ ## 6.1.1 / 2021-01-14
6
+
7
+ * Changes and bug fixes
8
+ * Remove /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ hint for all_synonyms [#2110, #2119]
9
+ * Fix write_lobs Invalid byte sequence in UTF-8 [#2097, #2111]
10
+ * Ensure FKs are properly included in structure dumps [#2109, #2113]
11
+
12
+ * CI
13
+ * CI against JRuby 9.2.14.0 [#2085]
14
+ * CI against Ruby 3.0.0 [#2091, #2092]
15
+ * Address Travis CI warnings and bump Ubuntu version to 20.04 [#2086]
16
+ * Exclude `ruby-head` and `ruby-debug` until minitest allows Ruby 3.1 #2094, #2095
17
+ * CI against Ruby 3.0.0 at Travis CI [#2093]
18
+
19
+ ## 6.1.0 / 2020-12-15
2
20
 
3
21
  * Changes and bug fixes
4
- * Address `next_sequence_value` ArgumentError syntax [#2048 #2050]
5
- * Add /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ hint to address slow SCHEMA queries [#2055, #2069]
6
- * `build_subselect` does not have ordering [#2023, #2070, #2073]
22
+ * Support Rails 6.1.0
23
+ * Update bug report templates for Oracle enhanced adapter 6.1 [#2063]
24
+ * Use released version of rake [#2065 #2066]
25
+ * Add /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ hint to address slow SCHEMA queries [#2055, #2068]
26
+ * `build_subselect` does not have ordering [#2070]
27
+ * Remove `visit_Arel_Nodes_NotIn` and `visit_Arel_Nodes_In` visitors [#2075, #2077]
28
+ * `NOT IN` clause needs separated by `AND` [#2079, #2081]
29
+
30
+ ## 6.1.0.rc1 / 2020-11-03
31
+
32
+ * Changes and bug fixes
33
+ * Support Rails 6.1.0.rc1
34
+ * Add support to change the permissions granted when creating DB [#1885]
35
+ * Refactor `create_table`'s options separation [#1886]
36
+ * Move schema cache to pool [#1888]
37
+ * Clear schema cache when a table is created/dropped/renamed [#1891]
38
+ * Deduplicate various Active Record schema cache structures [#1897]
39
+ * Support SQLCounter change to ignore "SCHEMA" and "TRANSACTION" log [#1892]
40
+ * Share the column and table name quote cache between connections [#1901]
41
+ * Add database_exists? method to connection adapters [#1906]
42
+ * Accept columns passed with options in remove_index [#1930]
43
+ * Fix `NameError` for `SchemaCreation` [#1933]
44
+ * Add `supports_common_table_expressions?` for CTE testing [#1946]
45
+ * create_table_definition and add_column take keyword arguments [#1942]
46
+ * Address `uninitialized constant ActiveRecord::ConnectionAdapters::AbstractAdapter::Quoting (NameError) [#1950]
47
+ * Fix an error when writing lobs [#1962]
48
+ * Uninstall SimpleCov [#1968]
49
+ * fix: Auto retry only works for connection.exec() [#1976]
50
+ * Fix keyword arguments errors for Ruby 2.8.0-dev [#1977]
51
+ * Fix a build errors when using Ruby 2.8.0-dev [#1983]
52
+ * Include sync option when dumping a context index [#1988]
53
+ * Use `build_result` instead of `ActiveRecord::Result.new` [#1994]
54
+ * Use the new API for build_results [#1995]
55
+ * Merge Arel visitors [#2002]
56
+ * Enable `Rails/IndexBy` and `Rails/IndexWith` cops [#2006]
57
+ * Don't refer `allowed_index_name_length` directly [#2009]
58
+ * Should not rely on the global `Arel::Table.engine` in the framework [#2010]
59
+ * Suppress `warning: already initialized constant` [#2011]
60
+ * Deprecate passing a column to `type_cast` [#2012]
61
+ * Limit number of expressions in a list during a "homogenous in" operation [#2013]
62
+ * Allow column name with function (e.g. `length(title)`) as safe SQL string [#2017]
63
+ * Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic [#2019]
64
+ * Separate primary key column options from table options [#2019]
65
+ * Make index options to kwargs [#2022]
66
+ * Make remaining migration options to kwargs [#2024]
67
+ * Allow TruffleRuby RUBY_ENGINE [#2046]
68
+ * Restore Schema Dumper behavior changed by #2019 [#2047]
69
+ * Support JDBC service name syntax [#2035]
70
+ * Use Rake 13.0.0.pre.1 [#1924]
71
+ * Bump RuboCop version to 0.71 [#1887]
72
+ * Bump RuboCop to 0.74.0 [#1914]
73
+ * Bump RuboCop to 0.76.0 [#1947]
74
+ * Use RuboCop 0.77 [#1959]
75
+ * Bump RuboCop to 0.82.0 [#2005]
76
+ * Suppress RuboCop's offenses [#2020]
77
+ * Enable `Layout/EmptyLinesAroundAccessModifier` cop [#1890]
78
+ * Disable `Style/BracesAroundHashParameters` cop [#1923]
79
+ * Enable `Layout/ClosingHeredocIndentation` cop [#1958]
80
+ * Unlock RuboCop gem versions [#1926]
81
+ * Enable `Rails/IndexBy` and `Rails/IndexWith` cops [#2006]
82
+ * Enable `Performance/DeletePrefix` and `Performance/DeleteSuffix` cops [#2021]
83
+ * Enable `Layout/SpaceAroundOperators` cop [#2057]
84
+ * Fix links to rails-dev-box running on docker [#1883]
85
+ * Fix spec config template copy instructions [#1884]
86
+ * Update UPGRADE section for Rails 5.2 [#1993]
87
+
88
+ * CI
89
+ * Enable GitHub Actions and run RuboCop [#1925]
90
+ * Run CI with GitHub Actions [#2015]
91
+ * Enabled Dependabot by creating .dependabot/config.yml [#1931]
92
+ * Disable Code Climate #1938
93
+ * CI against JRuby 9.2.8.0 [#1911]
94
+ * CI against JRuby 9.2.9.0 #1948
95
+ * CI against Ruby 2.6.4 and Ruby 2.5.6 [#1921]
96
+ * CI against Ruby 2.5.7 and Ruby 2.6.5 [#1949]
97
+ * CI against Ruby 2.7.0 [#1975]
98
+ * CI against JRuby 9.2.10.0 [#1989]
99
+ * CI against JRuby 9.2.11.0 [#1992]
100
+ * CI against JRuby 9.2.11.1 [#1997]
101
+ * CI againt Ruby 2.7.1, 2.6.6 and 2.5.8 #1998
102
+ * CI against JRuby 9.2.12.0 [#2034]
103
+ * Use Oracle Instant Client 18.5 [#2036]
104
+ * Support `jruby-head` again [#2037]
105
+ * CI against JRuby 9.2.13.0 [#2041]
106
+ * CI against Ruby 2.7.2 [#2052]
107
+ * Remove unnecessary PATH and LD_LIBRARY_PATH environment variables [#1927]
108
+ * Use Ubuntu 18.04 (Bionic Beaver) at Travis CI [#1937]
109
+ * Run bug report template at CI [#1936]
110
+ * Skip known failures until #1943 is resolved [#1961]
111
+ * Migrate to `ruby/setup-ruby` to use Ruby 2.7 [#2026]
7
112
 
8
113
  ## 6.0.4 / 2020-08-18
9
114
 
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.5
1
+ 6.1.2
@@ -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
@@ -35,7 +34,7 @@ module ActiveRecord
35
34
  table_owner, table_name = default_owner, real_name
36
35
  end
37
36
  sql = <<~SQL.squish
38
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, table_name, 'TABLE' name_type
37
+ SELECT owner, table_name, 'TABLE' name_type
39
38
  FROM all_tables
40
39
  WHERE owner = '#{table_owner}'
41
40
  AND table_name = '#{table_name}'
@@ -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")
@@ -17,21 +17,20 @@ module ActiveRecord
17
17
  print "Please provide the SYSTEM password for your Oracle installation (set ORACLE_SYSTEM_PASSWORD to avoid this prompt)\n>"
18
18
  $stdin.gets.strip
19
19
  }
20
- establish_connection(@config.merge("username" => "SYSTEM", "password" => system_password))
20
+ establish_connection(@config.merge(username: "SYSTEM", password: system_password))
21
21
  begin
22
- connection.execute "CREATE USER #{@config['username']} IDENTIFIED BY #{@config['password']}"
22
+ connection.execute "CREATE USER #{@config[:username]} IDENTIFIED BY #{@config[:password]}"
23
23
  rescue => e
24
24
  if /ORA-01920/.match?(e.message) # user name conflicts with another user or role name
25
- connection.execute "ALTER USER #{@config['username']} IDENTIFIED BY #{@config['password']}"
25
+ connection.execute "ALTER USER #{@config[:username]} IDENTIFIED BY #{@config[:password]}"
26
26
  else
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
@@ -47,7 +46,7 @@ module ActiveRecord
47
46
  def structure_dump(filename, extra_flags)
48
47
  establish_connection(@config)
49
48
  File.open(filename, "w:utf-8") { |f| f << connection.structure_dump }
50
- if @config["structure_dump"] == "db_stored_code"
49
+ if @config[:structure_dump] == "db_stored_code"
51
50
  File.open(filename, "a") { |f| f << connection.structure_dump_db_stored_code }
52
51
  end
53
52
  end
@@ -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,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