mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
Just create new hash instead of enforcing unique hash
This commit is contained in:
20
app/jobs/one_time/generate_unique_heartbeat_hashes_job.rb
Normal file
20
app/jobs/one_time/generate_unique_heartbeat_hashes_job.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class OneTime::GenerateUniqueHeartbeatHashesJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform
|
||||
Heartbeat.find_each do |heartbeat|
|
||||
heartbeat.send(:set_fields_hash!)
|
||||
heartbeat.save!
|
||||
end
|
||||
|
||||
# error if any two heartbeats have the same fields_hash
|
||||
duplicates = false
|
||||
|
||||
Heartbeat.group(:fields_hash).having("count(*) > 1").count.each do |fields_hash, count|
|
||||
puts "Duplicate fields_hash: #{fields_hash} (count: #{count})"
|
||||
duplicates = true
|
||||
end
|
||||
|
||||
raise "Duplicate in fields_hash" if duplicates
|
||||
end
|
||||
end
|
||||
@@ -24,28 +24,11 @@ class UniquenessIndexToHashOnHeartbeats < ActiveRecord::Migration[8.0]
|
||||
:is_write
|
||||
]
|
||||
|
||||
add_column :heartbeats, :fields_hash, :text
|
||||
|
||||
Heartbeat.find_each do |heartbeat|
|
||||
heartbeat.send(:set_fields_hash!)
|
||||
heartbeat.save!
|
||||
end
|
||||
|
||||
# error if any two heartbeats have the same fields_hash
|
||||
duplicates = false
|
||||
Heartbeat.group(:fields_hash).having("count(*) > 1").count.each do |fields_hash, count|
|
||||
puts "Duplicate fields_hash: #{fields_hash} (count: #{count})"
|
||||
duplicates = true
|
||||
end
|
||||
|
||||
raise "Duplicate in fields_hash" if duplicates
|
||||
|
||||
change_column_null :heartbeats, :fields_hash, false
|
||||
add_index :heartbeats, :fields_hash, unique: true
|
||||
|
||||
# clean up the index from ./20250303180842_create_heartbeats.rb
|
||||
remove_index :heartbeats,
|
||||
attributes,
|
||||
unique: true
|
||||
|
||||
add_column :heartbeats, :fields_hash, :text
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user