1
1
module MigrationsHelpers
2
+ def active_record_base
3
+ ActiveRecord ::Base
4
+ end
5
+
2
6
def table ( name )
3
- Class . new ( ActiveRecord :: Base ) do
7
+ Class . new ( active_record_base ) do
4
8
self . table_name = name
5
9
self . inheritance_column = :_type_disabled
6
10
@@ -19,7 +23,7 @@ def migrations
19
23
end
20
24
21
25
def clear_schema_cache!
22
- ActiveRecord :: Base . connection_pool . connections . each do |conn |
26
+ active_record_base . connection_pool . connections . each do |conn |
23
27
conn . schema_cache . clear!
24
28
end
25
29
end
@@ -40,11 +44,18 @@ def reset_column_in_all_models
40
44
# Reset column information for the most offending classes **after** we
41
45
# migrated the schema up, otherwise, column information could be
42
46
# outdated. We have a separate method for this so we can override it in EE.
43
- ActiveRecord ::Base . descendants . each ( &method ( :reset_column_information ) )
47
+ active_record_base . descendants . each ( &method ( :reset_column_information ) )
48
+ end
44
49
45
- # Without that, we get errors because of missing attributes, e.g.
50
+ def refresh_attribute_methods
51
+ # Without this, we get errors because of missing attributes, e.g.
46
52
# super: no superclass method `elasticsearch_indexing' for #<ApplicationSetting:0x00007f85628508d8>
47
- ApplicationSetting . define_attribute_methods
53
+ # attr_encrypted also expects ActiveRecord attribute methods to be
54
+ # defined, or it will override the accessors:
55
+ # https://gitlab.com/gitlab-org/gitlab-ee/issues/8234#note_113976421
56
+ [ ApplicationSetting , SystemHook ] . each do |model |
57
+ model . define_attribute_methods
58
+ end
48
59
end
49
60
50
61
def reset_column_information ( klass )
@@ -84,6 +95,7 @@ def schema_migrate_up!
84
95
end
85
96
86
97
reset_column_in_all_models
98
+ refresh_attribute_methods
87
99
end
88
100
89
101
def disable_migrations_output
0 commit comments