activerecord-oracle_enhanced-adapter-monky_patch_755 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 126a4ca05008abafa013f727d12b1e63d8cc93a1
4
- data.tar.gz: 356e802ba546bf6aa21d9d9d26d5464a6010757d
3
+ metadata.gz: 5f4ae731eb481175433c8d957add4457c1fdb359
4
+ data.tar.gz: e61dcaa85b1a36bd231863e7349394e2c275c589
5
5
  SHA512:
6
- metadata.gz: 67a203db760816d586498789b00a35a94dda46c007073266ee726b239413377c8514cccd2bfa87bc1a838f45707d432505b5f4a6c7a8055d9e6b6661c0f05e62
7
- data.tar.gz: 8e143df1032a05f846c2fbbadfa0e93298e71f5d697acd5eab5789ece32f96f0ec93c9042d97ab51b75313961bc71749d4b7e149388db50e8cc9f5ee03c5acc8
6
+ metadata.gz: 17dae0dd78ec2bed3b9dfe4249c92ed7bd755244dc05132a12bc66b9afe254728373e71d65156a5931cafbd90d1962b75e2b38ccf8a982fa70cdc8160d5e42ae
7
+ data.tar.gz: e56022b35d084c5a935eacba0c8b794a121315309fd5800cab9d7668f2097ff63e87f5bc3599c51b7b8b1c28c8df2bf81a7f423de16f5a03677894737eac4000
data/README.md CHANGED
@@ -26,8 +26,8 @@ $ gem install activerecord-oracle_enhanced-adapter-monky_patch_755
26
26
 
27
27
  ## Target
28
28
 
29
- * 'activerecord', '=> 4.2.1'
30
- * 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
29
+ * 'activerecord', '>= 4.2.1'
30
+ * 'activerecord-oracle_enhanced-adapter', '>= 1.6.0'
31
31
 
32
32
  ## Motivation
33
33
 
@@ -1,6 +1,11 @@
1
- case Rails::VERSION::MAJOR
2
- when 4; require 'activerecord/monkey_patch/rails4'
3
- when 5; require 'activerecord/monkey_patch/rails5'
1
+ if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2
2
+ require 'activerecord/monkey_patch/rails4_2'
3
+ elsif ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 0
4
+ require 'activerecord/monkey_patch/rails5_0'
5
+ elsif ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 1
6
+ require 'activerecord/monkey_patch/rails5_1'
7
+ else
8
+ raise "Unsupported version of Active Record: #{ActiveRecord.version}"
4
9
  end
5
10
 
6
11
  #
@@ -18,12 +18,42 @@ module ActiveRecord
18
18
  end
19
19
 
20
20
  module ConnectionAdapters
21
- #
22
- # Original code is the following URL.
23
- #
24
- # https://github.com/rsim/oracle-enhanced/blob/rails5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb#L938
25
- #
26
21
  class OracleEnhancedAdapter
22
+ #
23
+ # `supports_datetime_with_precision?` method and `native_database_types` method are overwriting
24
+ # the mapping between Rails and Oracle type to match Rails 4.2 behavior.
25
+ #
26
+ # The following is the SQL type when generating datetime column.
27
+ #
28
+ # - Rails 5 ... `TIMESTAMP(6)' SQL type.
29
+ # - Rails 4 ... `DATE' SQL type. ***This is the behavior of the monkey patch***.
30
+ #
31
+ # Original code is the following URL.
32
+ #
33
+ # https://github.com/rsim/oracle-enhanced/blob/v1.7.9/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb#L521
34
+ #
35
+ def supports_datetime_with_precision?
36
+ false
37
+ end
38
+
39
+ def native_database_types
40
+ native_database_types_patch = {
41
+ datetime: { name: "DATE" },
42
+ time: { name: "DATE" }
43
+ }
44
+
45
+ if emulate_booleans_from_strings
46
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS.dup.merge(native_database_types_patch)
47
+ else
48
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::NATIVE_DATABASE_TYPES.dup.merge(native_database_types_patch)
49
+ end
50
+ end
51
+
52
+ #
53
+ # Original code is the following URL.
54
+ #
55
+ # https://github.com/rsim/oracle-enhanced/blob/rails5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb#L938
56
+ #
27
57
  def columns_without_cache(table_name, name = nil) #:nodoc:
28
58
  table_name = table_name.to_s
29
59
  # get ignored_columns by original table name
@@ -106,6 +136,34 @@ module ActiveRecord
106
136
  end
107
137
 
108
138
  module OracleEnhanced
139
+ #
140
+ # This is a monkey patch to the problem below.
141
+ # As a result of `rails db:schema:dump`, the `DATE` type column expects to return `t.datetime :created_at`.
142
+ # But actually `t.date :created_at` is returned.
143
+ #
144
+ # Perhaps, converting the `DATE` type created in Rails 4 to `TIMESTAMP(6)` type that is used in Rails 5 makes
145
+ # this monkey patch unnecessary.
146
+ #
147
+ # Original code is the following URL.
148
+ #
149
+ # https://github.com/rsim/oracle-enhanced/blob/v1.7.9/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb#L5-L14
150
+ #
151
+ module ColumnDumper
152
+ def column_spec(column)
153
+ spec = Hash[prepare_column_options(column).map { |k, v| [k, "#{k}: #{v}"] }]
154
+ spec[:name] = column.name.inspect
155
+ if column.virtual?
156
+ spec[:type] = "virtual"
157
+ else
158
+ spec[:type] = schema_type(column).to_s
159
+ end
160
+
161
+ spec[:type] = "datetime" if spec[:type] == "date" # *** This line includes a monky patch condition. ***
162
+
163
+ spec
164
+ end
165
+ end
166
+
109
167
  #
110
168
  # Original code is the following URL.
111
169
  #
@@ -0,0 +1,242 @@
1
+ module ActiveRecord
2
+ module MonkeyPatch
3
+ SUPPORTED_MAJOR_VERSION = 5
4
+ MINIMUM_SUPPORTED_VERSION = '5.1.0'.freeze
5
+ end
6
+
7
+ module ConnectionAdapters
8
+ #
9
+ # This is a monkey patch to the problem below.
10
+ # As a result of `rails db:schema:dump`, the `DATE` type column expects to return `t.datetime :created_at`.
11
+ # But actually `t.date :created_at` is returned.
12
+ #
13
+ # Perhaps, converting the `DATE` type created in Rails 4 to `TIMESTAMP(6)` type that is used in Rails 5 makes
14
+ # this monkey patch unnecessary.
15
+ #
16
+ # Original code is the following URL.
17
+ #
18
+ # https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb#L9-L11
19
+ #
20
+ module ColumnDumper
21
+ def column_spec(column)
22
+ # The following 2 lines are a main monkey patch in this method.
23
+ spec = Hash[prepare_column_options(column).map { |k, v| [k, "#{k}: #{v}"] }]
24
+
25
+ schema_type = (column.type == :date) ? :datetime : schema_type_with_virtual(column)
26
+
27
+ [schema_type, prepare_column_options(column)]
28
+ end
29
+ end
30
+
31
+ class OracleEnhancedAdapter
32
+ #
33
+ # `supports_datetime_with_precision?` method and `native_database_types` method are overwriting
34
+ # the mapping between Rails and Oracle type to match Rails 4.2 behavior.
35
+ #
36
+ # The following is the SQL type when generating datetime column.
37
+ #
38
+ # - Rails 5 ... `TIMESTAMP(6)' SQL type.
39
+ # - Rails 4 ... `DATE' SQL type. ***This is the behavior of the monkey patch***.
40
+ #
41
+ # Original code is the following URL.
42
+ #
43
+ # https://github.com/rsim/oracle-enhanced/blob/v1.8.0.rc1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb#L336
44
+ #
45
+ def supports_datetime_with_precision?
46
+ false
47
+ end
48
+
49
+ def native_database_types
50
+ native_database_types_patch = {
51
+ datetime: { name: "DATE" },
52
+ time: { name: "DATE" }
53
+ }
54
+
55
+ if emulate_booleans_from_strings
56
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS.dup.merge(native_database_types_patch)
57
+ else
58
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::NATIVE_DATABASE_TYPES.dup.merge(native_database_types_patch)
59
+ end
60
+ end
61
+
62
+ #
63
+ # Original code is the following URL.
64
+ #
65
+ # https://github.com/rsim/oracle-enhanced/blob/v1.8.0.beta1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb#L735-L801
66
+ #
67
+ def columns_without_cache(table_name, name = nil) #:nodoc:
68
+ table_name = table_name.to_s
69
+
70
+ (owner, desc_table_name, db_link) = @connection.describe(table_name)
71
+
72
+ # reset do_not_prefetch_primary_key cache for this table
73
+ @@do_not_prefetch_primary_key[table_name] = nil
74
+
75
+ table_cols = <<-SQL.strip.gsub(/\s+/, " ")
76
+ SELECT cols.column_name AS name, cols.data_type AS sql_type,
77
+ cols.data_default, cols.nullable, cols.virtual_column, cols.hidden_column,
78
+ cols.data_type_owner AS sql_type_owner,
79
+ DECODE(cols.data_type, 'NUMBER', data_precision,
80
+ 'FLOAT', data_precision,
81
+ 'VARCHAR2', DECODE(char_used, 'C', char_length, data_length),
82
+ 'RAW', DECODE(char_used, 'C', char_length, data_length),
83
+ 'CHAR', DECODE(char_used, 'C', char_length, data_length),
84
+ NULL) AS limit,
85
+ DECODE(data_type, 'NUMBER', data_scale, NULL) AS scale,
86
+ comments.comments as column_comment
87
+ FROM all_tab_cols#{db_link} cols, all_col_comments#{db_link} comments
88
+ WHERE cols.owner = '#{owner}'
89
+ AND cols.table_name = #{quote(desc_table_name)}
90
+ AND cols.hidden_column = 'NO'
91
+ AND cols.owner = comments.owner
92
+ AND cols.table_name = comments.table_name
93
+ AND cols.column_name = comments.column_name
94
+ ORDER BY cols.column_id
95
+ SQL
96
+
97
+ # added deletion of ignored columns
98
+ select_all(table_cols, name).to_a.map do |row|
99
+ limit, scale = row["limit"], row["scale"]
100
+ if limit || scale
101
+ row["sql_type"] += "(#{(limit || 38).to_i}" + ((scale = scale.to_i) > 0 ? ",#{scale})" : ")")
102
+ end
103
+
104
+ if row["sql_type_owner"]
105
+ row["sql_type"] = row["sql_type_owner"] + "." + row["sql_type"]
106
+ end
107
+
108
+ is_virtual = row["virtual_column"] == "YES"
109
+
110
+ # clean up odd default spacing from Oracle
111
+ if row["data_default"] && !is_virtual
112
+ row["data_default"].sub!(/^(.*?)\s*$/, '\1')
113
+
114
+ # If a default contains a newline these cleanup regexes need to
115
+ # match newlines.
116
+ row["data_default"].sub!(/^'(.*)'$/m, '\1')
117
+ row["data_default"] = nil if row["data_default"] =~ /^(null|empty_[bc]lob\(\))$/i
118
+ # TODO: Needs better fix to fallback "N" to false
119
+ row["data_default"] = false if (row["data_default"] == "N" && OracleEnhancedAdapter.emulate_booleans_from_strings)
120
+ end
121
+
122
+ type_metadata = fetch_type_metadata(row["sql_type"])
123
+
124
+ # *** Its a monkey patch paragraph. ***
125
+ if /date/i === type_metadata.sql_type
126
+ if type_metadata.type == :date
127
+ type_metadata.instance_eval('@sql_type = "DATETIME"')
128
+ end
129
+ end
130
+
131
+ new_column(oracle_downcase(row["name"]),
132
+ row["data_default"],
133
+ type_metadata,
134
+ row["nullable"] == "Y",
135
+ table_name,
136
+ is_virtual,
137
+ false,
138
+ row["column_comment"]
139
+ )
140
+ end
141
+ end
142
+ end
143
+
144
+ module OracleEnhanced
145
+ module Quoting
146
+ #
147
+ # Original code has been removed.
148
+ #
149
+ # https://github.com/rsim/oracle-enhanced/commit/28dd91ccbbbf8e1e313ba816257ad281860f100b
150
+ #
151
+ def quote(value)
152
+ case value
153
+ when ::Date, ::Time, ::DateTime # *** Its a monky patch condition. ***
154
+ if value.acts_like?(:time)
155
+ zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
156
+
157
+ if value.respond_to?(zone_conversion_method)
158
+ value = value.send(zone_conversion_method)
159
+ end
160
+ end
161
+
162
+ "'#{value.to_s(:db)}'"
163
+ else
164
+ super
165
+ end
166
+ end
167
+
168
+ #
169
+ # Follow up to https://github.com/rsim/oracle-enhanced/pull/1267/commits/f26432f679fb836f4f4d72f6a7e9999da175ac91
170
+ #
171
+ def _type_cast(value)
172
+ case value
173
+ when Date, Time # *** Its a monky patch condition. ***
174
+ if value.acts_like?(:time)
175
+ zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
176
+ value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
177
+ else
178
+ value
179
+ end
180
+ when ActiveRecord::OracleEnhanced::Type::NationalCharacterString::Data
181
+ value.to_s
182
+ else
183
+ super
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+ #
191
+ # Original code is the following URL.
192
+ #
193
+ # https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/relation/where_clause_factory.rb
194
+ #
195
+ class Relation
196
+ class WhereClauseFactory
197
+
198
+ def build(opts, other)
199
+ binds = []
200
+
201
+ case opts
202
+ when String, Array
203
+ parts = [klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
204
+ when Hash
205
+ opts = ActiveRecord::MonkeyPatch.adjust_timezone_offset(opts)
206
+
207
+ attributes = predicate_builder.resolve_column_aliases(opts)
208
+ attributes = klass.send(:expand_hash_conditions_for_aggregates, attributes)
209
+ attributes.stringify_keys!
210
+
211
+ attributes, binds = predicate_builder.create_binds(attributes)
212
+
213
+ parts = predicate_builder.build_from_hash(attributes)
214
+ when Arel::Nodes::Node
215
+ parts = [opts]
216
+ binds = other
217
+ else
218
+ raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
219
+ end
220
+
221
+ WhereClause.new(parts, binds)
222
+ end
223
+ end
224
+ end
225
+
226
+ #
227
+ # Original code is the following URL.
228
+ #
229
+ # https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/statement_cache.rb#L81-L85
230
+ #
231
+ class StatementCache # :nodoc:
232
+ class BindMap # :nodoc:
233
+ def bind(values)
234
+ values = ActiveRecord::MonkeyPatch.adjust_timezone_offset(values)
235
+
236
+ bas = @bound_attributes.dup
237
+ @indexes.each_with_index { |offset,i| bas[offset] = bas[offset].with_cast_value(values[i]) }
238
+ bas
239
+ end
240
+ end
241
+ end
242
+ end
@@ -1,5 +1,5 @@
1
1
  module OracleEnhanced
2
2
  module MonkeyPatch755
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-oracle_enhanced-adapter-monky_patch_755
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi ITO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -90,8 +90,9 @@ files:
90
90
  - README.md
91
91
  - lib/activerecord-oracle_enhanced-adapter-monky_patch_755.rb
92
92
  - lib/activerecord/monkey_patch.rb
93
- - lib/activerecord/monkey_patch/rails4.rb
94
- - lib/activerecord/monkey_patch/rails5.rb
93
+ - lib/activerecord/monkey_patch/rails4_2.rb
94
+ - lib/activerecord/monkey_patch/rails5_0.rb
95
+ - lib/activerecord/monkey_patch/rails5_1.rb
95
96
  - lib/oracle_enhanced/monkey_patch_755/hooks.rb
96
97
  - lib/oracle_enhanced/monkey_patch_755/railtie.rb
97
98
  - lib/oracle_enhanced/monkey_patch_755/version.rb
@@ -101,8 +102,13 @@ licenses:
101
102
  metadata: {}
102
103
  post_install_message: |
103
104
  [activerecord-oracle_enhanced-adapter-monky_patch_755]
104
- oracle-enhanced ISSUE #755 has been fixed at oracle-enhanced 1.7.3.
105
- The best way is to use oracle-enhanced 1.7.3 or later. Thanks.
105
+ oracle-enhanced ISSUE #755 has been resolved at oracle-enhanced 1.7.3.
106
+ The best way is to use oracle-enhanced 1.7.3 or later.
107
+
108
+ Upgrade Rails 4.2 or older version to Rails 5.
109
+ See https://github.com/rsim/oracle-enhanced#upgrade-rails-42-or-older-version-to-rails-5
110
+
111
+ Thank you.
106
112
  rdoc_options: []
107
113
  require_paths:
108
114
  - lib
@@ -118,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
124
  version: '0'
119
125
  requirements: []
120
126
  rubyforge_project:
121
- rubygems_version: 2.6.8
127
+ rubygems_version: 2.6.12
122
128
  signing_key:
123
129
  specification_version: 4
124
130
  summary: 'A monkey patch for oracle-enhanced ISSUE #755.'
125
131
  test_files: []
126
- has_rdoc: