Skip to content

Commit

Permalink
Prevent to create blank comment
Browse files Browse the repository at this point in the history
Currently blank comment does not dump to `db/schema.rb`. But created it
even if specified blank.
  • Loading branch information
kamipo committed Oct 8, 2016
1 parent 0fc1157 commit 72bf3de
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ def create_table(table_name, comment: nil, **options)
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def add_index(table_name, column_name, options = {}) #:nodoc:
end

def add_sql_comment!(sql, comment) # :nodoc:
sql << " COMMENT #{quote(comment)}" if comment
sql << " COMMENT #{quote(comment)}" if comment.present?
sql
end

Expand Down
8 changes: 5 additions & 3 deletions activerecord/lib/active_record/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ def table(table, stream)

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|"
Expand Down Expand Up @@ -237,6 +235,10 @@ def foreign_keys(table, stream)
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
Expand Down

0 comments on commit 72bf3de

Please sign in to comment.