diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-10-09 23:45:24 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-09 23:45:24 -0300 |
commit | 02989ee38f8cc5e82e7106ff8689d4635b016f40 (patch) | |
tree | 7ab56cbfac198eeaa9a9eca514b3a9006607c1a4 | |
parent | 88e00d303df5caad9393f81a12a1eaf227b2e293 (diff) | |
parent | 72bf3ded097f1c492f00bd07c9148ef0bf1d3973 (diff) | |
download | rails-02989ee38f8cc5e82e7106ff8689d4635b016f40.tar.gz rails-02989ee38f8cc5e82e7106ff8689d4635b016f40.tar.bz2 rails-02989ee38f8cc5e82e7106ff8689d4635b016f40.zip |
Merge pull request #26735 from kamipo/prevent_to_create_blank_comment
Prevent to create blank comment
3 files changed, 8 insertions, 6 deletions
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 29520ed9c8..51819f7980 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -284,10 +284,10 @@ module ActiveRecord end if supports_comments? && !supports_comments_in_create? - change_table_comment(table_name, comment) if comment + change_table_comment(table_name, comment) if comment.present? td.columns.each do |column| - change_column_comment(table_name, column.name, column.comment) if column.comment + change_column_comment(table_name, column.name, column.comment) if column.comment.present? end end 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 be8511f119..5923136df8 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -509,7 +509,7 @@ module ActiveRecord end def add_sql_comment!(sql, comment) # :nodoc: - sql << " COMMENT #{quote(comment)}" if comment + sql << " COMMENT #{quote(comment)}" if comment.present? sql end diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index ab2d64e903..41fed004a0 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -128,9 +128,7 @@ HEADER table_options = @connection.table_options(table) if table_options.present? - table_options.each do |key, value| - tbl.print ", #{key}: #{value.inspect}" if value.present? - end + tbl.print ", #{format_options(table_options)}" end tbl.puts " do |t|" @@ -237,6 +235,10 @@ HEADER end end + def format_options(options) + options.map { |key, value| "#{key}: #{value.inspect}" if value }.compact.join(", ") + end + def remove_prefix_and_suffix(table) table.gsub(/^(#{@options[:table_name_prefix]})(.+)(#{@options[:table_name_suffix]})$/, "\\2") end |