Skip to content

Commit

Permalink
regen schema and types
Browse files Browse the repository at this point in the history
  • Loading branch information
sipec committed Jul 17, 2024
1 parent 80591db commit a951360
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 88 deletions.
2 changes: 0 additions & 2 deletions backend/scheduler/src/jobs/update-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ dayjs.extend(timezone)
import {
uniq,
sum,
sumBy,
countBy,
groupBy,
mapValues,
intersection,
mergeWith,
Expand Down
2 changes: 1 addition & 1 deletion backend/supabase/answers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ begin
new.prob_change_week := ((new.data) -> 'probChanges'->>'week')::numeric;
new.prob_change_month := ((new.data) -> 'probChanges'->>'month')::numeric;
new.resolution_time :=
case when new.data ? 'resolutionTime' then millis_to_ts(((new.data) ->> 'resolutionTime')::bigint) end;
case when new.data ? 'resolutionTime' then millis_to_ts(((new.data) ->> 'resolutionTime')::bigint) end;
end if;
return new;
end
Expand Down
8 changes: 4 additions & 4 deletions backend/supabase/contract_bets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ drop index if exists contract_bets_contract_user_id;

create index contract_bets_contract_user_id on public.contract_bets using btree (contract_id, user_id, created_time desc);

drop index if exists contract_bets_user_id_contract_id;

create index contract_bets_user_id_contract_id on public.contract_bets using btree (user_id,contract_id, created_time desc);

drop index if exists contract_bets_created_time;

create index contract_bets_created_time on public.contract_bets using btree (contract_id, created_time desc);
Expand Down Expand Up @@ -132,3 +128,7 @@ create index contract_bets_contract_limit_orders on public.contract_bets using b
is_redemption,
created_time desc
);

drop index if exists contract_bets_user_id_contract_id;

create index contract_bets_user_id_contract_id on public.contract_bets using btree (user_id, contract_id, created_time);
8 changes: 4 additions & 4 deletions backend/supabase/contracts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ drop index if exists contracts_creator_id;

create index contracts_creator_id on public.contracts using btree (creator_id, created_time);

drop index if exists contracts_daily_score;

create index contracts_daily_score on public.contracts using btree (daily_score desc);

drop index if exists contracts_elasticity;

create index contracts_elasticity on public.contracts using btree ((((data ->> 'elasticity'::text))::numeric) desc);
Expand Down Expand Up @@ -205,3 +201,7 @@ create index question_nostop_fts on public.contracts using gin (question_nostop_
drop index if exists market_tier_idx;

create index market_tier_idx on public.contracts using btree (tier);

drop index if exists contracts_daily_score;

create index contracts_daily_score on public.contracts using btree (daily_score desc);
125 changes: 55 additions & 70 deletions backend/supabase/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -238,30 +238,18 @@ where creator_id = any(creator_ids)
group by creator_id;
$function$;

create
or replace function public.get_contracts_in_group_slugs (
contract_ids text[],
group_slugs text[],
ignore_slugs text[]
) returns table (data json, importance_score numeric) language sql stable parallel SAFE as $function$
select data, importance_score
from public_contracts
where id = any(contract_ids)
and (public_contracts.data -> 'groupSlugs' ?| group_slugs)
and not (public_contracts.data -> 'groupSlugs' ?| ignore_slugs)
$function$;

create
or replace function public.get_contracts_in_group_slugs_1 (
contract_ids text[],
p_group_slugs text[],
ignore_slugs text[]
) returns table (data json, importance_score numeric) language sql stable parallel SAFE as $function$
select data, importance_score
from public_contracts
from contracts
where id = any(contract_ids)
and (public_contracts.group_slugs && p_group_slugs)
and not (public_contracts.group_slugs && ignore_slugs)
and visibility = 'public'
and (group_slugs && p_group_slugs)
and not (group_slugs && ignore_slugs)
$function$;

create
Expand Down Expand Up @@ -442,24 +430,6 @@ where
and (contracts.close_time > now() or contracts.close_time is null)
$function$;

create
or replace function public.get_non_empty_private_message_channel_ids (
p_user_id text,
p_ignored_statuses text[],
p_limit integer
) returns setof private_user_message_channels language sql as $function$
select distinct pumc.*
from private_user_message_channels pumc
join private_user_message_channel_members pumcm on pumcm.channel_id = pumc.id
left join private_user_messages pum on pumc.id = pum.channel_id
and (pum.visibility != 'introduction' or pum.user_id != p_user_id)
where pumcm.user_id = p_user_id
and pumcm.status not in (select unnest(p_ignored_statuses))
and pum.id is not null
order by pumc.last_updated_time desc
limit p_limit;
$function$;

create
or replace function public.get_non_empty_private_message_channel_ids (
p_user_id text,
Expand All @@ -481,6 +451,24 @@ BEGIN
END;
$function$;

create
or replace function public.get_non_empty_private_message_channel_ids (
p_user_id text,
p_ignored_statuses text[],
p_limit integer
) returns setof private_user_message_channels language sql as $function$
select distinct pumc.*
from private_user_message_channels pumc
join private_user_message_channel_members pumcm on pumcm.channel_id = pumc.id
left join private_user_messages pum on pumc.id = pum.channel_id
and (pum.visibility != 'introduction' or pum.user_id != p_user_id)
where pumcm.user_id = p_user_id
and pumcm.status not in (select unnest(p_ignored_statuses))
and pum.id is not null
order by pumc.last_updated_time desc
limit p_limit;
$function$;

create
or replace function public.get_noob_questions () returns setof contracts language sql as $function$with newbs as (
select id
Expand Down Expand Up @@ -581,31 +569,19 @@ or replace function public.get_rating (user_id text) returns table (count bigint
FROM total_count,rating;
$function$;

create
or replace function public.get_recently_active_contracts_in_group_slugs (
group_slugs text[],
ignore_slugs text[],
max integer
) returns table (data json, importance_score numeric) language sql stable parallel SAFE as $function$
select data, importance_score
from public_contracts
where (public_contracts.data -> 'groupSlugs' ?| group_slugs)
and not (public_contracts.data -> 'groupSlugs' ?| ignore_slugs)
order by ((data->>'lastUpdatedTime')::bigint) desc
limit max
$function$;

create
or replace function public.get_recently_active_contracts_in_group_slugs_1 (
p_group_slugs text[],
ignore_slugs text[],
max integer
) returns table (data json, importance_score numeric) language sql stable parallel SAFE as $function$
select data, importance_score
from public_contracts
where (public_contracts.group_slugs && p_group_slugs)
and not (public_contracts.group_slugs && ignore_slugs)
order by ((data->>'lastUpdatedTime')::bigint) desc
from contracts
where
visibility = 'public'
and (group_slugs && p_group_slugs)
and not (group_slugs && ignore_slugs)
order by last_updated_time desc
limit max
$function$;

Expand Down Expand Up @@ -763,23 +739,23 @@ $function$;
create
or replace function public.get_user_bets_from_resolved_contracts (uid text, count integer, start integer) returns table (contract_id text, bets jsonb[], contract jsonb) language sql stable parallel SAFE as $function$;
select contract_id,
bets.data as bets,
c.data as contracts
bets.data as bets,
c.data as contracts
from (
select contract_id,
array_agg(
data
order by created_time desc
) as data
from contract_bets
where user_id = uid
and amount != 0
group by contract_id
) as bets
join contracts c on c.id = bets.contract_id
select contract_id,
array_agg(
data
order by created_time desc
) as data
from contract_bets
where user_id = uid
and amount != 0
group by contract_id
) as bets
join contracts c on c.id = bets.contract_id
where c.resolution_time is not null
and c.outcome_type = 'BINARY'
order by c.resolution_time desc
order by c.resolution_time desc
limit count offset start $function$;

create
Expand Down Expand Up @@ -866,6 +842,15 @@ union
select contract_id
from your_followed_contracts $function$;

create
or replace function public.get_your_daily_changed_contracts (uid text, n integer, start integer) returns table (data jsonb, daily_score real) language sql stable parallel SAFE as $function$
select data,
coalesce((data->>'dailyScore')::real, 0.0) as daily_score
from get_your_contract_ids(uid)
left join contracts on contracts.id = contract_id
where contracts.outcome_type = 'BINARY'
order by daily_score desc
limit n offset start $function$;

create
or replace function public.get_your_recent_contracts (uid text, n integer, start integer) returns table (data jsonb, max_ts bigint) language sql stable parallel SAFE as $function$
Expand Down Expand Up @@ -1233,11 +1218,11 @@ or replace function public.top_creators_for_user (uid text, excluded_ids text[],
$function$;

create
or replace function public.ts_to_millis (ts timestamp with time zone) returns bigint language sql immutable parallel SAFE as $function$
select (extract(epoch from ts) * 1000)::bigint
or replace function public.ts_to_millis (ts timestamp without time zone) returns bigint language sql immutable parallel SAFE as $function$
select extract(epoch from ts)::bigint * 1000
$function$;

create
or replace function public.ts_to_millis (ts timestamp without time zone) returns bigint language sql immutable parallel SAFE as $function$
select extract(epoch from ts)::bigint * 1000
or replace function public.ts_to_millis (ts timestamp with time zone) returns bigint language sql immutable parallel SAFE as $function$
select (extract(epoch from ts) * 1000)::bigint
$function$;
3 changes: 0 additions & 3 deletions backend/supabase/private_user_message_channel_members.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ create table if not exists
notify_after_time timestamp with time zone default now() not null
);

-- Policies
alter table private_user_message_channel_members enable row level security;

-- Indexes
drop index if exists private_user_message_channel_members_pkey;

Expand Down
3 changes: 0 additions & 3 deletions backend/supabase/private_user_messages.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ create table if not exists
visibility text default 'private'::text not null
);

-- Policies
alter table private_user_messages enable row level security;

-- Indexes
drop index if exists private_user_messages_pkey;

Expand Down
5 changes: 4 additions & 1 deletion backend/supabase/user_notifications.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ create index user_notifications_notification_id on public.user_notifications usi

drop index if exists user_notifications_user_id_created_time;

create index user_notifications_user_id_created_time on user_notifications(user_id, ((data->'createdTime')::bigint) desc);
create index user_notifications_user_id_created_time on public.user_notifications using btree (
user_id,
(((data -> 'createdTime'::text))::bigint) desc
);
7 changes: 7 additions & 0 deletions common/src/supabase/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type Database = {
prob_change_day: number | null
prob_change_month: number | null
prob_change_week: number | null
resolution_time: string | null
subsidy_pool: number | null
text: string | null
text_fts: unknown | null
Expand All @@ -40,6 +41,7 @@ export type Database = {
prob_change_day?: number | null
prob_change_month?: number | null
prob_change_week?: number | null
resolution_time?: string | null
subsidy_pool?: number | null
text?: string | null
text_fts?: unknown | null
Expand All @@ -58,6 +60,7 @@ export type Database = {
prob_change_day?: number | null
prob_change_month?: number | null
prob_change_week?: number | null
resolution_time?: string | null
subsidy_pool?: number | null
text?: string | null
text_fts?: unknown | null
Expand Down Expand Up @@ -396,6 +399,7 @@ export type Database = {
conversion_score: number
created_time: string | null
creator_id: string | null
daily_score: number
data: Json
deleted: boolean | null
description_fts: unknown | null
Expand Down Expand Up @@ -428,6 +432,7 @@ export type Database = {
conversion_score?: number
created_time?: string | null
creator_id?: string | null
daily_score?: number
data: Json
deleted?: boolean | null
description_fts?: unknown | null
Expand Down Expand Up @@ -460,6 +465,7 @@ export type Database = {
conversion_score?: number
created_time?: string | null
creator_id?: string | null
daily_score?: number
data?: Json
deleted?: boolean | null
description_fts?: unknown | null
Expand Down Expand Up @@ -3289,6 +3295,7 @@ export type Database = {
conversion_score: number
created_time: string | null
creator_id: string | null
daily_score: number
data: Json
deleted: boolean | null
description_fts: unknown | null
Expand Down

0 comments on commit a951360

Please sign in to comment.