diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-07-28 10:33:41 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-28 10:33:41 -0300 |
commit | be85efe8db42edb50a4f90e9f39f069bb5479b8e (patch) | |
tree | 0fc67f8da7550ec167305160c8766bce192ad7bf /activerecord/lib/active_record/connection_adapters | |
parent | b3348819c5d6acf13b97cb6c4825f0b1a004f7e9 (diff) | |
parent | a31e837431ee131fbc6900f1b3c3d6ef09753f7a (diff) | |
download | rails-be85efe8db42edb50a4f90e9f39f069bb5479b8e.tar.gz rails-be85efe8db42edb50a4f90e9f39f069bb5479b8e.tar.bz2 rails-be85efe8db42edb50a4f90e9f39f069bb5479b8e.zip |
Merge pull request #25340 from kamipo/prevent_table_comment_query
Prevent `table_comment` query if a table doesn't have a comment
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 4 |
2 files changed, 13 insertions, 3 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 c73159b796..610d78245f 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -547,7 +547,9 @@ module ActiveRecord 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 @@ -556,10 +558,14 @@ module ActiveRecord # 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. diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index cc606e4828..4cf6d4b14a 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -238,6 +238,10 @@ module ActiveRecord 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) |