mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #22547 from kamipo/fix_create_table_info_cache
Correctly cache create_table_info
This commit is contained in:
commit
d3ec85402a
1 changed files with 6 additions and 2 deletions
|
@ -623,6 +623,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
|
||||
|
||||
|
@ -1018,9 +1019,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:
|
||||
|
|
Loading…
Reference in a new issue