From 8e111b753a3411b258cdb008c9a53bad696f4df1 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 14 Aug 2018 19:19:32 +0200 Subject: 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 --- db/migrate/20180812173710_copy_status_stats.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 db/migrate/20180812173710_copy_status_stats.rb (limited to 'db/migrate/20180812173710_copy_status_stats.rb') diff --git a/db/migrate/20180812173710_copy_status_stats.rb b/db/migrate/20180812173710_copy_status_stats.rb new file mode 100644 index 000000000..6ecccc0ae --- /dev/null +++ b/db/migrate/20180812173710_copy_status_stats.rb @@ -0,0 +1,19 @@ +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 -- cgit From be13e95d066bcef058abb88790d5cdff74f57a21 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 14 Aug 2018 20:24:36 +0200 Subject: Fix null constraint violation in copy status stats migration (#8198) --- db/migrate/20180812173710_copy_status_stats.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'db/migrate/20180812173710_copy_status_stats.rb') diff --git a/db/migrate/20180812173710_copy_status_stats.rb b/db/migrate/20180812173710_copy_status_stats.rb index 6ecccc0ae..64a564ca0 100644 --- a/db/migrate/20180812173710_copy_status_stats.rb +++ b/db/migrate/20180812173710_copy_status_stats.rb @@ -4,8 +4,8 @@ class CopyStatusStats < ActiveRecord::Migration[5.2] def up safety_assured do execute <<-SQL.squish - INSERT INTO status_stats (status_id, reblogs_count, favourites_count) - SELECT id, reblogs_count, favourites_count + 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 ON CONFLICT (status_id) DO UPDATE SET reblogs_count = EXCLUDED.reblogs_count, favourites_count = EXCLUDED.favourites_count -- cgit