You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
703 B

  1. class CopyStatusStats < ActiveRecord::Migration[5.2]
  2. disable_ddl_transaction!
  3. def up
  4. safety_assured do
  5. Status.unscoped.select('id').find_in_batches(batch_size: 5_000) do |statuses|
  6. execute <<-SQL.squish
  7. INSERT INTO status_stats (status_id, reblogs_count, favourites_count, created_at, updated_at)
  8. SELECT id, reblogs_count, favourites_count, created_at, updated_at
  9. FROM statuses
  10. WHERE id IN (#{statuses.map(&:id).join(', ')})
  11. ON CONFLICT (status_id) DO UPDATE
  12. SET reblogs_count = EXCLUDED.reblogs_count, favourites_count = EXCLUDED.favourites_count
  13. SQL
  14. end
  15. end
  16. end
  17. def down
  18. # Nothing
  19. end
  20. end