Commit 9a9ee0d7 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'ce-4813-fix-ee-projects-destroy_service_spec' into 'master'

Reset column information after the schema is migrated in MigrationsHelpers.schema_migrate_up!

Closes gitlab-ee#4813

See merge request gitlab-org/gitlab-ce!16950
parents 7141344a 0c62b494
...@@ -15,10 +15,6 @@ describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :m ...@@ -15,10 +15,6 @@ describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :m
.to receive(:commits_count=).and_return(nil) .to receive(:commits_count=).and_return(nil)
end end
after do
[Project, MergeRequest, MergeRequestDiff].each(&:reset_column_information)
end
def diffs_to_hashes(diffs) def diffs_to_hashes(diffs)
diffs.as_json(only: Gitlab::Git::Diff::SERIALIZE_KEYS).map(&:with_indifferent_access) diffs.as_json(only: Gitlab::Git::Diff::SERIALIZE_KEYS).map(&:with_indifferent_access)
end end
......
...@@ -7,10 +7,6 @@ describe Gitlab::BackgroundMigration::PopulateMergeRequestMetricsWithEventsData, ...@@ -7,10 +7,6 @@ describe Gitlab::BackgroundMigration::PopulateMergeRequestMetricsWithEventsData,
.to receive(:commits_count=).and_return(nil) .to receive(:commits_count=).and_return(nil)
end end
after do
[Project, MergeRequest, MergeRequestDiff].each(&:reset_column_information)
end
describe '#perform' do describe '#perform' do
let(:mr_with_event) { create(:merge_request) } let(:mr_with_event) { create(:merge_request) }
let!(:merged_event) { create(:event, :merged, target: mr_with_event) } let!(:merged_event) { create(:event, :merged, target: mr_with_event) }
......
...@@ -21,7 +21,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do ...@@ -21,7 +21,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do
events[event] = true events[event] = true
end end
user = build(:user).becomes(user_class).tap(&:save!) user = user_class.create!(email: "user-#{SecureRandom.hex}@example.org", username: "user-#{SecureRandom.hex}", encrypted_password: '12345678')
create_params = { user_id: user.id, level: params[:level], events: events } create_params = { user_id: user.id, level: params[:level], events: events }
notification_setting = described_class::NotificationSetting.create(create_params) notification_setting = described_class::NotificationSetting.create(create_params)
...@@ -37,7 +37,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do ...@@ -37,7 +37,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do
events[event] = true events[event] = true
end end
user = build(:user).becomes(user_class).tap(&:save!) user = user_class.create!(email: "user-#{SecureRandom.hex}@example.org", username: "user-#{SecureRandom.hex}", encrypted_password: '12345678')
create_params = events.merge(user_id: user.id, level: params[:level]) create_params = events.merge(user_id: user.id, level: params[:level])
notification_setting = described_class::NotificationSetting.create(create_params) notification_setting = described_class::NotificationSetting.create(create_params)
......
...@@ -15,18 +15,22 @@ module MigrationsHelpers ...@@ -15,18 +15,22 @@ module MigrationsHelpers
ActiveRecord::Migrator.migrations(migrations_paths) ActiveRecord::Migrator.migrations(migrations_paths)
end end
def reset_column_in_migration_models def clear_schema_cache!
ActiveRecord::Base.connection_pool.connections.each do |conn| ActiveRecord::Base.connection_pool.connections.each do |conn|
conn.schema_cache.clear! conn.schema_cache.clear!
end end
end
described_class.constants.sort.each do |name| def reset_column_in_all_models
const = described_class.const_get(name) clear_schema_cache!
if const.is_a?(Class) && const < ActiveRecord::Base # Reset column information for the most offending classes **after** we
const.reset_column_information # migrated the schema up, otherwise, column information could be outdated
end ActiveRecord::Base.descendants.each { |klass| klass.reset_column_information }
end
# Without that, we get errors because of missing attributes, e.g.
# super: no superclass method `elasticsearch_indexing' for #<ApplicationSetting:0x00007f85628508d8>
ApplicationSetting.define_attribute_methods
end end
def previous_migration def previous_migration
...@@ -45,7 +49,7 @@ module MigrationsHelpers ...@@ -45,7 +49,7 @@ module MigrationsHelpers
migration_schema_version) migration_schema_version)
end end
reset_column_in_migration_models reset_column_in_all_models
end end
def schema_migrate_up! def schema_migrate_up!
...@@ -53,7 +57,7 @@ module MigrationsHelpers ...@@ -53,7 +57,7 @@ module MigrationsHelpers
ActiveRecord::Migrator.migrate(migrations_paths) ActiveRecord::Migrator.migrate(migrations_paths)
end end
reset_column_in_migration_models reset_column_in_all_models
end end
def disable_migrations_output def disable_migrations_output
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment