提交 a31e8374 编写于 作者: R Ryuta Kamizono

Prevent `table_comment` query if a table doesn't have a comment

上级 f9a39e0d
......@@ -542,7 +542,9 @@ def foreign_keys(table_name)
end
end
def table_options(table_name)
def table_options(table_name) # :nodoc:
table_options = {}
create_table_info = create_table_info(table_name)
# strip create_definitions and partition_options
......@@ -551,10 +553,14 @@ def table_options(table_name)
# strip AUTO_INCREMENT
raw_table_options.sub!(/(ENGINE=\w+)(?: AUTO_INCREMENT=\d+)/, '\1')
table_options[:options] = raw_table_options
# strip COMMENT
raw_table_options.sub!(/ COMMENT='.+'/, '')
if raw_table_options.sub!(/ COMMENT='.+'/, '')
table_options[:comment] = table_comment(table_name)
end
raw_table_options
table_options
end
# Maps logical Rails types to MySQL-specific data types.
......
......@@ -238,6 +238,10 @@ def new_column(*args) # :nodoc:
PostgreSQLColumn.new(*args)
end
def table_options(table_name) # :nodoc:
{ comment: table_comment(table_name) }
end
# Returns a comment stored in database for given table
def table_comment(table_name) # :nodoc:
name = Utils.extract_schema_qualified_name(table_name.to_s)
......
......@@ -132,10 +132,10 @@ def table(table, stream)
tbl.print ", force: :cascade"
table_options = @connection.table_options(table)
tbl.print ", options: #{table_options.inspect}" unless table_options.blank?
if comment = @connection.table_comment(table).presence
tbl.print ", comment: #{comment.inspect}"
if table_options.present?
table_options.each do |key, value|
tbl.print ", #{key}: #{value.inspect}" if value.present?
end
end
tbl.puts " do |t|"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册