mastodon/db/migrate/20180812173710_copy_status_stats.rb
Eugen Rochko 8e111b753a
Move status counters to separate table, count replies (#8104)
* Move status counters to separate table, count replies

* Migration to remove old counter columns from statuses table

* Fix schema file
2018-08-14 19:19:32 +02:00

20 lines
490 B
Ruby

class CopyStatusStats < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
def up
safety_assured do
execute <<-SQL.squish
INSERT INTO status_stats (status_id, reblogs_count, favourites_count)
SELECT id, reblogs_count, favourites_count
FROM statuses
ON CONFLICT (status_id) DO UPDATE
SET reblogs_count = EXCLUDED.reblogs_count, favourites_count = EXCLUDED.favourites_count
SQL
end
end
def down
# Nothing
end
end