more accurately detect if schema cache needs cleared

and add override to force-clear it

Change-Id: I05a4b68be963ca8eceace456cc2d81f4556a9da6
Reviewed-on: https://gerrit.instructure.com/160992
Tested-by: Jenkins
Reviewed-by: James Williams  <jamesw@instructure.com>
Reviewed-by: Rob Orton <rob@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2018-08-15 17:20:55 -06:00
parent 4282b958ee
commit 6a36bcc3f5
1 changed files with 20 additions and 1 deletions

View File

@ -2,7 +2,26 @@
# not once per shard, and after the migrations have run
%w{db:migrate db:migrate:predeploy db:migrate:up db:migrate:down db:rollback}.each do |task_name|
Rake::Task[task_name].enhance do
ActiveRecord::Base.connection.tables.each do |table_name|
def sanitize_sequences(columns)
columns.map do |details|
details[2] = 'sequence' if details[2]&.start_with?('nextval')
details
end
end
connection = ActiveRecord::Base.connection
connection.tables.each do |table_name|
unless ENV['CLEAR_SCHEMA_CACHE']
cached_value = sanitize_sequences(connection.column_definitions(table_name))
ActiveRecord::Base.in_migration = true
actual_value =
begin
sanitize_sequences(connection.column_definitions(table_name))
ensure
ActiveRecord::Base.in_migration = false
end
next if cached_value == actual_value
end
MultiCache.delete(["schema", table_name])
end
end