提交 d1917cfe 编写于 作者: J Jeremy Kemper

Skip column options for primary keys. Closes #7048.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5944 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 64a80ef7
*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]
......
......@@ -203,17 +203,19 @@ class IndexDefinition < Struct.new(:table, :name, :unique, :columns) #:nodoc:
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 @@ def initialize(base)
# 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+.
......
......@@ -254,7 +254,7 @@ def dump_schema_information #:nodoc:
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]
......
......@@ -172,7 +172,7 @@ def quote_string(s) #:nodoc:
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册