From df72b999c3cde12fb66bb7f8816a6a5790d0fa2c Mon Sep 17 00:00:00 2001 From: Sinclair Chen Date: Thu, 11 Jul 2024 16:35:29 -0700 Subject: [PATCH] delete composite types this removes the annoying step of undoing the composite type changes whenever you run supabase regen types. --- backend/supabase/functions.sql | 39 ++++++++++++++++-------------- backend/supabase/tv.sql | 16 ------------- common/src/supabase/schema.ts | 43 +++++++++++----------------------- 3 files changed, 36 insertions(+), 62 deletions(-) delete mode 100644 backend/supabase/tv.sql diff --git a/backend/supabase/functions.sql b/backend/supabase/functions.sql index 76b0974086..5627fb0fa9 100644 --- a/backend/supabase/functions.sql +++ b/backend/supabase/functions.sql @@ -576,23 +576,6 @@ or replace function public.creator_rank (uid text) returns integer language sql where data->'creatorTraders'->'allTime' > (select data->'creatorTraders'->'allTime' from users where id = uid) $function$; -create -or replace function public.get_groups_and_scores_from_user_seen_markets (uid text) returns setof group_with_score_and_bet_flag language sql as $function$ -select (g.id, g.data, g.importance_score, false)::group_with_score_and_bet_flag -from - groups g - join group_contracts gc on g.id = gc.group_id - join user_contract_views ucv on gc.contract_id = ucv.contract_id - where ucv.user_id = uid and ucv.page_views > 0 -union -select (g.id, g.data, g.importance_score, true)::group_with_score_and_bet_flag -from - groups g - join group_contracts gc on g.id = gc.group_id - join contract_bets cb on gc.contract_id = cb.contract_id -where cb.user_id = uid -$function$; - create or replace function public.creator_leaderboard (limit_n integer) returns table ( user_id text, @@ -744,6 +727,28 @@ from ( where (politics is false or is_politics = politics) limit count $function$; +create +or replace function public.get_groups_and_scores_from_user_seen_markets (uid text) returns table ( + id text, + data jsonb, + importance_score numeric, + has_bet boolean +) language sql as $function$ +select (g.id, g.data, g.importance_score, false) +from + groups g + join group_contracts gc on g.id = gc.group_id + join user_contract_views ucv on gc.contract_id = ucv.contract_id + where ucv.user_id = uid and ucv.page_views > 0 +union +select (g.id, g.data, g.importance_score, true) +from + groups g + join group_contracts gc on g.id = gc.group_id + join contract_bets cb on gc.contract_id = cb.contract_id +where cb.user_id = uid +$function$; + create or replace function public.get_noob_questions () returns setof contracts language sql as $function$with newbs as ( select id diff --git a/backend/supabase/tv.sql b/backend/supabase/tv.sql deleted file mode 100644 index 722d52a2c8..0000000000 --- a/backend/supabase/tv.sql +++ /dev/null @@ -1,16 +0,0 @@ -create table if not exists - tv_schedule ( - id serial primary key, - schedule_created_time timestamptz default now(), - creator_id text not null, - contract_id text not null, - stream_id text not null, - source text not null, - start_time timestamptz not null, - end_time timestamptz not null, - title text not null, - is_featured boolean default false - ); - -alter publication supabase_realtime -add table tv_schedule; diff --git a/common/src/supabase/schema.ts b/common/src/supabase/schema.ts index bec3ede396..9c1f745145 100644 --- a/common/src/supabase/schema.ts +++ b/common/src/supabase/schema.ts @@ -3302,7 +3302,12 @@ export type Database = { Args: { uid: string } - Returns: Database['public']['CompositeTypes']['group_with_score_and_bet_flag'][] + Returns: { + id: string + data: Json + importance_score: number + has_bet: boolean + }[] } get_love_question_answers_and_lovers: { Args: { @@ -3824,35 +3829,15 @@ export type Database = { status_type: 'new' | 'under review' | 'resolved' | 'needs admin' } CompositeTypes: { - contract_ids: { - contract_id: string - } - contract_score: { - contract_id: string - } - group_with_bet_flag: { - id: string - data: Json - has_bet: boolean - } - group_with_score_and_bet_flag: { - id: string - data: Json - importance_score: number - has_bet: boolean - } - jsonb_data: { - data: Json - } love_question_with_count_type: { - id: number - creator_id: string - created_time: string - question: string - importance_score: number - answer_type: string - multiple_choice_options: Json - answer_count: number + id: number | null + creator_id: string | null + created_time: string | null + question: string | null + importance_score: number | null + answer_type: string | null + multiple_choice_options: Json | null + answer_count: number | null } other_lover_answers_type: { question_id: number | null