From 5cab344494c340ea82a35b46efa06b94f0b7730b Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 11 Jun 2019 19:57:38 +0900 Subject: Clear schema cache when a table is created/dropped/renamed Otherwise `Model.table_exists?` returns the staled cache result. --- .../active_record/connection_adapters/abstract/schema_statements.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb') 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 cf57af5473..c85ea8e1da 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -310,6 +310,8 @@ module ActiveRecord if force drop_table(table_name, force: force, if_exists: true) + else + schema_cache.clear_data_source_cache!(table_name.to_s) end result = execute schema_creation.accept td @@ -499,6 +501,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 = {}) + schema_cache.clear_data_source_cache!(table_name.to_s) execute "DROP TABLE#{' IF EXISTS' if options[:if_exists]} #{quote_table_name(table_name)}" end -- cgit v1.2.3