Follow up - c3fce714dc
- Running Scheduler has outdated column information and disables Stats.generate job.
This commit is contained in:
parent
b72a15a017
commit
09d2d4df58
1 changed files with 9 additions and 2 deletions
|
@ -8,13 +8,21 @@ class StatsStorePolymorphicAssociation < ActiveRecord::Migration[5.2]
|
||||||
# create empty, indexed polymorphic association columns
|
# create empty, indexed polymorphic association columns
|
||||||
add_reference :stats_stores, :stats_storable, polymorphic: true, index: true
|
add_reference :stats_stores, :stats_storable, polymorphic: true, index: true
|
||||||
|
|
||||||
|
# set last run 20 min in future to avoid scheduler errors until restart
|
||||||
|
Scheduler.find_by(method: 'Stats.generate').update(last_run: 20.minutes.from_now)
|
||||||
|
|
||||||
# migrate column data in the most performance way
|
# migrate column data in the most performance way
|
||||||
object_lookup_map.each do |id, model|
|
object_lookup_map.each do |id, model|
|
||||||
StatsStore.where(stats_store_object_id: id)
|
StatsStore.where(stats_store_object_id: id)
|
||||||
.update_all("stats_storable_id = o_id, stats_storable_type = '#{model}'") # rubocop:disable Rails/SkipsModelValidations
|
.update_all("stats_storable_id = o_id, stats_storable_type = '#{model}'") # rubocop:disable Rails/SkipsModelValidations
|
||||||
end
|
end
|
||||||
|
|
||||||
# rubocop:disable Rails/ReversibleMigration
|
remove_unneeded_columns
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def remove_unneeded_columns
|
||||||
# remove home made "polymorphic association" columns
|
# remove home made "polymorphic association" columns
|
||||||
remove_column :stats_stores, :o_id
|
remove_column :stats_stores, :o_id
|
||||||
remove_column :stats_stores, :stats_store_object_id
|
remove_column :stats_stores, :stats_store_object_id
|
||||||
|
@ -22,6 +30,5 @@ class StatsStorePolymorphicAssociation < ActiveRecord::Migration[5.2]
|
||||||
# remove unused/obsolete columns
|
# remove unused/obsolete columns
|
||||||
remove_column :stats_stores, :related_stats_store_object_id
|
remove_column :stats_stores, :related_stats_store_object_id
|
||||||
remove_column(:stats_stores, :related_o_id) if StatsStore.column_names.include?('related_o_id')
|
remove_column(:stats_stores, :related_o_id) if StatsStore.column_names.include?('related_o_id')
|
||||||
# rubocop:enable Rails/ReversibleMigration
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue