fedimovies/mitra-models/migrations/V0032__actor_profile__add_subscriber_count.sql

5 lines
290 B
SQL

ALTER TABLE actor_profile ADD COLUMN subscriber_count INTEGER NOT NULL CHECK (subscriber_count >= 0) DEFAULT 0;
UPDATE actor_profile SET subscriber_count = (
SELECT count(*) FROM relationship WHERE relationship.target_id = actor_profile.id
AND relationship.relationship_type = 3
);