From 6b0913b6bcdaa51e7a2dfc73ea8cb6c90f78cb6b Mon Sep 17 00:00:00 2001 From: mtrela <mtrela@syncad.com> Date: Mon, 14 Sep 2020 12:34:30 +0200 Subject: [PATCH] Added a view `hive_accounts_info_view` into `upgrade.sql` file --- scripts/upgrade.sql | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/scripts/upgrade.sql b/scripts/upgrade.sql index e2e3cd536..f32748ee1 100644 --- a/scripts/upgrade.sql +++ b/scripts/upgrade.sql @@ -90,3 +90,56 @@ $function$ JOIN hive_posts_view hp ON hp.id = trends.id ORDER BY trends.trend DESC $function$ language sql + +DROP VIEW IF EXISTS public.hive_accounts_info_view; + +CREATE OR REPLACE VIEW public.hive_accounts_info_view +AS +SELECT + id, + name, + ( + select count(*) post_count + FROM hive_posts hp + WHERE ha.id=hp.author_id + ) post_count, + created_at, + ( + SELECT GREATEST + ( + created_at, + COALESCE( + ( + select max(hp.created_at) + FROM hive_posts hp + WHERE ha.id=hp.author_id + ), + '1970-01-01 00:00:00.0' + ), + COALESCE( + ( + select max(hv.last_update) + from hive_votes hv + WHERE ha.id=hv.voter_id + ), + '1970-01-01 00:00:00.0' + ) + ) + ) active_at, + display_name, + about, + reputation, + profile_image, + location, + website, + cover_image, + rank, + following, + followers, + proxy, + proxy_weight, + lastread_at, + cached_at, + raw_json +FROM + hive_accounts ha -- GitLab