diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2015-12-10 18:29:28 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2015-12-17 06:31:22 +0900 |
commit | 228ed57de8679892199b9fe7a1d9d704e5e5fac7 (patch) | |
tree | 2c3d9831288613cfa251491026db337f4205ff84 /activerecord | |
parent | f39aa4dd3995a9d11b426af7f12841d515673a4c (diff) | |
download | rails-228ed57de8679892199b9fe7a1d9d704e5e5fac7.tar.gz rails-228ed57de8679892199b9fe7a1d9d704e5e5fac7.tar.bz2 rails-228ed57de8679892199b9fe7a1d9d704e5e5fac7.zip |
Correctly cache create_table_info
Follow up to #21664.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 8 |
1 files changed, 6 insertions, 2 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 25ba42e5c9..01a9fd8763 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -637,6 +637,7 @@ module ActiveRecord # it can be helpful to provide these in a migration's +change+ method so it can be reverted. # In that case, +options+ and the block will be used by create_table. def drop_table(table_name, options = {}) + create_table_info_cache.delete(table_name) if create_table_info_cache.key?(table_name) execute "DROP#{' TEMPORARY' if options[:temporary]} TABLE#{' IF EXISTS' if options[:if_exists]} #{quote_table_name(table_name)}#{' CASCADE' if options[:force] == :cascade}" end @@ -1032,9 +1033,12 @@ module ActiveRecord end end + def create_table_info_cache # :nodoc: + @create_table_info_cache ||= {} + end + def create_table_info(table_name) # :nodoc: - @create_table_info_cache = {} - @create_table_info_cache[table_name] ||= select_one("SHOW CREATE TABLE #{quote_table_name(table_name)}")["Create Table"] + create_table_info_cache[table_name] ||= select_one("SHOW CREATE TABLE #{quote_table_name(table_name)}")["Create Table"] end def create_table_definition(name, temporary = false, options = nil, as = nil) # :nodoc: |