activerecord-oracle_enhanced-adapter 1.7.11 → 1.8.2
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 +4 -4
- data/History.md +206 -4
- data/README.md +37 -1
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +7 -59
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -50
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +11 -11
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -117
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +37 -27
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +10 -10
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +56 -71
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +0 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +51 -69
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +76 -76
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +14 -43
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -64
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -47
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +150 -160
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +95 -133
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +66 -101
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +290 -533
- data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -10
- data/lib/active_record/oracle_enhanced/type/integer.rb +3 -4
- data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
- data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -1
- data/lib/active_record/oracle_enhanced/type/raw.rb +2 -3
- data/lib/active_record/oracle_enhanced/type/string.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/text.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/timestamptz.rb +23 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +55 -162
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +32 -34
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +44 -42
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +250 -357
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -6
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -5
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +115 -124
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +68 -72
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +64 -80
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +223 -329
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +18 -20
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +59 -59
- data/spec/support/alter_system_user_password.sql +2 -0
- data/spec/support/create_oracle_enhanced_users.sql +31 -0
- metadata +25 -25
- data/.rspec +0 -2
- data/Gemfile +0 -22
- data/RUNNING_TESTS.md +0 -83
- data/Rakefile +0 -45
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -94
- data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -19
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_support"
|
2
2
|
|
3
3
|
module ActiveRecord #:nodoc:
|
4
4
|
# Custom create, update, delete methods functionality.
|
@@ -96,99 +96,99 @@ module ActiveRecord #:nodoc:
|
|
96
96
|
|
97
97
|
private
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
99
|
+
# Creates a record with custom create method
|
100
|
+
# and returns its id.
|
101
|
+
def _create_record
|
102
|
+
# check if class has custom create method
|
103
|
+
if self.class.custom_create_method
|
104
|
+
# run before/after callbacks defined in model
|
105
|
+
run_callbacks(:create) do
|
106
|
+
# timestamp
|
107
|
+
if self.record_timestamps
|
108
|
+
current_time = current_time_from_proper_timezone
|
109
|
+
|
110
|
+
all_timestamp_attributes_in_model.each do |column|
|
111
|
+
if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
|
112
|
+
write_attribute(column.to_s, current_time)
|
113
|
+
end
|
113
114
|
end
|
114
115
|
end
|
116
|
+
# run
|
117
|
+
create_using_custom_method
|
115
118
|
end
|
116
|
-
|
117
|
-
|
119
|
+
else
|
120
|
+
super
|
118
121
|
end
|
119
|
-
else
|
120
|
-
super
|
121
122
|
end
|
122
|
-
end
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
def create_using_custom_method
|
125
|
+
log_custom_method("custom create method", "#{self.class.name} Create") do
|
126
|
+
self.id = instance_eval(&self.class.custom_create_method)
|
127
|
+
end
|
128
|
+
@new_record = false
|
129
|
+
# Starting from ActiveRecord 3.0.3 @persisted is used instead of @new_record
|
130
|
+
@persisted = true
|
131
|
+
id
|
127
132
|
end
|
128
|
-
@new_record = false
|
129
|
-
# Starting from ActiveRecord 3.0.3 @persisted is used instead of @new_record
|
130
|
-
@persisted = true
|
131
|
-
id
|
132
|
-
end
|
133
133
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
134
|
+
# Updates the associated record with custom update method
|
135
|
+
# Returns the number of affected rows.
|
136
|
+
def _update_record(attribute_names = @attributes.keys)
|
137
|
+
# check if class has custom update method
|
138
|
+
if self.class.custom_update_method
|
139
|
+
# run before/after callbacks defined in model
|
140
|
+
run_callbacks(:update) do
|
141
|
+
# timestamp
|
142
|
+
if should_record_timestamps?
|
143
|
+
current_time = current_time_from_proper_timezone
|
144
|
+
|
145
|
+
timestamp_attributes_for_update_in_model.each do |column|
|
146
|
+
column = column.to_s
|
147
|
+
next if attribute_changed?(column)
|
148
|
+
write_attribute(column, current_time)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
# update just dirty attributes
|
152
|
+
if partial_writes?
|
153
|
+
# Serialized attributes should always be written in case they've been
|
154
|
+
# changed in place.
|
155
|
+
update_using_custom_method(changed | (attributes.keys & self.class.columns.select { |column| column.is_a?(Type::Serialized) }))
|
156
|
+
else
|
157
|
+
update_using_custom_method(attributes.keys)
|
149
158
|
end
|
150
159
|
end
|
151
|
-
|
152
|
-
|
153
|
-
# Serialized attributes should always be written in case they've been
|
154
|
-
# changed in place.
|
155
|
-
update_using_custom_method(changed | (attributes.keys & self.class.columns.select {|column| column.is_a?(Type::Serialized)}))
|
156
|
-
else
|
157
|
-
update_using_custom_method(attributes.keys)
|
158
|
-
end
|
160
|
+
else
|
161
|
+
super
|
159
162
|
end
|
160
|
-
else
|
161
|
-
super
|
162
163
|
end
|
163
|
-
end
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
165
|
+
def update_using_custom_method(attribute_names)
|
166
|
+
return 0 if attribute_names.empty?
|
167
|
+
log_custom_method("custom update method with #{self.class.primary_key}=#{self.id}", "#{self.class.name} Update") do
|
168
|
+
instance_eval(&self.class.custom_update_method)
|
169
|
+
end
|
170
|
+
1
|
169
171
|
end
|
170
|
-
1
|
171
|
-
end
|
172
172
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
173
|
+
# Deletes the record in the database with custom delete method
|
174
|
+
# and freezes this instance to reflect that no changes should
|
175
|
+
# be made (since they can't be persisted).
|
176
|
+
def destroy_using_custom_method
|
177
|
+
unless new_record? || @destroyed
|
178
|
+
log_custom_method("custom delete method with #{self.class.primary_key}=#{self.id}", "#{self.class.name} Destroy") do
|
179
|
+
instance_eval(&self.class.custom_delete_method)
|
180
|
+
end
|
180
181
|
end
|
181
|
-
end
|
182
182
|
|
183
|
-
|
184
|
-
|
185
|
-
|
183
|
+
@destroyed = true
|
184
|
+
freeze
|
185
|
+
end
|
186
186
|
|
187
|
-
|
188
|
-
|
189
|
-
|
187
|
+
def log_custom_method(*args)
|
188
|
+
self.class.connection.send(:log, *args) { yield }
|
189
|
+
end
|
190
190
|
|
191
|
-
|
192
|
-
|
191
|
+
alias_method :update_record, :_update_record if private_method_defined?(:_update_record)
|
192
|
+
alias_method :create_record, :_create_record if private_method_defined?(:_create_record)
|
193
193
|
end
|
194
194
|
end
|
@@ -76,79 +76,50 @@ module ActiveRecord
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def quote_table_name(name) #:nodoc:
|
79
|
-
name, link = name.to_s.split(
|
80
|
-
@quoted_table_names[name] ||= [name.split(
|
79
|
+
name, link = name.to_s.split("@")
|
80
|
+
@quoted_table_names[name] ||= [name.split(".").map { |n| quote_column_name(n) }.join("."), quote_database_link(link)].compact.join("@")
|
81
81
|
end
|
82
82
|
|
83
83
|
def quote_string(s) #:nodoc:
|
84
84
|
s.gsub(/'/, "''")
|
85
85
|
end
|
86
86
|
|
87
|
-
def quote(value, column = nil) #:nodoc:
|
88
|
-
super
|
89
|
-
end
|
90
|
-
|
91
87
|
def _quote(value) #:nodoc:
|
92
88
|
case value
|
93
89
|
when ActiveRecord::OracleEnhanced::Type::NationalCharacterString::Data then
|
94
|
-
|
90
|
+
"N" << "'#{quote_string(value.to_s)}'"
|
95
91
|
when ActiveModel::Type::Binary::Data then
|
96
|
-
|
92
|
+
"empty_blob()"
|
97
93
|
when ActiveRecord::OracleEnhanced::Type::Text::Data then
|
98
|
-
|
94
|
+
"empty_clob()"
|
99
95
|
else
|
100
96
|
super
|
101
97
|
end
|
102
98
|
end
|
103
99
|
|
104
100
|
def quoted_true #:nodoc:
|
105
|
-
return "'
|
101
|
+
return "'Y'" if emulate_booleans_from_strings
|
106
102
|
"1".freeze
|
107
103
|
end
|
108
104
|
|
109
105
|
def unquoted_true #:nodoc:
|
110
|
-
return "
|
106
|
+
return "Y" if emulate_booleans_from_strings
|
111
107
|
"1".freeze
|
112
108
|
end
|
113
109
|
|
114
110
|
def quoted_false #:nodoc:
|
115
|
-
return "'
|
111
|
+
return "'N'" if emulate_booleans_from_strings
|
116
112
|
"0".freeze
|
117
113
|
end
|
118
114
|
|
119
115
|
def unquoted_false #:nodoc:
|
120
|
-
return "
|
116
|
+
return "N" if emulate_booleans_from_strings
|
121
117
|
"0".freeze
|
122
118
|
end
|
123
119
|
|
124
|
-
def quote_date_with_to_date(value) #:nodoc:
|
125
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
126
|
-
`quote_date_with_to_date` will be deprecated in future version of Oracle enhanced adapter.
|
127
|
-
Also this method should not be called directly. Let Abstract adapter `_quote` method handle it.
|
128
|
-
MSG
|
129
|
-
# should support that composite_primary_keys gem will pass date as string
|
130
|
-
value = quoted_date(value) if value.acts_like?(:date) || value.acts_like?(:time)
|
131
|
-
"TO_DATE('#{value}','YYYY-MM-DD HH24:MI:SS')"
|
132
|
-
end
|
133
|
-
|
134
|
-
def quote_timestamp_with_to_timestamp(value) #:nodoc:
|
135
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
136
|
-
`quote_timestamp_with_to_timestamp` will be deprecated in future version of Oracle enhanced adapter.
|
137
|
-
Also this method should not be called directly. Let Abstract adapter `_quote` method handle it.
|
138
|
-
MSG
|
139
|
-
# add up to 9 digits of fractional seconds to inserted time
|
140
|
-
value = "#{quoted_date(value)}:#{("%.6f"%value.to_f).split('.')[1]}" if value.acts_like?(:time)
|
141
|
-
"TO_TIMESTAMP('#{value}','YYYY-MM-DD HH24:MI:SS:FF6')"
|
142
|
-
end
|
143
|
-
|
144
|
-
# Cast a +value+ to a type that the database understands.
|
145
|
-
def type_cast(value, column = nil)
|
146
|
-
super
|
147
|
-
end
|
148
|
-
|
149
120
|
def _type_cast(value)
|
150
121
|
case value
|
151
|
-
when
|
122
|
+
when ActiveRecord::OracleEnhanced::Type::TimestampTz::Data
|
152
123
|
if value.acts_like?(:time)
|
153
124
|
zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
|
154
125
|
value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
|
@@ -167,11 +138,11 @@ module ActiveRecord
|
|
167
138
|
end
|
168
139
|
|
169
140
|
# if MRI or YARV
|
170
|
-
if !defined?(RUBY_ENGINE) || RUBY_ENGINE ==
|
171
|
-
require
|
141
|
+
if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
|
142
|
+
require "active_record/connection_adapters/oracle_enhanced/oci_quoting"
|
172
143
|
# if JRuby
|
173
|
-
elsif RUBY_ENGINE ==
|
174
|
-
require
|
144
|
+
elsif RUBY_ENGINE == "jruby"
|
145
|
+
require "active_record/connection_adapters/oracle_enhanced/jdbc_quoting"
|
175
146
|
else
|
176
147
|
raise "Unsupported Ruby engine #{RUBY_ENGINE}"
|
177
148
|
end
|
@@ -4,92 +4,88 @@ module ActiveRecord
|
|
4
4
|
class SchemaCreation < AbstractAdapter::SchemaCreation
|
5
5
|
private
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
when o.type.to_sym == :virtual
|
10
|
-
sql_type = type_to_sql(o.default[:type], o.limit, o.precision, o.scale) if o.default[:type]
|
11
|
-
return "#{quote_column_name(o.name)} #{sql_type} AS (#{o.default[:as]})"
|
12
|
-
when [:blob, :clob].include?(sql_type = type_to_sql(o.type.to_sym, o.limit, o.precision, o.scale).downcase.to_sym)
|
7
|
+
def visit_ColumnDefinition(o)
|
8
|
+
if [:blob, :clob].include?(sql_type = type_to_sql(o.type, o.options).downcase.to_sym)
|
13
9
|
if (tablespace = default_tablespace_for(sql_type))
|
14
10
|
@lob_tablespaces ||= {}
|
15
11
|
@lob_tablespaces[o.name] = tablespace
|
16
12
|
end
|
13
|
+
end
|
14
|
+
super
|
17
15
|
end
|
18
|
-
super
|
19
|
-
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
def visit_TableDefinition(o)
|
18
|
+
create_sql = "CREATE#{' GLOBAL TEMPORARY' if o.temporary} TABLE #{quote_table_name(o.name)} "
|
19
|
+
statements = o.columns.map { |c| accept c }
|
20
|
+
statements << accept(o.primary_keys) if o.primary_keys
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
if supports_foreign_keys_in_create?
|
23
|
+
statements.concat(o.foreign_keys.map { |to_table, options| foreign_key_in_create(o.name, to_table, options) })
|
24
|
+
end
|
29
25
|
|
30
|
-
|
26
|
+
create_sql << "(#{statements.join(', ')})" if statements.present?
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
unless o.temporary
|
29
|
+
@lob_tablespaces.each do |lob_column, tablespace|
|
30
|
+
create_sql << " LOB (#{quote_column_name(lob_column)}) STORE AS (TABLESPACE #{tablespace}) \n"
|
31
|
+
end if defined?(@lob_tablespaces)
|
32
|
+
create_sql << " ORGANIZATION #{o.organization}" if o.organization
|
33
|
+
if (tablespace = o.tablespace || default_tablespace_for(:table))
|
34
|
+
create_sql << " TABLESPACE #{tablespace}"
|
35
|
+
end
|
39
36
|
end
|
37
|
+
add_table_options!(create_sql, table_options(o))
|
38
|
+
create_sql << " AS #{@conn.to_sql(o.as)}" if o.as
|
39
|
+
create_sql
|
40
40
|
end
|
41
|
-
add_table_options!(create_sql, table_options(o))
|
42
|
-
create_sql << " AS #{@conn.to_sql(o.as)}" if o.as
|
43
|
-
create_sql
|
44
|
-
end
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
def default_tablespace_for(type)
|
43
|
+
(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[type] ||
|
44
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[native_database_types[type][:name]]) rescue nil
|
45
|
+
end
|
50
46
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
def add_column_options!(sql, options)
|
48
|
+
type = options[:type] || ((column = options[:column]) && column.type)
|
49
|
+
type = type && type.to_sym
|
50
|
+
# handle case of defaults for CLOB columns, which would otherwise get "quoted" incorrectly
|
51
|
+
if options_include_default?(options)
|
52
|
+
if type == :text
|
53
|
+
sql << " DEFAULT #{@conn.quote(options[:default])}"
|
54
|
+
else
|
55
|
+
sql << " DEFAULT #{quote_default_expression(options[:default], options[:column])}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
# must explicitly add NULL or NOT NULL to allow change_column to work on migrations
|
59
|
+
if options[:null] == false
|
60
|
+
sql << " NOT NULL"
|
61
|
+
elsif options[:null] == true
|
62
|
+
sql << " NULL" unless type == :primary_key
|
63
|
+
end
|
64
|
+
# add AS expression for virtual columns
|
65
|
+
if options[:as].present?
|
66
|
+
sql << " AS (#{options[:as]})"
|
67
|
+
end
|
68
|
+
if options[:primary_key] == true
|
69
|
+
sql << " PRIMARY KEY"
|
60
70
|
end
|
61
71
|
end
|
62
|
-
# must explicitly add NULL or NOT NULL to allow change_column to work on migrations
|
63
|
-
if options[:null] == false
|
64
|
-
sql << " NOT NULL"
|
65
|
-
elsif options[:null] == true
|
66
|
-
sql << " NULL" unless type == :primary_key
|
67
|
-
end
|
68
|
-
# add AS expression for virtual columns
|
69
|
-
if options[:as].present?
|
70
|
-
sql << " AS (#{options[:as]})"
|
71
|
-
end
|
72
|
-
if options[:primary_key] == true
|
73
|
-
sql << " PRIMARY KEY"
|
74
|
-
end
|
75
|
-
end
|
76
72
|
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
def action_sql(action, dependency)
|
74
|
+
if action == "UPDATE"
|
75
|
+
raise ArgumentError, <<-MSG.strip_heredoc
|
80
76
|
'#{action}' is not supported by Oracle
|
81
77
|
MSG
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
78
|
+
end
|
79
|
+
case dependency
|
80
|
+
when :nullify then "ON #{action} SET NULL"
|
81
|
+
when :cascade then "ON #{action} CASCADE"
|
82
|
+
else
|
83
|
+
raise ArgumentError, <<-MSG.strip_heredoc
|
88
84
|
'#{dependency}' is not supported for #{action}
|
89
85
|
Supported values are: :nullify, :cascade
|
90
86
|
MSG
|
87
|
+
end
|
91
88
|
end
|
92
|
-
end
|
93
89
|
end
|
94
90
|
end
|
95
91
|
end
|
@@ -1,14 +1,32 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module ConnectionAdapters
|
3
3
|
module OracleEnhanced
|
4
|
-
|
5
|
-
def name
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
module ColumnMethods
|
5
|
+
def primary_key(name, type = :primary_key, **options)
|
6
|
+
# This is a placeholder for future :auto_increment support
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
[
|
11
|
+
:raw
|
12
|
+
].each do |column_type|
|
13
|
+
module_eval <<-CODE, __FILE__, __LINE__ + 1
|
14
|
+
def #{column_type}(*args, **options)
|
15
|
+
args.each { |name| column(name, :#{column_type}, options) }
|
16
|
+
end
|
17
|
+
CODE
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ReferenceDefinition < ActiveRecord::ConnectionAdapters::ReferenceDefinition # :nodoc:
|
22
|
+
def initialize(
|
23
|
+
name,
|
24
|
+
polymorphic: false,
|
25
|
+
index: true,
|
26
|
+
foreign_key: false,
|
27
|
+
type: :integer,
|
28
|
+
**options)
|
29
|
+
super
|
12
30
|
end
|
13
31
|
end
|
14
32
|
|
@@ -26,10 +44,9 @@ module ActiveRecord
|
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
29
|
-
class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
|
30
|
-
end
|
31
|
-
|
32
47
|
class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
|
48
|
+
include ActiveRecord::ConnectionAdapters::OracleEnhanced::ColumnMethods
|
49
|
+
|
33
50
|
attr_accessor :tablespace, :organization
|
34
51
|
def initialize(name, temporary = false, options = nil, as = nil, tablespace = nil, organization = nil, comment: nil)
|
35
52
|
@tablespace = tablespace
|
@@ -37,51 +54,20 @@ module ActiveRecord
|
|
37
54
|
super(name, temporary, options, as, comment: comment)
|
38
55
|
end
|
39
56
|
|
40
|
-
def
|
41
|
-
options = args.extract_options!
|
42
|
-
column_names = args
|
43
|
-
column_names.each { |name| column(name, :virtual, options) }
|
44
|
-
end
|
45
|
-
|
46
|
-
def column(name, type, options = {})
|
57
|
+
def new_column_definition(name, type, **options) # :nodoc:
|
47
58
|
if type == :virtual
|
48
|
-
|
49
|
-
|
50
|
-
default[:as] = options[:as]
|
51
|
-
elsif options[:default]
|
52
|
-
warn "[DEPRECATION] virtual column `:default` option is deprecated. Please use `:as` instead."
|
53
|
-
default[:as] = options[:default]
|
54
|
-
else
|
55
|
-
raise "No virtual column definition found."
|
56
|
-
end
|
57
|
-
options[:default] = default
|
59
|
+
raise "No virtual column definition found." unless options[:as]
|
60
|
+
type = options[:type]
|
58
61
|
end
|
59
|
-
super
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
def create_column_definition(name, type)
|
64
|
-
OracleEnhanced::ColumnDefinition.new name, type
|
62
|
+
super
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
68
66
|
class AlterTable < ActiveRecord::ConnectionAdapters::AlterTable
|
69
|
-
def add_foreign_key(to_table, options)
|
70
|
-
@foreign_key_adds << OracleEnhanced::ForeignKeyDefinition.new(name, to_table, options)
|
71
|
-
end
|
72
67
|
end
|
73
68
|
|
74
69
|
class Table < ActiveRecord::ConnectionAdapters::Table
|
75
|
-
|
76
|
-
ActiveSupport::Deprecation.warn "`foreign_key` option will be deprecated. Please use `references` option"
|
77
|
-
to_table = to_table.to_s.pluralize if ActiveRecord::Base.pluralize_table_names
|
78
|
-
@base.add_foreign_key(@name, to_table, options)
|
79
|
-
end
|
80
|
-
|
81
|
-
def remove_foreign_key(options = {})
|
82
|
-
ActiveSupport::Deprecation.warn "`remove_foreign_key` option will be deprecated. Please use `remove_references` option"
|
83
|
-
@base.remove_foreign_key(@name, options)
|
84
|
-
end
|
70
|
+
include ActiveRecord::ConnectionAdapters::OracleEnhanced::ColumnMethods
|
85
71
|
end
|
86
72
|
end
|
87
73
|
end
|