aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb14
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/oracle_adapter.rb2
4 files changed, 11 insertions, 9 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 4d44538b91..32d977a11d 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,6 +1,6 @@
*SVN*
-* change_column accepts :default => nil. #6956 [dcmanges, Jeremy Kemper]
+* change_column accepts :default => nil. Skip column options for primary keys. #6956, #7048 [dcmanges, Jeremy Kemper]
* MySQL, PostgreSQL: change_column_default quotes the default value and doesn't lose column type information. #3987, #6664 [Jonathan Viney, manfred, altano@bigfoot.com]
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index 1b6ccdc7fc..ec839e6f64 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -203,17 +203,19 @@ module ActiveRecord
end
class ColumnDefinition < Struct.new(:base, :name, :type, :limit, :precision, :scale, :default, :null) #:nodoc:
+
+ def sql_type
+ base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
+ end
+
def to_sql
- column_sql = "#{base.quote_column_name(name)} #{type_to_sql(type.to_sym, limit, precision, scale)}"
- add_column_options!(column_sql, :null => null, :default => default)
+ column_sql = "#{base.quote_column_name(name)} #{sql_type}"
+ add_column_options!(column_sql, :null => null, :default => default) unless type.to_sym == :primary_key
column_sql
end
alias to_s :to_sql
private
- def type_to_sql(name, limit, precision, scale)
- base.type_to_sql(name, limit, precision, scale) rescue name
- end
def add_column_options!(sql, options)
base.add_column_options!(sql, options.merge(:column => self))
@@ -233,7 +235,7 @@ module ActiveRecord
# Appends a primary key definition to the table definition.
# Can be called multiple times, but this is probably not a good idea.
def primary_key(name)
- column(name, native[:primary_key])
+ column(name, :primary_key)
end
# Returns a ColumnDefinition for the column with name +name+.
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index edb3042afc..5ae5362a6d 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -254,7 +254,7 @@ module ActiveRecord
def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
native = native_database_types[type]
- column_type_sql = native[:name]
+ column_type_sql = native.is_a?(Hash) ? native[:name] : native
if type == :decimal # ignore limit, use precison and scale
precision ||= native[:precision]
scale ||= native[:scale]
diff --git a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
index 6a0209fceb..01408933f4 100644
--- a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
@@ -172,7 +172,7 @@ begin
def quote(value, column = nil) #:nodoc:
if column && [:text, :binary].include?(column.type)
- %Q{empty_#{ column.sql_type rescue 'blob' }()}
+ %Q{empty_#{ column.sql_type.downcase rescue 'blob' }()}
else
super
end