1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Extract add_sql_comment! method

Refactor of #22911.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
This commit is contained in:
Ryuta Kamizono 2016-04-27 09:11:06 +09:00 committed by Jeremy Daer
parent 2db8514d21
commit 0eac27904e
No known key found for this signature in database
GPG key ID: AB8F6399D5C60664
3 changed files with 13 additions and 20 deletions

View file

@ -502,8 +502,12 @@ module ActiveRecord
def add_index(table_name, column_name, options = {}) #:nodoc: def add_index(table_name, column_name, options = {}) #:nodoc:
index_name, index_type, index_columns, _, index_algorithm, index_using, comment = add_index_options(table_name, column_name, options) index_name, index_type, index_columns, _, index_algorithm, index_using, comment = add_index_options(table_name, column_name, options)
sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}" sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}"
execute add_sql_comment!(sql, comment)
end
def add_sql_comment!(sql, comment) # :nodoc:
sql << " COMMENT #{quote(comment)}" if comment sql << " COMMENT #{quote(comment)}" if comment
execute sql sql
end end
def foreign_keys(table_name) def foreign_keys(table_name)

View file

@ -2,8 +2,8 @@ module ActiveRecord
module ConnectionAdapters module ConnectionAdapters
module MySQL module MySQL
class SchemaCreation < AbstractAdapter::SchemaCreation class SchemaCreation < AbstractAdapter::SchemaCreation
delegate :quote, to: :@conn delegate :add_sql_comment!, to: :@conn
private :quote private :add_sql_comment!
private private
@ -26,11 +26,7 @@ module ActiveRecord
end end
def add_table_options!(create_sql, options) def add_table_options!(create_sql, options)
super add_sql_comment!(super, options[:comment])
if comment = options[:comment]
create_sql << " COMMENT #{quote(comment)}"
end
end end
def column_options(o) def column_options(o)
@ -48,13 +44,7 @@ module ActiveRecord
sql << " COLLATE #{collation}" sql << " COLLATE #{collation}"
end end
super add_sql_comment!(super, options[:comment])
if comment = options[:comment]
sql << " COMMENT #{quote(comment)}"
end
sql
end end
def add_column_position!(sql, options) def add_column_position!(sql, options)
@ -69,8 +59,7 @@ module ActiveRecord
def index_in_create(table_name, column_name, options) def index_in_create(table_name, column_name, options)
index_name, index_type, index_columns, _, _, index_using, comment = @conn.add_index_options(table_name, column_name, options) index_name, index_type, index_columns, _, _, index_using, comment = @conn.add_index_options(table_name, column_name, options)
index_option = " COMMENT #{quote(comment)}" if comment add_sql_comment!("#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})", comment)
"#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})#{index_option} "
end end
end end
end end