diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-04-27 09:11:06 +0900 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2016-04-29 17:54:38 -0700 |
commit | 0eac27904eb4fd4d945ff16b6681b24d09d16f3f (patch) | |
tree | 5d4f9f10b3714a80387a32a1def82ed3f836671a /activerecord/lib | |
parent | 2db8514d218068cae7b37b7939ed3ba812407105 (diff) | |
download | rails-0eac27904eb4fd4d945ff16b6681b24d09d16f3f.tar.gz rails-0eac27904eb4fd4d945ff16b6681b24d09d16f3f.tar.bz2 rails-0eac27904eb4fd4d945ff16b6681b24d09d16f3f.zip |
Extract `add_sql_comment!` method
Refactor of #22911.
Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb | 21 |
2 files changed, 10 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index d5fe880841..535038d96b 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -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) diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb index 0384079da2..fd2dc2aee8 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb @@ -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 |