From 81ba787c56735d0815ca1aa0558f3f2cadd45a67 Mon Sep 17 00:00:00 2001 From: harisato Date: Fri, 4 Aug 2023 13:55:16 +0700 Subject: [PATCH] feat(hasura): add total creator subscribers --- .../punkga-pg/tables/public_creators.yaml | 10 +++++ hasura/metadata/query_collections.yaml | 37 ++++++++++--------- .../down.sql | 9 +++++ .../up.sql | 7 ++++ 4 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 hasura/migrations/punkga-pg/1691132025036_calculate total_creator_subscribers /down.sql create mode 100644 hasura/migrations/punkga-pg/1691132025036_calculate total_creator_subscribers /up.sql diff --git a/hasura/metadata/databases/punkga-pg/tables/public_creators.yaml b/hasura/metadata/databases/punkga-pg/tables/public_creators.yaml index 9767dd4f..59379d29 100644 --- a/hasura/metadata/databases/punkga-pg/tables/public_creators.yaml +++ b/hasura/metadata/databases/punkga-pg/tables/public_creators.yaml @@ -9,6 +9,12 @@ array_relationships: table: name: manga_creator schema: public +computed_fields: + - name: total_subscribers + definition: + function: + name: total_creator_subscribers + schema: public select_permissions: - role: anonymous permission: @@ -22,6 +28,8 @@ select_permissions: - name - created_at - updated_at + computed_fields: + - total_subscribers filter: {} allow_aggregations: true - role: user @@ -36,6 +44,8 @@ select_permissions: - name - created_at - updated_at + computed_fields: + - total_subscribers filter: {} limit: 20 allow_aggregations: true diff --git a/hasura/metadata/query_collections.yaml b/hasura/metadata/query_collections.yaml index e5c854ee..1a0eff18 100644 --- a/hasura/metadata/query_collections.yaml +++ b/hasura/metadata/query_collections.yaml @@ -346,24 +346,6 @@ signup_methods } } - - name: Admin - Query creators - query: | - query QueryCreators { - creators(order_by: {created_at:desc}) { - id - name - manga_creators_aggregate { - aggregate { - count - } - } - subcribers - created_at - socials - isActive - bio - } - } - name: Admin - Get chapter detail query: | query GetChapterDetail ($manga_id: Int = 18, $chapter_number: Int = 1) { @@ -844,3 +826,22 @@ } } } + - name: Admin - Query creators + query: | + query QueryCreators { + creators(order_by: {created_at:desc}) { + id + name + total_subscribers + manga_creators_aggregate { + aggregate { + count + } + } + subcribers + created_at + socials + isActive + bio + } + } diff --git a/hasura/migrations/punkga-pg/1691132025036_calculate total_creator_subscribers /down.sql b/hasura/migrations/punkga-pg/1691132025036_calculate total_creator_subscribers /down.sql new file mode 100644 index 00000000..e553b279 --- /dev/null +++ b/hasura/migrations/punkga-pg/1691132025036_calculate total_creator_subscribers /down.sql @@ -0,0 +1,9 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- CREATE OR REPLACE FUNCTION total_creator_subscribers(creator_row creators) RETURNS +-- int +-- AS $$ +-- SELECT COUNT(1) as total_subscribers FROM public.subscribers +-- INNER JOIN manga_creator mc on subscribers.manga_id = mc.manga_id +-- WHERE mc.creator_id = creator_row.id +-- $$ LANGUAGE sql STABLE; diff --git a/hasura/migrations/punkga-pg/1691132025036_calculate total_creator_subscribers /up.sql b/hasura/migrations/punkga-pg/1691132025036_calculate total_creator_subscribers /up.sql new file mode 100644 index 00000000..30cff317 --- /dev/null +++ b/hasura/migrations/punkga-pg/1691132025036_calculate total_creator_subscribers /up.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE FUNCTION total_creator_subscribers(creator_row creators) RETURNS +int +AS $$ + SELECT COUNT(1) as total_subscribers FROM public.subscribers + INNER JOIN manga_creator mc on subscribers.manga_id = mc.manga_id + WHERE mc.creator_id = creator_row.id +$$ LANGUAGE sql STABLE;