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:
parent
2db8514d21
commit
0eac27904e
3 changed files with 13 additions and 20 deletions
|
@ -502,8 +502,12 @@ module ActiveRecord
|
|||
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)
|
||||
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
|
||||
execute sql
|
||||
sql
|
||||
end
|
||||
|
||||
def foreign_keys(table_name)
|
||||
|
|
|
@ -2,8 +2,8 @@ module ActiveRecord
|
|||
module ConnectionAdapters
|
||||
module MySQL
|
||||
class SchemaCreation < AbstractAdapter::SchemaCreation
|
||||
delegate :quote, to: :@conn
|
||||
private :quote
|
||||
delegate :add_sql_comment!, to: :@conn
|
||||
private :add_sql_comment!
|
||||
|
||||
private
|
||||
|
||||
|
@ -26,11 +26,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def add_table_options!(create_sql, options)
|
||||
super
|
||||
|
||||
if comment = options[:comment]
|
||||
create_sql << " COMMENT #{quote(comment)}"
|
||||
end
|
||||
add_sql_comment!(super, options[:comment])
|
||||
end
|
||||
|
||||
def column_options(o)
|
||||
|
@ -48,13 +44,7 @@ module ActiveRecord
|
|||
sql << " COLLATE #{collation}"
|
||||
end
|
||||
|
||||
super
|
||||
|
||||
if comment = options[:comment]
|
||||
sql << " COMMENT #{quote(comment)}"
|
||||
end
|
||||
|
||||
sql
|
||||
add_sql_comment!(super, options[:comment])
|
||||
end
|
||||
|
||||
def add_column_position!(sql, options)
|
||||
|
@ -69,8 +59,7 @@ module ActiveRecord
|
|||
|
||||
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_option = " COMMENT #{quote(comment)}" if comment
|
||||
"#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})#{index_option} "
|
||||
add_sql_comment!("#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})", comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue