blob: 6da76803f7cec1a01d9c5c41a5e27d33b9eb673f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# frozen_string_literal: true
module Gitlab
module Database
module SchemaCacheWithRenamedTable
# Override methods in ActiveRecord::ConnectionAdapters::SchemaCache
def clear!
super
clear_renamed_tables_cache!
end
def clear_data_source_cache!(name)
super(name)
clear_renamed_tables_cache!
end
def primary_keys(table_name)
super(underlying_table(table_name))
end
def columns(table_name)
super(underlying_table(table_name))
end
def columns_hash(table_name)
super(underlying_table(table_name))
end
def indexes(table_name)
super(underlying_table(table_name))
end
private
def underlying_table(table_name)
renamed_tables_cache.fetch(table_name, table_name)
end
def renamed_tables_cache
@renamed_tables ||= Gitlab::Database::TABLES_TO_BE_RENAMED.select do |old_name, new_name|
connection.view_exists?(old_name)
end
end
def clear_renamed_tables_cache!
@renamed_tables = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
end
end
end
|