activerecord-oracle_enhanced-adapter-monky_patch_755 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5f4ae731eb481175433c8d957add4457c1fdb359
4
- data.tar.gz: e61dcaa85b1a36bd231863e7349394e2c275c589
2
+ SHA256:
3
+ metadata.gz: 06fe1c2f06a608758e071627802d4ddfdfb6b650d0a41c0f6359adda79e31af4
4
+ data.tar.gz: 80f000c4cb4114014d0a1c4b1f7d2586ff449aa1d7ca63f063ab3d6c3d86e40d
5
5
  SHA512:
6
- metadata.gz: 17dae0dd78ec2bed3b9dfe4249c92ed7bd755244dc05132a12bc66b9afe254728373e71d65156a5931cafbd90d1962b75e2b38ccf8a982fa70cdc8160d5e42ae
7
- data.tar.gz: e56022b35d084c5a935eacba0c8b794a121315309fd5800cab9d7668f2097ff63e87f5bc3599c51b7b8b1c28c8df2bf81a7f423de16f5a03677894737eac4000
6
+ metadata.gz: 1387e40b2fa4d8c0a916e1b9170511c90b93b0c60618f3891ab0a3d3e2fb04318f70d48b5dc33c2961cb32f0886c4180e3a74de7b2c31fff18fcceb9cf36d0e2
7
+ data.tar.gz: 51aa051b7dde9d41082f9ebb8cb42ffb262d5626f79b4af110db40d00c2460b52cc9b465dc31af4c34aca4a3fe5512576c0f2f9a97ce831f940fbbbd2d2aaf23
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  A monkey patch for oracle-enhanced ISSUE [#755](https://github.com/rsim/oracle-enhanced/issues/755).
4
4
 
5
- **ISSUE #755 has been resolved at activerecord-oracle_enhanced-adapter 1.7.3.**
5
+ **ISSUE #755 has been resolved on activerecord-oracle_enhanced-adapter 1.7.3 or higher.**
6
+
7
+ The development of this gem has ended. Rails 5.2 or higher are not supported.
6
8
 
7
9
  ## Installation
8
10
 
@@ -184,6 +184,21 @@ module ActiveRecord
184
184
  end
185
185
  end
186
186
  end
187
+
188
+ module SchemaStatements
189
+ # https://github.com/rsim/oracle-enhanced/blob/v1.7.9/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb#L290
190
+ def change_column_null(table_name, column_name, null, default = nil) #:nodoc:
191
+ column = column_for(table_name, column_name)
192
+
193
+ unless null || default.nil?
194
+ execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
195
+ end
196
+
197
+ sql_type = column.sql_type.to_s == 'DATETIME' ? 'DATE' : column.sql_type # monkey_patched
198
+
199
+ change_column table_name, column_name, sql_type, :null => null
200
+ end
201
+ end
187
202
  end
188
203
  end
189
204
 
@@ -0,0 +1,219 @@
1
+ module ActiveRecord
2
+ module MonkeyPatch
3
+ SUPPORTED_MAJOR_VERSION = 5
4
+ MINIMUM_SUPPORTED_VERSION = '5.2.0'.freeze
5
+ end
6
+
7
+ module ConnectionAdapters
8
+ #
9
+ # This is a monkey patch to the problem below.
10
+ # As a result of `bin/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.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb#L13-L15
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
+ module OracleEnhanced
32
+ module SchemaStatements
33
+
34
+ #
35
+ # Original code is the following URL.
36
+ # https://github.com/rsim/oracle-enhanced/blob/v5.2.3/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb#L618-L652
37
+ #
38
+ def new_column_from_field(table_name, field)
39
+ limit, scale = field["limit"], field["scale"]
40
+ if limit || scale
41
+ field["sql_type"] += "(#{(limit || 38).to_i}" + ((scale = scale.to_i) > 0 ? ",#{scale})" : ")")
42
+ end
43
+
44
+ if field["sql_type_owner"]
45
+ field["sql_type"] = field["sql_type_owner"] + "." + field["sql_type"]
46
+ end
47
+
48
+ is_virtual = field["virtual_column"] == "YES"
49
+
50
+ # clean up odd default spacing from Oracle
51
+ if field["data_default"] && !is_virtual
52
+ field["data_default"].sub!(/^(.*?)\s*$/, '\1')
53
+
54
+ # If a default contains a newline these cleanup regexes need to
55
+ # match newlines.
56
+ field["data_default"].sub!(/^'(.*)'$/m, '\1')
57
+ field["data_default"] = nil if field["data_default"] =~ /^(null|empty_[bc]lob\(\))$/i
58
+ # TODO: Needs better fix to fallback "N" to false
59
+ field["data_default"] = false if (field["data_default"] == "N" && OracleEnhancedAdapter.emulate_booleans_from_strings)
60
+ end
61
+
62
+ type_metadata = fetch_type_metadata(field["sql_type"], is_virtual)
63
+
64
+ # *** Its a monkey patch paragraph. ***
65
+ p "sql_type: #{type_metadata.sql_type}"
66
+ if /date/i === type_metadata.sql_type
67
+ if type_metadata.type == :date
68
+ type_metadata.instance_eval('@sql_type = "DATETIME"')
69
+ end
70
+ end
71
+
72
+ default_value = extract_value_from_default(field["data_default"])
73
+ default_value = nil if is_virtual
74
+ OracleEnhanced::Column.new(oracle_downcase(field["name"]),
75
+ default_value,
76
+ type_metadata,
77
+ field["nullable"] == "Y",
78
+ table_name,
79
+ field["column_comment"]
80
+ )
81
+ end
82
+ end
83
+ end
84
+
85
+ class OracleEnhancedAdapter
86
+ #
87
+ # `supports_datetime_with_precision?` method and `native_database_types` method are overwriting
88
+ # the mapping between Rails and Oracle type to match Rails 4.2 behavior.
89
+ #
90
+ # The following is the SQL type when generating datetime column.
91
+ #
92
+ # - Rails 5 ... `TIMESTAMP(6)' SQL type.
93
+ # - Rails 4 ... `DATE' SQL type. ***This is the behavior of the monkey patch***.
94
+ #
95
+ # Original code is the following URL.
96
+ #
97
+ # https://github.com/rsim/oracle-enhanced/blob/v5.2.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
98
+ #
99
+ def supports_datetime_with_precision?
100
+ false
101
+ end
102
+
103
+ def native_database_types
104
+ native_database_types_patch = {
105
+ datetime: { name: "DATE" },
106
+ time: { name: "DATE" }
107
+ }
108
+
109
+ if emulate_booleans_from_strings
110
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS.dup.merge(native_database_types_patch)
111
+ else
112
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::NATIVE_DATABASE_TYPES.dup.merge(native_database_types_patch)
113
+ end
114
+ end
115
+ end
116
+
117
+ module OracleEnhanced
118
+ module Quoting
119
+ #
120
+ # Original code has been removed.
121
+ #
122
+ # https://github.com/rsim/oracle-enhanced/commit/28dd91ccbbbf8e1e313ba816257ad281860f100b
123
+ #
124
+ def quote(value)
125
+ # p caller.each {|c| p c }
126
+ p "*** quote: #{value}"
127
+ p "*** quote: #{value.class}"
128
+ case value
129
+ when ::Date, ::Time, ::DateTime # *** Its a monky patch condition. ***
130
+ p "xxx quote: #{value.class}"
131
+ p "xxx quote acts_like?: #{value.acts_like?(:time)}"
132
+ if value.acts_like?(:time)
133
+ zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
134
+
135
+ # p "*** quote respond_to?: #{value.respond_to?(zone_conversion_method)}"
136
+ if value.respond_to?(zone_conversion_method)
137
+ value = value.send(zone_conversion_method)
138
+ end
139
+ end
140
+
141
+ # p "*** quote to_s(:db): #{value.to_s(:db)}"
142
+ "'#{value.to_s(:db)}'"
143
+ else
144
+ super
145
+ end
146
+ end
147
+
148
+ #
149
+ # Follow up to https://github.com/rsim/oracle-enhanced/pull/1267/commits/f26432f679fb836f4f4d72f6a7e9999da175ac91
150
+ #
151
+ def _type_cast(value)
152
+ # p "*** _type_cast: #{value}"
153
+ # p "*** _type_cast: #{value.class}"
154
+ case value
155
+ when Date, Time # *** Its a monky patch condition. ***
156
+ if value.acts_like?(:time)
157
+ zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
158
+ value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
159
+ else
160
+ value
161
+ end
162
+ when ActiveRecord::Type::OracleEnhanced::NationalCharacterString::Data
163
+ value.to_s
164
+ else
165
+ super
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ #
173
+ # Original code is the following URL.
174
+ #
175
+ # https://github.com/rails/rails/blob/v5.2.0.beta2/activerecord/lib/active_record/relation/where_clause_factory.rb
176
+ #
177
+ class Relation
178
+ class WhereClauseFactory
179
+ def build(opts, other)
180
+ # p "*** WhereClauseFactory #{opts}"
181
+ # p "*** WhereClauseFactory #{opts.class}"
182
+ case opts
183
+ when String, Array
184
+ parts = [klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
185
+ when Hash
186
+ opts = ActiveRecord::MonkeyPatch.adjust_timezone_offset(opts)
187
+
188
+ attributes = predicate_builder.resolve_column_aliases(opts)
189
+ attributes = klass.send(:expand_hash_conditions_for_aggregates, attributes)
190
+ attributes.stringify_keys!
191
+
192
+ parts = predicate_builder.build_from_hash(attributes)
193
+ when Arel::Nodes::Node
194
+ parts = [opts]
195
+ else
196
+ raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
197
+ end
198
+
199
+ WhereClause.new(parts)
200
+ end
201
+ end
202
+ end
203
+
204
+ #
205
+ # Original code is the following URL.
206
+ # https://github.com/rails/rails/blob/v5.2.0.beta2/activerecord/lib/active_record/statement_cache.rb#L83-L87
207
+ #
208
+ class StatementCache # :nodoc:
209
+ class BindMap # :nodoc:
210
+ def bind(values)
211
+ values = ActiveRecord::MonkeyPatch.adjust_timezone_offset(values)
212
+
213
+ bas = @bound_attributes.dup
214
+ @indexes.each_with_index { |offset, i| bas[offset] = bas[offset].with_cast_value(values[i]) }
215
+ bas
216
+ end
217
+ end
218
+ end
219
+ end
@@ -1,5 +1,5 @@
1
1
  module OracleEnhanced
2
2
  module MonkeyPatch755
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '1.0.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.3.0
4
+ version: 1.0.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: 2017-05-15 00:00:00.000000000 Z
11
+ date: 2019-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.2.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 4.2.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activerecord-oracle_enhanced-adapter
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +65,9 @@ dependencies:
59
65
  - - ">="
60
66
  - !ruby/object:Gem::Version
61
67
  version: 4.2.1
68
+ - - "<"
69
+ - !ruby/object:Gem::Version
70
+ version: '5.2'
62
71
  type: :development
63
72
  prerelease: false
64
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -66,6 +75,9 @@ dependencies:
66
75
  - - ">="
67
76
  - !ruby/object:Gem::Version
68
77
  version: 4.2.1
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: '5.2'
69
81
  - !ruby/object:Gem::Dependency
70
82
  name: rspec
71
83
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +105,7 @@ files:
93
105
  - lib/activerecord/monkey_patch/rails4_2.rb
94
106
  - lib/activerecord/monkey_patch/rails5_0.rb
95
107
  - lib/activerecord/monkey_patch/rails5_1.rb
108
+ - lib/activerecord/monkey_patch/rails5_2.rb
96
109
  - lib/oracle_enhanced/monkey_patch_755/hooks.rb
97
110
  - lib/oracle_enhanced/monkey_patch_755/railtie.rb
98
111
  - lib/oracle_enhanced/monkey_patch_755/version.rb
@@ -108,6 +121,8 @@ post_install_message: |
108
121
  Upgrade Rails 4.2 or older version to Rails 5.
109
122
  See https://github.com/rsim/oracle-enhanced#upgrade-rails-42-or-older-version-to-rails-5
110
123
 
124
+ Also this gem doesn't support Rails 5.2 or higher.
125
+
111
126
  Thank you.
112
127
  rdoc_options: []
113
128
  require_paths:
@@ -123,8 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
138
  - !ruby/object:Gem::Version
124
139
  version: '0'
125
140
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.6.12
141
+ rubygems_version: 3.0.2
128
142
  signing_key:
129
143
  specification_version: 4
130
144
  summary: 'A monkey patch for oracle-enhanced ISSUE #755.'