diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-05-03 18:43:58 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-05-03 18:43:58 -0300 |
commit | b6cc44bfa6b78f380503d3a4bc141bb529fd16bd (patch) | |
tree | 706d337a8b930e08297e0ec316c7fab938ef881f /activerecord/lib/active_record/connection_adapters | |
parent | 8847bed3ebe8cffcae2ec4c85070295783c9f8a4 (diff) | |
parent | 22ba159efcf85d66ff086d0f760d22c239607b77 (diff) | |
download | rails-b6cc44bfa6b78f380503d3a4bc141bb529fd16bd.tar.gz rails-b6cc44bfa6b78f380503d3a4bc141bb529fd16bd.tar.bz2 rails-b6cc44bfa6b78f380503d3a4bc141bb529fd16bd.zip |
Merge pull request #17569 from kamipo/dump_table_options
Correctly dump `:options` on `create_table` for MySQL
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 10 |
2 files changed, 14 insertions, 0 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 c4a37f8538..654ed0250e 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -14,6 +14,10 @@ module ActiveRecord {} end + def table_options(table_name) + nil + end + # Truncates a table alias according to the limits of the current adapter. def table_alias_for(table_name) table_name[0...table_alias_length].tr('.', '_') 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 c37e0da76b..cd51b60616 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -683,6 +683,16 @@ module ActiveRecord end end + def table_options(table_name) + create_table_info = select_one("SHOW CREATE TABLE #{quote_table_name(table_name)}")["Create Table"] + + # strip create_definitions and partition_options + raw_table_options = create_table_info.sub(/\A.*\n\) /m, '').sub(/\n\/\*!.*\*\/\n\z/m, '').strip + + # strip AUTO_INCREMENT + raw_table_options.sub(/(ENGINE=\w+)(?: AUTO_INCREMENT=\d+)/, '\1') + end + # Maps logical Rails types to MySQL-specific data types. def type_to_sql(type, limit = nil, precision = nil, scale = nil) case type.to_s |