Permalink
Browse files

Support add_column_options

  • Loading branch information...
1 parent ca3d08f commit 7d2a0eb0cdd466683529d076547a5c26d4711334 @yahonda committed Jul 1, 2013
@@ -587,7 +587,7 @@ def quote(value, column = nil) #:nodoc:
if value && column
case column.type
when :text, :binary
- %Q{empty_#{ column.sql_type.downcase rescue 'blob' }()}
+ %Q{empty_#{ type_to_sql(column.type.to_sym).downcase rescue 'blob' }()}
# NLS_DATE_FORMAT independent TIMESTAMP support
when :timestamp
quote_timestamp_with_to_timestamp(value)
@@ -1591,6 +1591,31 @@ def tablespace_for(obj_type, tablespace_option, table_name=nil, column_name=nil)
tablespace_sql
end
+ def add_column_options!(sql, options)
+ type = options[:type] || ((column = options[:column]) && column.type)
+ type = type && type.to_sym
+ # handle case of defaults for CLOB columns, which would otherwise get "quoted" incorrectly
+ if options_include_default?(options)
+ if type == :text
+ sql << " DEFAULT #{@conn.quote(options[:default])}"
+
+ else
+ # from abstract adapter
+ sql << " DEFAULT #{@conn.quote(options[:default], options[:column])}"
+ end
+ end
+ # must explicitly add NULL or NOT NULL to allow change_column to work on migrations
+ if options[:null] == false
+ sql << " NOT NULL"
+ elsif options[:null] == true
+ sql << " NULL" unless type == :primary_key
+ end
+ # add AS expression for virtual columns
+ if options[:as].present?
+ sql << " AS (#{options[:as]})"
+ end
+ end
+
def default_tablespace_for(type)
(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[type] ||
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[native_database_types[type][:name]]) rescue nil
@@ -215,6 +215,7 @@ def full_drop(preserve_tables=false) #:nodoc:
end
def add_column_options!(sql, options) #:nodoc:
+ #TODO: should be removed?
type = options[:type] || ((column = options[:column]) && column.type)
type = type && type.to_sym
# handle case of defaults for CLOB columns, which would otherwise get "quoted" incorrectly

0 comments on commit 7d2a0eb

Please sign in to comment.