mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-13 17:20:14 +00:00
Optimize message count migration
This commit is contained in:
parent
8ac2f1e4b8
commit
920c8cff01
1 changed files with 3 additions and 1 deletions
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
-- Add message count row to members table, initialize it with the correct data
|
-- Add message count row to members table, initialize it with the correct data
|
||||||
alter table members add column message_count int not null default 0;
|
alter table members add column message_count int not null default 0;
|
||||||
update members set message_count = (select count(*) from messages where messages.member = members.id);
|
|
||||||
|
|
||||||
|
update members set message_count = counts.count
|
||||||
|
from (select member, count(*) as count from messages group by messages.member) as counts
|
||||||
|
where counts.member = members.id;
|
||||||
|
|
||||||
-- Create a trigger function to increment the message count on inserting to the messages table
|
-- Create a trigger function to increment the message count on inserting to the messages table
|
||||||
create function trg_msgcount_increment() returns trigger as $$
|
create function trg_msgcount_increment() returns trigger as $$
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue