-- Restore migration 024's counts (which included banned users' likes and comments).
CREATE OR REPLACE VIEW v_feed AS
SELECT
    u.id,
    u.event_id,
    u.user_id,
    usr.display_name AS uploader_name,
    usr.is_banned,
    usr.uploads_hidden,
    u.preview_path,
    u.thumbnail_path,
    u.display_path,
    u.mime_type,
    u.caption,
    u.created_at,
    (SELECT count(*) FROM "like" l WHERE l.upload_id = u.id)                           AS like_count,
    (SELECT count(*) FROM comment c WHERE c.upload_id = u.id AND c.deleted_at IS NULL) AS comment_count
FROM upload u
JOIN "user" usr ON u.user_id = usr.id
WHERE u.deleted_at IS NULL
  AND usr.uploads_hidden = FALSE
  AND usr.is_banned = FALSE;
