2018-08-15 03:19:32 +10:00
|
|
|
class CopyStatusStats < ActiveRecord::Migration[5.2]
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
def up
|
|
|
|
safety_assured do
|
2018-08-19 10:01:49 +10:00
|
|
|
Status.unscoped.select('id').find_in_batches(batch_size: 5_000) do |statuses|
|
2018-08-18 11:44:50 +10:00
|
|
|
execute <<-SQL.squish
|
|
|
|
INSERT INTO status_stats (status_id, reblogs_count, favourites_count, created_at, updated_at)
|
|
|
|
SELECT id, reblogs_count, favourites_count, created_at, updated_at
|
|
|
|
FROM statuses
|
|
|
|
WHERE id IN (#{statuses.map(&:id).join(', ')})
|
|
|
|
ON CONFLICT (status_id) DO UPDATE
|
|
|
|
SET reblogs_count = EXCLUDED.reblogs_count, favourites_count = EXCLUDED.favourites_count
|
|
|
|
SQL
|
|
|
|
end
|
2018-08-15 03:19:32 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# Nothing
|
|
|
|
end
|
|
|
|
end
|