From 93967fef8e94421bfe4ceb9ec1500351c0c2f610 Mon Sep 17 00:00:00 2001 From: ingawei Date: Fri, 6 Dec 2024 11:29:25 -0800 Subject: [PATCH] revert supabase automatic changes --- backend/supabase/answers.sql | 76 +- backend/supabase/audit_events.sql | 36 +- backend/supabase/chart_annotations.sql | 65 +- backend/supabase/chat_messages.sql | 28 + backend/supabase/contract_bets.sql | 129 ++-- backend/supabase/contract_comment_edits.sql | 40 +- backend/supabase/contract_comments.sql | 87 ++- backend/supabase/contract_edits.sql | 42 +- backend/supabase/contract_embeddings.sql | 37 +- backend/supabase/contract_follows.sql | 36 +- backend/supabase/contract_liquidity.sql | 30 +- backend/supabase/contracts.sql | 264 ++++--- .../supabase/creator_portfolio_history.sql | 42 +- backend/supabase/daily_stats.sql | 72 +- backend/supabase/dashboard_follows.sql | 24 +- backend/supabase/dashboard_groups.sql | 32 +- backend/supabase/dashboards.sql | 58 +- backend/supabase/delete_after_reading.sql | 25 +- backend/supabase/discord_messages_markets.sql | 27 +- backend/supabase/discord_users.sql | 21 +- backend/supabase/functions.sql | 687 +++++++----------- backend/supabase/gidx_receipts.sql | 73 +- backend/supabase/group_contracts.sql | 49 +- backend/supabase/group_embeddings.sql | 35 +- backend/supabase/group_groups.sql | 32 +- backend/supabase/group_invites.sql | 71 +- backend/supabase/group_members.sql | 70 +- backend/supabase/groups.sql | 62 +- backend/supabase/kyc_bonus_rewards.sql | 34 +- backend/supabase/league_chats.sql | 42 +- backend/supabase/leagues.sql | 46 +- backend/supabase/love_answers.sql | 71 +- .../supabase/love_compatibility_answers.sql | 73 +- backend/supabase/love_likes.sql | 38 +- backend/supabase/love_questions.sql | 34 +- backend/supabase/love_ships.sql | 46 +- backend/supabase/love_stars.sql | 32 +- backend/supabase/love_waitlist.sql | 28 +- backend/supabase/lover_comments.sql | 46 +- backend/supabase/lovers.sql | 124 ++-- backend/supabase/mana_supply_stats.sql | 60 +- backend/supabase/manachan_tweets.sql | 36 +- backend/supabase/manalink_claims.sql | 28 +- backend/supabase/manalinks.sql | 42 +- backend/supabase/market_ads.sql | 49 +- backend/supabase/mod_reports.sql | 28 +- backend/supabase/news.sql | 48 +- backend/supabase/old_post_comments.sql | 56 +- backend/supabase/old_posts.sql | 49 +- backend/supabase/platform_calibration.sql | 28 +- backend/supabase/portfolios.sql | 34 +- backend/supabase/posts.sql | 58 +- .../private_user_message_channel_members.sql | 39 +- .../private_user_message_channels.sql | 28 +- backend/supabase/private_user_messages.sql | 31 +- .../supabase/private_user_phone_numbers.sql | 35 +- .../private_user_seen_message_channels.sql | 51 +- backend/supabase/private_users.sql | 36 +- .../supabase/push_notification_tickets.sql | 33 +- backend/supabase/q_and_a.sql | 36 +- backend/supabase/q_and_a_answers.sql | 36 +- backend/supabase/redemption_status.sql | 31 +- backend/supabase/reports.sql | 32 +- backend/supabase/reviews.sql | 26 +- backend/supabase/scheduler_info.sql | 36 +- backend/supabase/sent_emails.sql | 27 +- backend/supabase/stats.sql | 26 +- backend/supabase/system_trading_status.sql | 26 +- backend/supabase/topic_embeddings.sql | 31 +- backend/supabase/tv_schedule.sql | 32 +- backend/supabase/txn_summary_stats.sql | 42 +- backend/supabase/txns.sql | 83 ++- backend/supabase/user_comment_view_events.sql | 29 +- .../supabase/user_contract_interactions.sql | 45 +- backend/supabase/user_contract_metrics.sql | 27 +- backend/supabase/user_contract_views.sql | 79 +- backend/supabase/user_disinterests.sql | 48 +- backend/supabase/user_embeddings.sql | 35 +- backend/supabase/user_events.sql | 54 +- backend/supabase/user_follows.sql | 30 +- backend/supabase/user_monitor_status.sql | 37 +- backend/supabase/user_notifications.sql | 45 +- backend/supabase/user_portfolio_history.sql | 64 +- .../user_portfolio_history_latest.sql | 36 +- backend/supabase/user_quest_metrics.sql | 32 +- backend/supabase/user_reactions.sql | 44 +- backend/supabase/user_seen_chats.sql | 41 +- backend/supabase/user_topic_interests.sql | 27 +- backend/supabase/user_topics.sql | 35 +- backend/supabase/user_view_events.sql | 39 +- backend/supabase/users.sql | 82 ++- backend/supabase/views.sql | 159 ++-- backend/supabase/votes.sql | 28 +- 93 files changed, 2767 insertions(+), 2346 deletions(-) create mode 100644 backend/supabase/chat_messages.sql diff --git a/backend/supabase/answers.sql b/backend/supabase/answers.sql index 9d0180e97b..9fad9122cc 100644 --- a/backend/supabase/answers.sql +++ b/backend/supabase/answers.sql @@ -1,42 +1,48 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS answers ( - color text, - contract_id text, - created_time timestamp with time zone DEFAULT now(), - id text PRIMARY KEY DEFAULT random_alphanumeric(12) NOT NULL, - index integer, - is_other boolean DEFAULT false NOT NULL, - pool_no numeric, - pool_yes numeric, - prob numeric, - prob_change_day numeric DEFAULT 0, - prob_change_month numeric DEFAULT 0, - prob_change_week numeric DEFAULT 0, - resolution text, - resolution_probability numeric, - resolution_time timestamp with time zone, - resolver_id text, - subsidy_pool numeric DEFAULT 0, - text text, - text_fts tsvector GENERATED ALWAYS AS (to_tsvector('english_extended'::regconfig, text)) STORED, - total_liquidity numeric DEFAULT 0, - user_id text -); - - +create table if not exists + answers ( + color text, + contract_id text, + created_time timestamp with time zone default now(), + id text primary key default random_alphanumeric (12) not null, + index integer, + is_other boolean default false not null, + pool_no numeric, + pool_yes numeric, + prob numeric, + prob_change_day numeric default 0, + prob_change_month numeric default 0, + prob_change_week numeric default 0, + resolution text, + resolution_probability numeric, + resolution_time timestamp with time zone, + resolver_id text, + subsidy_pool numeric default 0, + text text, + text_fts tsvector generated always as (to_tsvector('english_extended'::regconfig, text)) stored, + total_liquidity numeric default 0, + user_id text + ); -- Row Level Security -ALTER TABLE answers ENABLE ROW LEVEL SECURITY; +alter table answers enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON answers; -CREATE POLICY "public read" ON answers FOR SELECT USING (true) ; +drop policy if exists "public read" on answers; + +create policy "public read" on answers for +select + using (true); -- Indexes -DROP INDEX IF EXISTS answer_contract_id; -CREATE INDEX answer_contract_id ON public.answers USING btree (contract_id); -DROP INDEX IF EXISTS answer_text_fts; -CREATE INDEX answer_text_fts ON public.answers USING gin (text_fts); -DROP INDEX IF EXISTS answers_pkey; -CREATE UNIQUE INDEX answers_pkey ON public.answers USING btree (id); +drop index if exists answer_contract_id; + +create index answer_contract_id on public.answers using btree (contract_id); + +drop index if exists answer_text_fts; + +create index answer_text_fts on public.answers using gin (text_fts); + +drop index if exists answers_pkey; +create unique index answers_pkey on public.answers using btree (id); diff --git a/backend/supabase/audit_events.sql b/backend/supabase/audit_events.sql index 90edc6e50f..9aacb73687 100644 --- a/backend/supabase/audit_events.sql +++ b/backend/supabase/audit_events.sql @@ -1,24 +1,26 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS audit_events ( - comment_id text, - contract_id text, - created_time timestamp with time zone DEFAULT now() NOT NULL, - data jsonb, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - name text NOT NULL, - user_id text NOT NULL -); - - +create table if not exists + audit_events ( + comment_id text, + contract_id text, + created_time timestamp with time zone default now() not null, + data jsonb, + id bigint primary key generated always as identity not null, + name text not null, + user_id text not null + ); -- Row Level Security -ALTER TABLE audit_events ENABLE ROW LEVEL SECURITY; +alter table audit_events enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON audit_events; -CREATE POLICY "public read" ON audit_events FOR SELECT USING (true) ; +drop policy if exists "public read" on audit_events; + +create policy "public read" on audit_events for +select + using (true); -- Indexes -DROP INDEX IF EXISTS audit_events_pkey; -CREATE UNIQUE INDEX audit_events_pkey ON public.audit_events USING btree (id); +drop index if exists audit_events_pkey; +create unique index audit_events_pkey on public.audit_events using btree (id); diff --git a/backend/supabase/chart_annotations.sql b/backend/supabase/chart_annotations.sql index 82cd199464..d2352a2d53 100644 --- a/backend/supabase/chart_annotations.sql +++ b/backend/supabase/chart_annotations.sql @@ -1,36 +1,43 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS chart_annotations ( - answer_id text, - comment_id text, - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_avatar_url text NOT NULL, - creator_id text NOT NULL, - creator_name text NOT NULL, - creator_username text NOT NULL, - down_votes integer DEFAULT 0 NOT NULL, - event_time bigint NOT NULL, - external_url text, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - prob_change numeric CONSTRAINT chart_annotations_prob_change_check CHECK (((prob_change >= ('-1'::integer)::numeric) AND (prob_change <= (1)::numeric))), - text text, - thumbnail_url text, - up_votes integer DEFAULT 0 NOT NULL, - user_id text -); - - +create table if not exists + chart_annotations ( + answer_id text, + comment_id text, + contract_id text not null, + created_time timestamp with time zone default now() not null, + creator_avatar_url text not null, + creator_id text not null, + creator_name text not null, + creator_username text not null, + down_votes integer default 0 not null, + event_time bigint not null, + external_url text, + id bigint primary key generated always as identity not null, + prob_change numeric constraint chart_annotations_prob_change_check check ( + ( + (prob_change >= ('-1'::integer)::numeric) + and (prob_change <= (1)::numeric) + ) + ), + text text, + thumbnail_url text, + up_votes integer default 0 not null, + user_id text + ); -- Row Level Security -ALTER TABLE chart_annotations ENABLE ROW LEVEL SECURITY; +alter table chart_annotations enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON chart_annotations; -CREATE POLICY "public read" ON chart_annotations FOR ALL USING (true) ; +drop policy if exists "public read" on chart_annotations; + +create policy "public read" on chart_annotations for all using (true); -- Indexes -DROP INDEX IF EXISTS chart_annotations_pkey; -CREATE UNIQUE INDEX chart_annotations_pkey ON public.chart_annotations USING btree (id); -DROP INDEX IF EXISTS contract_annotations_event_time; -CREATE INDEX contract_annotations_event_time ON public.chart_annotations USING btree (contract_id, event_time); +drop index if exists chart_annotations_pkey; + +create unique index chart_annotations_pkey on public.chart_annotations using btree (id); + +drop index if exists contract_annotations_event_time; +create index contract_annotations_event_time on public.chart_annotations using btree (contract_id, event_time); diff --git a/backend/supabase/chat_messages.sql b/backend/supabase/chat_messages.sql new file mode 100644 index 0000000000..bc47ad5863 --- /dev/null +++ b/backend/supabase/chat_messages.sql @@ -0,0 +1,28 @@ +-- This file is autogenerated from regen-schema.ts +create table if not exists + chat_messages ( + channel_id text not null, + content jsonb not null, + created_time timestamp with time zone default now() not null, + id serial not null, + user_id text not null + ); + +-- Row Level Security +alter table chat_messages enable row level security; + +-- Policies +drop policy if exists "public read" on chat_messages; + +create policy "public read" on chat_messages for +select + using (true); + +-- Indexes +drop index if exists chat_messages_channel_id; + +create index chat_messages_channel_id on public.chat_messages using btree (channel_id, id desc); + +drop index if exists chat_messages_pkey; + +create unique index chat_messages_pkey on public.chat_messages using btree (id); diff --git a/backend/supabase/contract_bets.sql b/backend/supabase/contract_bets.sql index a513d4a55e..b1950601d3 100644 --- a/backend/supabase/contract_bets.sql +++ b/backend/supabase/contract_bets.sql @@ -1,35 +1,39 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS contract_bets ( - amount numeric, - answer_id text, - bet_id text PRIMARY KEY DEFAULT random_alphanumeric(12) NOT NULL, - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - data jsonb NOT NULL, - is_api boolean, - is_cancelled boolean, - is_filled boolean, - is_redemption boolean, - loan_amount numeric, - outcome text, - prob_after numeric, - prob_before numeric, - shares numeric, - updated_time timestamp with time zone DEFAULT now() NOT NULL, - user_id text NOT NULL -); - +create table if not exists + contract_bets ( + amount numeric, + answer_id text, + bet_id text primary key default random_alphanumeric (12) not null, + contract_id text not null, + created_time timestamp with time zone default now() not null, + data jsonb not null, + is_api boolean, + is_cancelled boolean, + is_filled boolean, + is_redemption boolean, + loan_amount numeric, + outcome text, + prob_after numeric, + prob_before numeric, + shares numeric, + updated_time timestamp with time zone default now() not null, + user_id text not null + ); -- Triggers -CREATE TRIGGER contract_bet_populate BEFORE INSERT OR UPDATE ON public.contract_bets FOR EACH ROW EXECUTE FUNCTION contract_bet_populate_cols(); -CREATE TRIGGER contract_bet_update AFTER UPDATE ON public.contract_bets FOR EACH ROW EXECUTE FUNCTION contract_bet_set_updated_time(); +create trigger contract_bet_populate before insert +or +update on public.contract_bets for each row +execute function contract_bet_populate_cols (); + +create trigger contract_bet_update +after +update on public.contract_bets for each row +execute function contract_bet_set_updated_time (); -- Functions -CREATE OR REPLACE FUNCTION public.contract_bet_populate_cols() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ +create +or replace function public.contract_bet_populate_cols () returns trigger language plpgsql as $function$ begin if new.bet_id is not null then new.data := new.data || jsonb_build_object('id', new.bet_id); @@ -53,37 +57,58 @@ begin end if; return new; end -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.contract_bet_set_updated_time() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ +create +or replace function public.contract_bet_set_updated_time () returns trigger language plpgsql as $function$ begin new.updated_time = now(); return new; end; -$function$ -; +$function$; -- Row Level Security -ALTER TABLE contract_bets ENABLE ROW LEVEL SECURITY; +alter table contract_bets enable row level security; + -- Indexes -DROP INDEX IF EXISTS contract_bets_contract_limit_orders; -CREATE INDEX contract_bets_contract_limit_orders ON public.contract_bets USING btree (contract_id, is_filled, is_cancelled, is_redemption, created_time DESC); -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_created_time; -CREATE INDEX contract_bets_created_time ON public.contract_bets USING btree (contract_id, created_time DESC); -DROP INDEX IF EXISTS contract_bets_created_time_only; -CREATE INDEX contract_bets_created_time_only ON public.contract_bets USING btree (created_time DESC); -DROP INDEX IF EXISTS contract_bets_historical_probs_non_redemption; -CREATE INDEX contract_bets_historical_probs_non_redemption ON public.contract_bets USING btree (contract_id, answer_id, created_time DESC) INCLUDE (prob_before, prob_after) WHERE (NOT is_redemption); -DROP INDEX IF EXISTS contract_bets_pkey; -CREATE UNIQUE INDEX contract_bets_pkey ON public.contract_bets USING btree (bet_id); -DROP INDEX IF EXISTS contract_bets_user_id_created_time; -CREATE INDEX contract_bets_user_id_created_time ON public.contract_bets USING btree (user_id, created_time DESC); -DROP INDEX IF EXISTS contract_bets_user_outstanding_limit_orders; -CREATE INDEX contract_bets_user_outstanding_limit_orders ON public.contract_bets USING btree (user_id, is_filled, is_cancelled); +drop index if exists contract_bets_contract_limit_orders; + +create index contract_bets_contract_limit_orders on public.contract_bets using btree ( + contract_id, + is_filled, + is_cancelled, + is_redemption, + created_time desc +); + +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_created_time; + +create index contract_bets_created_time on public.contract_bets using btree (contract_id, created_time desc); + +drop index if exists contract_bets_created_time_only; + +create index contract_bets_created_time_only on public.contract_bets using btree (created_time desc); + +drop index if exists contract_bets_historical_probs_non_redemption; + +create index concurrently contract_bets_historical_probs_non_redemption on public.contract_bets using btree + (contract_id, answer_id, created_time desc) + include (prob_before, prob_after) + where not is_redemption; + + +drop index if exists contract_bets_pkey; + +create unique index contract_bets_pkey on public.contract_bets using btree (bet_id); + +drop index if exists contract_bets_user_id_created_time; + +create index contract_bets_user_id_created_time on public.contract_bets using btree (user_id, created_time desc); + +drop index if exists contract_bets_user_outstanding_limit_orders; +create index contract_bets_user_outstanding_limit_orders on public.contract_bets using btree (user_id, is_filled, is_cancelled); diff --git a/backend/supabase/contract_comment_edits.sql b/backend/supabase/contract_comment_edits.sql index 0198e44efe..7e080dfd46 100644 --- a/backend/supabase/contract_comment_edits.sql +++ b/backend/supabase/contract_comment_edits.sql @@ -1,25 +1,29 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS contract_comment_edits ( - comment_id text NOT NULL, - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - data jsonb NOT NULL, - editor_id text NOT NULL, - id serial NOT NULL -); - - +create table if not exists + contract_comment_edits ( + comment_id text not null, + contract_id text not null, + created_time timestamp with time zone default now() not null, + data jsonb not null, + editor_id text not null, + id serial not null + ); -- Row Level Security -ALTER TABLE contract_comment_edits ENABLE ROW LEVEL SECURITY; +alter table contract_comment_edits enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON contract_comment_edits; -CREATE POLICY "public read" ON contract_comment_edits FOR SELECT USING (true) ; +drop policy if exists "public read" on contract_comment_edits; + +create policy "public read" on contract_comment_edits for +select + using (true); -- Indexes -DROP INDEX IF EXISTS comment_edits_comment_id_idx; -CREATE INDEX comment_edits_comment_id_idx ON public.contract_comment_edits USING btree (comment_id); -DROP INDEX IF EXISTS contract_comment_edits_pkey; -CREATE UNIQUE INDEX contract_comment_edits_pkey ON public.contract_comment_edits USING btree (id); +drop index if exists comment_edits_comment_id_idx; + +create index comment_edits_comment_id_idx on public.contract_comment_edits using btree (comment_id); + +drop index if exists contract_comment_edits_pkey; +create unique index contract_comment_edits_pkey on public.contract_comment_edits using btree (id); diff --git a/backend/supabase/contract_comments.sql b/backend/supabase/contract_comments.sql index a576202ef5..ca9ea12ef6 100644 --- a/backend/supabase/contract_comments.sql +++ b/backend/supabase/contract_comments.sql @@ -1,26 +1,26 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS contract_comments ( - comment_id text NOT NULL, - contract_id text NOT NULL, - created_time timestamp with time zone NOT NULL, - data jsonb NOT NULL, - dislikes integer DEFAULT 0, - likes integer DEFAULT 0 NOT NULL, - user_id text NOT NULL, - visibility text, - CONSTRAINT PRIMARY KEY (contract_id, comment_id) -); - +create table if not exists + contract_comments ( + comment_id text not null, + contract_id text not null, + created_time timestamp with time zone not null, + data jsonb not null, + dislikes integer default 0, + likes integer default 0 not null, + user_id text not null, + visibility text, + constraint primary key (contract_id, comment_id) + ); -- Triggers -CREATE TRIGGER comment_populate BEFORE INSERT OR UPDATE ON public.contract_comments FOR EACH ROW EXECUTE FUNCTION comment_populate_cols(); +create trigger comment_populate before insert +or +update on public.contract_comments for each row +execute function comment_populate_cols (); -- Functions -CREATE OR REPLACE FUNCTION public.comment_populate_cols() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ begin +create +or replace function public.comment_populate_cols () returns trigger language plpgsql as $function$ begin if new.data is not null then new.visibility := (new.data)->>'visibility'; new.user_id := (new.data)->>'userId'; new.created_time := case @@ -29,26 +29,43 @@ AS $function$ begin end; end if; return new; -end $function$ -; +end $function$; -- Row Level Security -ALTER TABLE contract_comments ENABLE ROW LEVEL SECURITY; +alter table contract_comments enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON contract_comments; -CREATE POLICY "public read" ON contract_comments FOR SELECT USING (true) ; +drop policy if exists "public read" on contract_comments; + +create policy "public read" on contract_comments for +select + using (true); -- Indexes -DROP INDEX IF EXISTS contract_comments_contract_id_created_time_idx; -CREATE INDEX contract_comments_contract_id_created_time_idx ON public.contract_comments USING btree (contract_id, created_time DESC); -DROP INDEX IF EXISTS contract_comments_created_time_idx; -CREATE INDEX contract_comments_created_time_idx ON public.contract_comments USING btree (created_time DESC); -DROP INDEX IF EXISTS contract_comments_id; -CREATE INDEX contract_comments_id ON public.contract_comments USING btree (comment_id); -DROP INDEX IF EXISTS contract_comments_pkey; -CREATE UNIQUE INDEX contract_comments_pkey ON public.contract_comments USING btree (contract_id, comment_id); -DROP INDEX IF EXISTS contract_replies; -CREATE INDEX contract_replies ON public.contract_comments USING btree (((data ->> 'replyToCommentId'::text)), contract_id, created_time DESC); -DROP INDEX IF EXISTS contracts_comments_user_id; -CREATE INDEX contracts_comments_user_id ON public.contract_comments USING btree (user_id, created_time); +drop index if exists contract_comments_contract_id_created_time_idx; + +create index contract_comments_contract_id_created_time_idx on public.contract_comments using btree (contract_id, created_time desc); + +drop index if exists contract_comments_created_time_idx; + +create index contract_comments_created_time_idx on public.contract_comments using btree (created_time desc); + +drop index if exists contract_comments_id; + +create index contract_comments_id on public.contract_comments using btree (comment_id); + +drop index if exists contract_comments_pkey; + +create unique index contract_comments_pkey on public.contract_comments using btree (contract_id, comment_id); + +drop index if exists contract_replies; + +create index contract_replies on public.contract_comments using btree ( + ((data ->> 'replyToCommentId'::text)), + contract_id, + created_time desc +); + +drop index if exists contracts_comments_user_id; +create index contracts_comments_user_id on public.contract_comments using btree (user_id, created_time); diff --git a/backend/supabase/contract_edits.sql b/backend/supabase/contract_edits.sql index 99affb6518..24e2102aed 100644 --- a/backend/supabase/contract_edits.sql +++ b/backend/supabase/contract_edits.sql @@ -1,26 +1,30 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS contract_edits ( - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - data jsonb NOT NULL, - editor_id text NOT NULL, - id serial NOT NULL, - idempotency_key text, - updated_keys text[] -); - - +create table if not exists + contract_edits ( + contract_id text not null, + created_time timestamp with time zone default now() not null, + data jsonb not null, + editor_id text not null, + id serial not null, + idempotency_key text, + updated_keys text[] + ); -- Row Level Security -ALTER TABLE contract_edits ENABLE ROW LEVEL SECURITY; +alter table contract_edits enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON contract_edits; -CREATE POLICY "public read" ON contract_edits FOR SELECT USING (true) ; +drop policy if exists "public read" on contract_edits; + +create policy "public read" on contract_edits for +select + using (true); -- Indexes -DROP INDEX IF EXISTS contract_edits_contract_id_idx; -CREATE INDEX contract_edits_contract_id_idx ON public.contract_edits USING btree (contract_id); -DROP INDEX IF EXISTS contract_edits_pkey; -CREATE UNIQUE INDEX contract_edits_pkey ON public.contract_edits USING btree (id); +drop index if exists contract_edits_contract_id_idx; + +create index contract_edits_contract_id_idx on public.contract_edits using btree (contract_id); + +drop index if exists contract_edits_pkey; +create unique index contract_edits_pkey on public.contract_edits using btree (id); diff --git a/backend/supabase/contract_embeddings.sql b/backend/supabase/contract_embeddings.sql index 37a6ecd6a3..2ac4dee271 100644 --- a/backend/supabase/contract_embeddings.sql +++ b/backend/supabase/contract_embeddings.sql @@ -1,25 +1,30 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + contract_embeddings ( + contract_id text primary key not null, + created_at timestamp with time zone default now() not null, + embedding vector (1536) not null + ); -CREATE TABLE IF NOT EXISTS contract_embeddings ( - contract_id text PRIMARY KEY NOT NULL, - created_at timestamp with time zone DEFAULT now() NOT NULL, - embedding vector(1536) NOT NULL -); +-- Row Level Security +alter table contract_embeddings enable row level security; +-- Policies +drop policy if exists "admin write access" on contract_embeddings; +create policy "admin write access" on contract_embeddings for all to service_role; --- Row Level Security -ALTER TABLE contract_embeddings ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "admin write access" ON contract_embeddings; -CREATE POLICY "admin write access" ON contract_embeddings FOR ALL TO service_role ; +drop policy if exists "public read" on contract_embeddings; -DROP POLICY IF EXISTS "public read" ON contract_embeddings; -CREATE POLICY "public read" ON contract_embeddings FOR SELECT USING (true) ; +create policy "public read" on contract_embeddings for +select + using (true); -- Indexes -DROP INDEX IF EXISTS contract_embeddings_embedding_aug_2024; -CREATE INDEX contract_embeddings_embedding_aug_2024 ON public.contract_embeddings USING hnsw (embedding vector_cosine_ops); -DROP INDEX IF EXISTS contract_embeddings_pkey; -CREATE UNIQUE INDEX contract_embeddings_pkey ON public.contract_embeddings USING btree (contract_id); +drop index if exists contract_embeddings_embedding_apr_2024; + +create index contract_embeddings_embedding_apr_2024 on public.contract_embeddings using hnsw (embedding vector_cosine_ops); + +drop index if exists contract_embeddings_pkey; +create unique index contract_embeddings_pkey on public.contract_embeddings using btree (contract_id); diff --git a/backend/supabase/contract_follows.sql b/backend/supabase/contract_follows.sql index 33d2b3837b..054221f390 100644 --- a/backend/supabase/contract_follows.sql +++ b/backend/supabase/contract_follows.sql @@ -1,23 +1,27 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS contract_follows ( - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - follow_id text NOT NULL, - CONSTRAINT PRIMARY KEY (contract_id, follow_id) -); - - +create table if not exists + contract_follows ( + contract_id text not null, + created_time timestamp with time zone default now() not null, + follow_id text not null, + constraint primary key (contract_id, follow_id) + ); -- Row Level Security -ALTER TABLE contract_follows ENABLE ROW LEVEL SECURITY; +alter table contract_follows enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON contract_follows; -CREATE POLICY "public read" ON contract_follows FOR SELECT USING (true) ; +drop policy if exists "public read" on contract_follows; + +create policy "public read" on contract_follows for +select + using (true); -- Indexes -DROP INDEX IF EXISTS contract_follows_idx; -CREATE INDEX contract_follows_idx ON public.contract_follows USING btree (follow_id); -DROP INDEX IF EXISTS contract_follows_pkey; -CREATE UNIQUE INDEX contract_follows_pkey ON public.contract_follows USING btree (contract_id, follow_id); +drop index if exists contract_follows_idx; + +create index contract_follows_idx on public.contract_follows using btree (follow_id); + +drop index if exists contract_follows_pkey; +create unique index contract_follows_pkey on public.contract_follows using btree (contract_id, follow_id); diff --git a/backend/supabase/contract_liquidity.sql b/backend/supabase/contract_liquidity.sql index f8b24aa02f..6f680b1cfc 100644 --- a/backend/supabase/contract_liquidity.sql +++ b/backend/supabase/contract_liquidity.sql @@ -1,21 +1,23 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS contract_liquidity ( - contract_id text NOT NULL, - data jsonb NOT NULL, - liquidity_id text NOT NULL, - CONSTRAINT PRIMARY KEY (contract_id, liquidity_id) -); - - +create table if not exists + contract_liquidity ( + contract_id text not null, + data jsonb not null, + liquidity_id text not null, + constraint primary key (contract_id, liquidity_id) + ); -- Row Level Security -ALTER TABLE contract_liquidity ENABLE ROW LEVEL SECURITY; +alter table contract_liquidity enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON contract_liquidity; -CREATE POLICY "public read" ON contract_liquidity FOR SELECT USING (true) ; +drop policy if exists "public read" on contract_liquidity; + +create policy "public read" on contract_liquidity for +select + using (true); -- Indexes -DROP INDEX IF EXISTS contract_liquidity_pkey; -CREATE UNIQUE INDEX contract_liquidity_pkey ON public.contract_liquidity USING btree (contract_id, liquidity_id); +drop index if exists contract_liquidity_pkey; +create unique index contract_liquidity_pkey on public.contract_liquidity using btree (contract_id, liquidity_id); diff --git a/backend/supabase/contracts.sql b/backend/supabase/contracts.sql index 7d27edb531..0adb69efc1 100644 --- a/backend/supabase/contracts.sql +++ b/backend/supabase/contracts.sql @@ -1,49 +1,71 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS contracts ( - close_time timestamp with time zone, - conversion_score numeric DEFAULT 0 NOT NULL, - created_time timestamp with time zone, - creator_id text, - daily_score numeric DEFAULT 0 NOT NULL, - data jsonb NOT NULL, - deleted boolean DEFAULT false, - description_fts tsvector GENERATED ALWAYS AS (to_tsvector('english_extended'::regconfig, add_creator_name_to_description(data))) STORED, - freshness_score numeric DEFAULT 0 NOT NULL, - group_slugs text[], - id text PRIMARY KEY NOT NULL, - importance_score numeric DEFAULT 0 NOT NULL, - is_spice_payout boolean DEFAULT false, - last_bet_time timestamp with time zone, - last_comment_time timestamp with time zone, - last_updated_time timestamp with time zone, - mechanism text, - outcome_type text, - popularity_score numeric DEFAULT 0 NOT NULL, - question text, - question_fts tsvector GENERATED ALWAYS AS (to_tsvector('english_extended'::regconfig, question)) STORED, - question_nostop_fts tsvector GENERATED ALWAYS AS (to_tsvector('english_nostop_with_prefix'::regconfig, question)) STORED, - resolution text, - resolution_probability numeric, - resolution_time timestamp with time zone, - slug text, - tier text, - token text DEFAULT 'MANA'::character varying NOT NULL CONSTRAINT contracts_token_check CHECK ((token = ANY (ARRAY[('MANA'::character varying)::text, ('CASH'::character varying)::text]))), - unique_bettor_count bigint DEFAULT 0 NOT NULL, - view_count bigint DEFAULT 0 NOT NULL, - visibility text -); - +create table if not exists + contracts ( + close_time timestamp with time zone, + conversion_score numeric default 0 not null, + created_time timestamp with time zone, + creator_id text, + daily_score numeric default 0 not null, + data jsonb not null, + deleted boolean default false, + description_fts tsvector generated always as ( + to_tsvector( + 'english_extended'::regconfig, + add_creator_name_to_description (data) + ) + ) stored, + freshness_score numeric default 0 not null, + group_slugs text[], + id text primary key not null, + importance_score numeric default 0 not null, + is_spice_payout boolean default false, + last_bet_time timestamp with time zone, + last_comment_time timestamp with time zone, + last_updated_time timestamp with time zone, + mechanism text, + outcome_type text, + popularity_score numeric default 0 not null, + question text, + question_fts tsvector generated always as ( + to_tsvector('english_extended'::regconfig, question) + ) stored, + question_nostop_fts tsvector generated always as ( + to_tsvector('english_nostop_with_prefix'::regconfig, question) + ) stored, + resolution text, + resolution_probability numeric, + resolution_time timestamp with time zone, + slug text, + tier text, + token text default 'MANA'::character varying not null constraint contracts_token_check check ( + ( + token = any ( + array[ + ('MANA'::character varying)::text, + ('CASH'::character varying)::text + ] + ) + ) + ), + unique_bettor_count bigint default 0 not null, + view_count bigint default 0 not null, + visibility text + ); -- Triggers -CREATE TRIGGER contract_populate BEFORE INSERT OR UPDATE ON public.contracts FOR EACH ROW EXECUTE FUNCTION contract_populate_cols(); -CREATE TRIGGER sync_sibling_contract_trigger AFTER UPDATE ON public.contracts FOR EACH ROW EXECUTE FUNCTION sync_sibling_contract(); +create trigger contract_populate before insert +or +update on public.contracts for each row +execute function contract_populate_cols (); + +create trigger sync_sibling_contract_trigger +after +update on public.contracts for each row +execute function sync_sibling_contract (); -- Functions -CREATE OR REPLACE FUNCTION public.contract_populate_cols() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ +create +or replace function public.contract_populate_cols () returns trigger language plpgsql as $function$ begin if new.data is not null then new.slug := (new.data) ->> 'slug'; @@ -90,13 +112,10 @@ begin end if; return new; end -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.sync_sibling_contract() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ +create +or replace function public.sync_sibling_contract () returns trigger language plpgsql as $function$ begin if new.token = 'MANA' and (new.data->>'siblingContractId') is not null and ( @@ -114,58 +133,111 @@ begin end if; return new; end; -$function$ -; +$function$; -- Row Level Security -ALTER TABLE contracts ENABLE ROW LEVEL SECURITY; +alter table contracts enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON contracts; -CREATE POLICY "public read" ON contracts FOR SELECT USING (true) ; +drop policy if exists "public read" on contracts; + +create policy "public read" on contracts for +select + using (true); -- Indexes -DROP INDEX IF EXISTS contracts_close_time; -CREATE INDEX contracts_close_time ON public.contracts USING btree (close_time DESC); -DROP INDEX IF EXISTS contracts_created_time; -CREATE INDEX contracts_created_time ON public.contracts USING btree (created_time DESC); -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); -DROP INDEX IF EXISTS contracts_freshness_score; -CREATE INDEX contracts_freshness_score ON public.contracts USING btree (freshness_score DESC); -DROP INDEX IF EXISTS contracts_group_slugs_importance; -CREATE INDEX contracts_group_slugs_importance ON public.contracts USING gin (group_slugs, importance_score); -DROP INDEX IF EXISTS contracts_importance_score; -CREATE INDEX contracts_importance_score ON public.contracts USING btree (importance_score DESC); -DROP INDEX IF EXISTS contracts_last_bet_time; -CREATE INDEX contracts_last_bet_time ON public.contracts USING btree (last_bet_time DESC NULLS LAST); -DROP INDEX IF EXISTS contracts_last_comment_time; -CREATE INDEX contracts_last_comment_time ON public.contracts USING btree (last_comment_time DESC NULLS LAST); -DROP INDEX IF EXISTS contracts_last_updated_time; -CREATE INDEX contracts_last_updated_time ON public.contracts USING btree (last_updated_time DESC NULLS LAST); -DROP INDEX IF EXISTS contracts_outcome_type_binary; -CREATE INDEX contracts_outcome_type_binary ON public.contracts USING btree (outcome_type) WHERE (outcome_type = 'BINARY'::text); -DROP INDEX IF EXISTS contracts_outcome_type_not_binary; -CREATE INDEX contracts_outcome_type_not_binary ON public.contracts USING btree (outcome_type) WHERE (outcome_type <> 'BINARY'::text); -DROP INDEX IF EXISTS contracts_pkey; -CREATE UNIQUE INDEX contracts_pkey ON public.contracts USING btree (id); -DROP INDEX IF EXISTS contracts_resolution_time; -CREATE INDEX contracts_resolution_time ON public.contracts USING btree (resolution_time DESC); -DROP INDEX IF EXISTS contracts_slug; -CREATE INDEX contracts_slug ON public.contracts USING btree (slug); -DROP INDEX IF EXISTS contracts_visibility_public; -CREATE INDEX contracts_visibility_public ON public.contracts USING btree (id) WHERE (visibility = 'public'::text); -DROP INDEX IF EXISTS contracts_volume_24_hours; -CREATE INDEX contracts_volume_24_hours ON public.contracts USING btree ((((data ->> 'volume24Hours'::text))::numeric) DESC); -DROP INDEX IF EXISTS description_fts; -CREATE INDEX description_fts ON public.contracts USING gin (description_fts); -DROP INDEX IF EXISTS market_token_tier_idx; -CREATE INDEX market_token_tier_idx ON public.contracts USING btree (token, tier); -DROP INDEX IF EXISTS question_fts; -CREATE INDEX question_fts ON public.contracts USING gin (question_fts); -DROP INDEX IF EXISTS question_nostop_fts; -CREATE INDEX question_nostop_fts ON public.contracts USING gin (question_nostop_fts); +drop index if exists contracts_close_time; + +create index contracts_close_time on public.contracts using btree (close_time desc); + +drop index if exists contracts_created_time; + +create index contracts_created_time on public.contracts using btree (created_time desc); + +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); + +drop index if exists contracts_freshness_score; + +create index contracts_freshness_score on public.contracts using btree (freshness_score desc); + +drop index if exists contracts_group_slugs_importance; + +create index contracts_group_slugs_importance on public.contracts using gin (group_slugs, importance_score); + +drop index if exists contracts_importance_score; + +create index contracts_importance_score on public.contracts using btree (importance_score desc); + +drop index if exists contracts_last_bet_time; + +create index contracts_last_bet_time on public.contracts using btree (last_bet_time desc nulls last); + +drop index if exists contracts_last_comment_time; + +create index contracts_last_comment_time on public.contracts using btree (last_comment_time desc nulls last); + +drop index if exists contracts_last_updated_time; + +create index contracts_last_updated_time on public.contracts using btree (last_updated_time desc nulls last); + +drop index if exists contracts_outcome_type_binary; + +create index contracts_outcome_type_binary on public.contracts using btree (outcome_type) +where + (outcome_type = 'BINARY'::text); + +drop index if exists contracts_outcome_type_not_binary; + +create index contracts_outcome_type_not_binary on public.contracts using btree (outcome_type) +where + (outcome_type <> 'BINARY'::text); + +drop index if exists contracts_pkey; + +create unique index contracts_pkey on public.contracts using btree (id); + +drop index if exists contracts_resolution_time; + +create index contracts_resolution_time on public.contracts using btree (resolution_time desc); + +drop index if exists contracts_slug; + +create index contracts_slug on public.contracts using btree (slug); + +drop index if exists contracts_visibility_public; + +create index contracts_visibility_public on public.contracts using btree (id) +where + (visibility = 'public'::text); + +drop index if exists contracts_volume_24_hours; + +create index contracts_volume_24_hours on public.contracts using btree ( + (((data ->> 'volume24Hours'::text))::numeric) desc +); + +drop index if exists description_fts; + +create index description_fts on public.contracts using gin (description_fts); + +drop index if exists market_token_tier_idx; + +create index market_token_tier_idx on public.contracts using btree (token, tier); + +drop index if exists question_fts; + +create index question_fts on public.contracts using gin (question_fts); + +drop index if exists question_nostop_fts; +create index question_nostop_fts on public.contracts using gin (question_nostop_fts); diff --git a/backend/supabase/creator_portfolio_history.sql b/backend/supabase/creator_portfolio_history.sql index 4f0077bd6e..3a730d99b7 100644 --- a/backend/supabase/creator_portfolio_history.sql +++ b/backend/supabase/creator_portfolio_history.sql @@ -1,26 +1,30 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS creator_portfolio_history ( - fees_earned numeric NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - ts timestamp without time zone DEFAULT now() NOT NULL, - unique_bettors integer NOT NULL, - user_id text NOT NULL, - views integer NOT NULL, - volume numeric NOT NULL -); - - +create table if not exists + creator_portfolio_history ( + fees_earned numeric not null, + id bigint primary key generated always as identity not null, + ts timestamp without time zone default now() not null, + unique_bettors integer not null, + user_id text not null, + views integer not null, + volume numeric not null + ); -- Row Level Security -ALTER TABLE creator_portfolio_history ENABLE ROW LEVEL SECURITY; +alter table creator_portfolio_history enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON creator_portfolio_history; -CREATE POLICY "public read" ON creator_portfolio_history FOR SELECT USING (true) ; +drop policy if exists "public read" on creator_portfolio_history; + +create policy "public read" on creator_portfolio_history for +select + using (true); -- Indexes -DROP INDEX IF EXISTS creator_portfolio_history_pkey; -CREATE UNIQUE INDEX creator_portfolio_history_pkey ON public.creator_portfolio_history USING btree (id); -DROP INDEX IF EXISTS creator_portfolio_history_user_ts; -CREATE INDEX creator_portfolio_history_user_ts ON public.creator_portfolio_history USING btree (user_id, ts DESC); +drop index if exists creator_portfolio_history_pkey; + +create unique index creator_portfolio_history_pkey on public.creator_portfolio_history using btree (id); + +drop index if exists creator_portfolio_history_user_ts; +create index creator_portfolio_history_user_ts on public.creator_portfolio_history using btree (user_id, ts desc); diff --git a/backend/supabase/daily_stats.sql b/backend/supabase/daily_stats.sql index 358e8fdd4a..2205b87868 100644 --- a/backend/supabase/daily_stats.sql +++ b/backend/supabase/daily_stats.sql @@ -1,42 +1,44 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS daily_stats ( - activation numeric, - active_d1_to_d3 numeric, - avg_user_actions numeric, - bet_amount numeric, - bet_count numeric, - cash_bet_amount numeric, - comment_count numeric, - contract_count numeric, - d1 numeric, - d1_bet_3_day_average numeric, - d1_bet_average numeric, - dau numeric, - engaged_users numeric, - feed_conversion numeric, - m1 numeric, - mau numeric, - nd1 numeric, - nw1 numeric, - sales numeric, - signups numeric, - signups_real numeric, - start_date date PRIMARY KEY NOT NULL, - topic_daus jsonb, - w1 numeric, - wau numeric -); - - +create table if not exists + daily_stats ( + activation numeric, + active_d1_to_d3 numeric, + avg_user_actions numeric, + bet_amount numeric, + bet_count numeric, + cash_bet_amount numeric, + comment_count numeric, + contract_count numeric, + d1 numeric, + d1_bet_3_day_average numeric, + d1_bet_average numeric, + dau numeric, + engaged_users numeric, + feed_conversion numeric, + m1 numeric, + mau numeric, + nd1 numeric, + nw1 numeric, + sales numeric, + signups numeric, + signups_real numeric, + start_date date primary key not null, + w1 numeric, + wau numeric, + topic_daus jsonb + ); -- Row Level Security -ALTER TABLE daily_stats ENABLE ROW LEVEL SECURITY; +alter table daily_stats enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON daily_stats; -CREATE POLICY "public read" ON daily_stats FOR SELECT USING (true) ; +drop policy if exists "public read" on daily_stats; + +create policy "public read" on daily_stats for +select + using (true); -- Indexes -DROP INDEX IF EXISTS daily_stats_pkey; -CREATE UNIQUE INDEX daily_stats_pkey ON public.daily_stats USING btree (start_date); +drop index if exists daily_stats_pkey; +create unique index daily_stats_pkey on public.daily_stats using btree (start_date); diff --git a/backend/supabase/dashboard_follows.sql b/backend/supabase/dashboard_follows.sql index ab8960eace..ccc281f1e9 100644 --- a/backend/supabase/dashboard_follows.sql +++ b/backend/supabase/dashboard_follows.sql @@ -1,17 +1,17 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + dashboard_follows ( + created_time timestamp with time zone default now(), + dashboard_id text not null, + follower_id text not null, + constraint primary key (dashboard_id, follower_id) + ); -CREATE TABLE IF NOT EXISTS dashboard_follows ( - created_time timestamp with time zone DEFAULT now(), - dashboard_id text NOT NULL, - follower_id text NOT NULL, - CONSTRAINT PRIMARY KEY (dashboard_id, follower_id) -); - +-- Indexes +drop index if exists dashboard_follows_pkey; +create unique index dashboard_follows_pkey on public.dashboard_follows using btree (dashboard_id, follower_id); --- Indexes -DROP INDEX IF EXISTS dashboard_follows_pkey; -CREATE UNIQUE INDEX dashboard_follows_pkey ON public.dashboard_follows USING btree (dashboard_id, follower_id); -DROP INDEX IF EXISTS idx_dashboard_follows_follower_dashboard; -CREATE INDEX idx_dashboard_follows_follower_dashboard ON public.dashboard_follows USING btree (follower_id, dashboard_id); +drop index if exists idx_dashboard_follows_follower_dashboard; +create index idx_dashboard_follows_follower_dashboard on public.dashboard_follows using btree (follower_id, dashboard_id); diff --git a/backend/supabase/dashboard_groups.sql b/backend/supabase/dashboard_groups.sql index 9d8d9edc43..e416a5ec2c 100644 --- a/backend/supabase/dashboard_groups.sql +++ b/backend/supabase/dashboard_groups.sql @@ -1,23 +1,29 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS dashboard_groups ( - dashboard_id text NOT NULL, - group_id text NOT NULL, - CONSTRAINT PRIMARY KEY (dashboard_id, group_id) -); +create table if not exists + dashboard_groups ( + dashboard_id text not null, + group_id text not null, + constraint primary key (dashboard_id, group_id) + ); -- Foreign Keys -ALTER TABLE dashboard_groups ADD CONSTRAINT dashboard_groups_dashboard_id_fkey FOREIGN KEY (dashboard_id) REFERENCES dashboards(id); -ALTER TABLE dashboard_groups ADD CONSTRAINT public_dashboard_groups_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON UPDATE CASCADE ON DELETE CASCADE; +alter table dashboard_groups +add constraint dashboard_groups_dashboard_id_fkey foreign key (dashboard_id) references dashboards (id); +alter table dashboard_groups +add constraint public_dashboard_groups_group_id_fkey foreign key (group_id) references groups (id) on update cascade on delete cascade; -- Row Level Security -ALTER TABLE dashboard_groups ENABLE ROW LEVEL SECURITY; +alter table dashboard_groups enable row level security; + -- Policies -DROP POLICY IF EXISTS "Enable read access for admin" ON dashboard_groups; -CREATE POLICY "Enable read access for admin" ON dashboard_groups FOR SELECT TO service_role USING (true) ; +drop policy if exists "Enable read access for admin" on dashboard_groups; + +create policy "Enable read access for admin" on dashboard_groups for +select + to service_role using (true); -- Indexes -DROP INDEX IF EXISTS dashboard_groups_pkey; -CREATE UNIQUE INDEX dashboard_groups_pkey ON public.dashboard_groups USING btree (dashboard_id, group_id); +drop index if exists dashboard_groups_pkey; +create unique index dashboard_groups_pkey on public.dashboard_groups using btree (dashboard_id, group_id); diff --git a/backend/supabase/dashboards.sql b/backend/supabase/dashboards.sql index 8707e3dcb1..c95c0ba8e7 100644 --- a/backend/supabase/dashboards.sql +++ b/backend/supabase/dashboards.sql @@ -1,35 +1,41 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS dashboards ( - ai_importance_score numeric DEFAULT 0 NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_avatar_url text NOT NULL, - creator_id text NOT NULL, - creator_name text NOT NULL, - creator_username text NOT NULL, - id text PRIMARY KEY DEFAULT random_alphanumeric(12) NOT NULL, - importance_score numeric DEFAULT 0 NOT NULL, - items jsonb DEFAULT '[]'::jsonb, - politics_importance_score numeric DEFAULT 0 NOT NULL, - slug text NOT NULL, - title text NOT NULL, - title_fts tsvector GENERATED ALWAYS AS (to_tsvector('english'::regconfig, title)) STORED, - visibility text DEFAULT 'public'::text -); +create table if not exists + dashboards ( + ai_importance_score numeric default 0 not null, + created_time timestamp with time zone default now() not null, + creator_avatar_url text not null, + creator_id text not null, + creator_name text not null, + creator_username text not null, + id text primary key default random_alphanumeric (12) not null, + importance_score numeric default 0 not null, + items jsonb default '[]'::jsonb, + politics_importance_score numeric default 0 not null, + slug text not null, + title text not null, + title_fts tsvector generated always as (to_tsvector('english'::regconfig, title)) stored, + visibility text default 'public'::text + ); -- Foreign Keys -ALTER TABLE dashboards ADD CONSTRAINT dashboards_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES users(id); - +alter table dashboards +add constraint dashboards_creator_id_fkey foreign key (creator_id) references users (id); -- Row Level Security -ALTER TABLE dashboards ENABLE ROW LEVEL SECURITY; +alter table dashboards enable row level security; + -- Policies -DROP POLICY IF EXISTS "Enable read access for admin" ON dashboards; -CREATE POLICY "Enable read access for admin" ON dashboards FOR SELECT TO service_role USING (true) ; +drop policy if exists "Enable read access for admin" on dashboards; + +create policy "Enable read access for admin" on dashboards for +select + to service_role using (true); -- Indexes -DROP INDEX IF EXISTS dashboards_pkey; -CREATE UNIQUE INDEX dashboards_pkey ON public.dashboards USING btree (id); -DROP INDEX IF EXISTS idx_dashboard_slug; -CREATE UNIQUE INDEX idx_dashboard_slug ON public.dashboards USING btree (slug); +drop index if exists dashboards_pkey; + +create unique index dashboards_pkey on public.dashboards using btree (id); + +drop index if exists idx_dashboard_slug; +create unique index idx_dashboard_slug on public.dashboards using btree (slug); diff --git a/backend/supabase/delete_after_reading.sql b/backend/supabase/delete_after_reading.sql index a1d220b899..564a4ac4cb 100644 --- a/backend/supabase/delete_after_reading.sql +++ b/backend/supabase/delete_after_reading.sql @@ -1,19 +1,20 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS delete_after_reading ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - data jsonb, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - user_id text NOT NULL -); +create table if not exists + delete_after_reading ( + created_time timestamp with time zone default now() not null, + data jsonb, + id bigint primary key generated always as identity not null, + user_id text not null + ); -- Foreign Keys -ALTER TABLE delete_after_reading ADD CONSTRAINT delete_after_reading_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); - +alter table delete_after_reading +add constraint delete_after_reading_user_id_fkey foreign key (user_id) references users (id); -- Row Level Security -ALTER TABLE delete_after_reading ENABLE ROW LEVEL SECURITY; +alter table delete_after_reading enable row level security; + -- Indexes -DROP INDEX IF EXISTS delete_after_reading_pkey; -CREATE UNIQUE INDEX delete_after_reading_pkey ON public.delete_after_reading USING btree (id); +drop index if exists delete_after_reading_pkey; +create unique index delete_after_reading_pkey on public.delete_after_reading using btree (id); diff --git a/backend/supabase/discord_messages_markets.sql b/backend/supabase/discord_messages_markets.sql index fb0f2a811e..8c91f1cee7 100644 --- a/backend/supabase/discord_messages_markets.sql +++ b/backend/supabase/discord_messages_markets.sql @@ -1,19 +1,18 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS discord_messages_markets ( - channel_id text NOT NULL, - last_updated_thread_time bigint, - market_id text NOT NULL, - market_slug text NOT NULL, - message_id text PRIMARY KEY NOT NULL, - thread_id text -); - - +create table if not exists + discord_messages_markets ( + channel_id text not null, + last_updated_thread_time bigint, + market_id text not null, + market_slug text not null, + message_id text primary key not null, + thread_id text + ); -- Row Level Security -ALTER TABLE discord_messages_markets ENABLE ROW LEVEL SECURITY; +alter table discord_messages_markets enable row level security; + -- Indexes -DROP INDEX IF EXISTS discord_messages_markets_pkey; -CREATE UNIQUE INDEX discord_messages_markets_pkey ON public.discord_messages_markets USING btree (message_id); +drop index if exists discord_messages_markets_pkey; +create unique index discord_messages_markets_pkey on public.discord_messages_markets using btree (message_id); diff --git a/backend/supabase/discord_users.sql b/backend/supabase/discord_users.sql index d9203eef7a..46f17b5aa3 100644 --- a/backend/supabase/discord_users.sql +++ b/backend/supabase/discord_users.sql @@ -1,16 +1,15 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS discord_users ( - api_key text NOT NULL, - discord_user_id text PRIMARY KEY NOT NULL, - user_id text NOT NULL -); - - +create table if not exists + discord_users ( + api_key text not null, + discord_user_id text primary key not null, + user_id text not null + ); -- Row Level Security -ALTER TABLE discord_users ENABLE ROW LEVEL SECURITY; +alter table discord_users enable row level security; + -- Indexes -DROP INDEX IF EXISTS discord_users_pkey; -CREATE UNIQUE INDEX discord_users_pkey ON public.discord_users USING btree (discord_user_id); +drop index if exists discord_users_pkey; +create unique index discord_users_pkey on public.discord_users using btree (discord_user_id); diff --git a/backend/supabase/functions.sql b/backend/supabase/functions.sql index 628bb39ceb..a4e1a214c2 100644 --- a/backend/supabase/functions.sql +++ b/backend/supabase/functions.sql @@ -1,23 +1,20 @@ -- This file is autogenerated from regen-schema.ts - -CREATE OR REPLACE FUNCTION public.add_creator_name_to_description(data jsonb) - RETURNS text - LANGUAGE sql - IMMUTABLE -AS $function$ +create +or replace function public.add_creator_name_to_description (data jsonb) returns text language sql immutable as $function$ select * from CONCAT_WS( ' '::text, data->>'creatorName', public.extract_text_from_rich_text_json(data->'description') ) -$function$ -; - -CREATE OR REPLACE FUNCTION public.calculate_earth_distance_km(lat1 double precision, lon1 double precision, lat2 double precision, lon2 double precision) - RETURNS double precision - LANGUAGE plpgsql - IMMUTABLE -AS $function$ +$function$; + +create +or replace function public.calculate_earth_distance_km ( + lat1 double precision, + lon1 double precision, + lat2 double precision, + lon2 double precision +) returns double precision language plpgsql immutable as $function$ DECLARE radius_earth_km CONSTANT FLOAT := 6371; delta_lat FLOAT; @@ -42,26 +39,27 @@ BEGIN -- Calculate distance RETURN radius_earth_km * c; END; -$function$ -; - -CREATE OR REPLACE FUNCTION public.can_access_private_messages(channel_id bigint, user_id text) - RETURNS boolean - LANGUAGE sql - PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.can_access_private_messages (channel_id bigint, user_id text) returns boolean language sql parallel SAFE as $function$ select exists ( select 1 from private_user_message_channel_members where private_user_message_channel_members.channel_id = $1 and private_user_message_channel_members.user_id = $2 ) -$function$ -; - -CREATE OR REPLACE FUNCTION public.close_contract_embeddings(input_contract_id text, similarity_threshold double precision, match_count integer) - RETURNS TABLE(contract_id text, similarity double precision, data jsonb) - LANGUAGE sql -AS $function$ WITH embedding AS ( +$function$; + +create +or replace function public.close_contract_embeddings ( + input_contract_id text, + similarity_threshold double precision, + match_count integer +) returns table ( + contract_id text, + similarity double precision, + data jsonb +) language sql as $function$ WITH embedding AS ( SELECT embedding FROM contract_embeddings WHERE contract_id = input_contract_id @@ -83,24 +81,18 @@ AS $function$ WITH embedding AS ( and contracts.visibility = 'public' order by similarity * similarity * importance_score desc limit match_count; -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.count_recent_comments(contract_id text) - RETURNS integer - LANGUAGE sql -AS $function$ +create +or replace function public.count_recent_comments (contract_id text) returns integer language sql as $function$ SELECT COUNT(*) FROM contract_comments WHERE contract_id = $1 AND created_time >= NOW() - INTERVAL '1 DAY' -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.count_recent_comments_by_contract() - RETURNS TABLE(contract_id text, comment_count integer) - LANGUAGE sql -AS $function$ +create +or replace function public.count_recent_comments_by_contract () returns table (contract_id text, comment_count integer) language sql as $function$ SELECT contract_id, COUNT(*) AS comment_count @@ -112,46 +104,36 @@ AS $function$ contract_id ORDER BY comment_count DESC; -$function$ -; - -CREATE OR REPLACE FUNCTION public.creator_leaderboard(limit_n integer) - RETURNS TABLE(user_id text, total_traders integer, name text, username text, avatar_url text) - LANGUAGE sql - STABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.creator_leaderboard (limit_n integer) returns table ( + user_id text, + total_traders integer, + name text, + username text, + avatar_url text +) language sql stable parallel SAFE as $function$ select id as user_id, (data->'creatorTraders'->'allTime')::int as total_traders, name, username, data->>'avatarUrl' as avatar_url from users order by total_traders desc limit limit_n -$function$ -; - -CREATE OR REPLACE FUNCTION public.creator_rank(uid text) - RETURNS integer - LANGUAGE sql - STABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.creator_rank (uid text) returns integer language sql stable parallel SAFE as $function$ select count(*) + 1 from users where data->'creatorTraders'->'allTime' > (select data->'creatorTraders'->'allTime' from users where id = uid) -$function$ -; - -CREATE OR REPLACE FUNCTION public.date_to_midnight_pt(d date) - RETURNS timestamp without time zone - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.date_to_midnight_pt (d date) returns timestamp without time zone language sql immutable parallel SAFE as $function$ select timezone('America/Los_Angeles', d::timestamp)::timestamptz -$function$ -; - -CREATE OR REPLACE FUNCTION public.extract_text_from_rich_text_json(description jsonb) - RETURNS text - LANGUAGE sql - IMMUTABLE -AS $function$ +$function$; + +create +or replace function public.extract_text_from_rich_text_json (description jsonb) returns text language sql immutable as $function$ WITH RECURSIVE content_elements AS ( SELECT jsonb_array_elements(description->'content') AS element WHERE jsonb_typeof(description) = 'object' @@ -181,22 +163,15 @@ SELECT END FROM all_text_elements; -$function$ -; - -CREATE OR REPLACE FUNCTION public.firebase_uid() - RETURNS text - LANGUAGE sql - STABLE PARALLEL SAFE LEAKPROOF -AS $function$ +$function$; + +create +or replace function public.firebase_uid () returns text language sql stable parallel SAFE as $function$ select nullif(current_setting('request.jwt.claims', true)::json->>'sub', '')::text; -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.get_average_rating(user_id text) - RETURNS numeric - LANGUAGE plpgsql -AS $function$ +create +or replace function public.get_average_rating (user_id text) returns numeric language plpgsql as $function$ DECLARE result numeric; BEGIN @@ -205,13 +180,10 @@ BEGIN WHERE vendor_id = user_id; RETURN result; END; -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.get_compatibility_questions_with_answer_count() - RETURNS SETOF love_question_with_count_type - LANGUAGE plpgsql -AS $function$ +create +or replace function public.get_compatibility_questions_with_answer_count () returns setof love_question_with_count_type language plpgsql as $function$ BEGIN RETURN QUERY SELECT @@ -227,28 +199,20 @@ BEGIN ORDER BY answer_count DESC; END; -$function$ -; - -CREATE OR REPLACE FUNCTION public.get_contract_metrics_with_contracts(uid text, count integer) - RETURNS TABLE(contract_id text, metrics jsonb, contract jsonb) - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.get_contract_metrics_with_contracts (uid text, count integer) returns table (contract_id text, metrics jsonb, contract jsonb) language sql immutable parallel SAFE as $function$ select ucm.contract_id, ucm.data as metrics, c.data as contract from user_contract_metrics as ucm join contracts as c on c.id = ucm.contract_id where ucm.user_id = uid order by ((ucm.data)->'lastBetTime')::bigint desc limit count -$function$ -; - -CREATE OR REPLACE FUNCTION public.get_contract_metrics_with_contracts(uid text, count integer, start integer) - RETURNS TABLE(contract_id text, metrics jsonb, contract jsonb) - LANGUAGE sql - STABLE -AS $function$select ucm.contract_id, +$function$; + +create +or replace function public.get_contract_metrics_with_contracts (uid text, count integer, start integer) returns table (contract_id text, metrics jsonb, contract jsonb) language sql stable as $function$select ucm.contract_id, ucm.data as metrics, c.data as contract from user_contract_metrics as ucm @@ -257,37 +221,29 @@ where ucm.user_id = uid and ucm.data->'lastBetTime' is not null and ucm.answer_id is null order by ((ucm.data)->'lastBetTime')::bigint desc offset start - limit count$function$ -; - -CREATE OR REPLACE FUNCTION public.get_contract_voters(this_contract_id text) - RETURNS TABLE(data json) - LANGUAGE sql - PARALLEL SAFE -AS $function$ + limit count$function$; + +create +or replace function public.get_contract_voters (this_contract_id text) returns table (data json) language sql parallel SAFE as $function$ SELECT users.data from users join votes on votes.user_id = users.id where votes.contract_id = this_contract_id; -$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$ +$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 contracts where id = any(contract_ids) and visibility = 'public' and (group_slugs && p_group_slugs) and not (group_slugs && ignore_slugs) -$function$ -; - -CREATE OR REPLACE FUNCTION public.get_cpmm_pool_prob(pool jsonb, p numeric) - RETURNS numeric - LANGUAGE plpgsql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.get_cpmm_pool_prob (pool jsonb, p numeric) returns numeric language plpgsql immutable parallel SAFE as $function$ declare p_no numeric := (pool->>'NO')::numeric; p_yes numeric := (pool->>'YES')::numeric; @@ -296,13 +252,10 @@ declare begin return case when yes_weight = 0 then 1 else (no_weight / yes_weight) end; end -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.get_daily_claimed_boosts(user_id text) - RETURNS TABLE(total numeric) - LANGUAGE sql -AS $function$ +create +or replace function public.get_daily_claimed_boosts (user_id text) returns table (total numeric) language sql as $function$ with daily_totals as ( select SUM(t.amount) as total @@ -314,13 +267,14 @@ with daily_totals as ( ) select total from daily_totals order by total desc; -$function$ -; - -CREATE OR REPLACE FUNCTION public.get_donations_by_charity() - RETURNS TABLE(charity_id text, num_supporters bigint, total numeric) - LANGUAGE sql -AS $function$ +$function$; + +create +or replace function public.get_donations_by_charity () returns table ( + charity_id text, + num_supporters bigint, + total numeric +) language sql as $function$ select to_id as charity_id, count(distinct from_id) as num_supporters, sum(case @@ -334,24 +288,17 @@ AS $function$ where category = 'CHARITY' group by to_id order by total desc -$function$ -; - -CREATE OR REPLACE FUNCTION public.get_group_contracts(this_group_id text) - RETURNS TABLE(data json) - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.get_group_contracts (this_group_id text) returns table (data json) language sql immutable parallel SAFE as $function$ select contracts.data from contracts join group_contracts on group_contracts.contract_id = contracts.id where group_contracts.group_id = this_group_id - $function$ -; + $function$; -CREATE OR REPLACE FUNCTION public.get_love_question_answers_and_lovers(p_question_id bigint) - RETURNS SETOF other_lover_answers_type - LANGUAGE plpgsql -AS $function$ +create +or replace function public.get_love_question_answers_and_lovers (p_question_id bigint) returns setof other_lover_answers_type language plpgsql as $function$ BEGIN RETURN QUERY SELECT @@ -374,13 +321,13 @@ BEGIN love_answers.question_id = p_question_id order by love_answers.created_time desc; END; -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.get_non_empty_private_message_channel_ids(p_user_id text, p_limit integer DEFAULT NULL::integer) - RETURNS TABLE(id bigint) - LANGUAGE plpgsql -AS $function$ +create +or replace function public.get_non_empty_private_message_channel_ids ( + p_user_id text, + p_limit integer default null::integer +) returns table (id bigint) language plpgsql as $function$ BEGIN RETURN QUERY SELECT pumc.id @@ -395,13 +342,14 @@ BEGIN ORDER BY pumc.last_updated_time DESC LIMIT p_limit; 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$ +$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 @@ -412,13 +360,10 @@ where pumcm.user_id = p_user_id and pum.id is not null order by pumc.last_updated_time desc limit p_limit; -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.get_noob_questions() - RETURNS SETOF contracts - LANGUAGE sql -AS $function$with newbs as ( +create +or replace function public.get_noob_questions () returns setof contracts language sql as $function$with newbs as ( select id from users where created_time > now() - interval '2 weeks' @@ -426,23 +371,15 @@ AS $function$with newbs as ( select * from contracts where creator_id in (select * from newbs) and visibility = 'public' - order by created_time desc$function$ -; - -CREATE OR REPLACE FUNCTION public.get_option_voters(this_contract_id text, this_option_id text) - RETURNS TABLE(data json) - LANGUAGE sql - PARALLEL SAFE -AS $function$ + order by created_time desc$function$; + +create +or replace function public.get_option_voters (this_contract_id text, this_option_id text) returns table (data json) language sql parallel SAFE as $function$ SELECT users.data from users join votes on votes.user_id = users.id where votes.contract_id = this_contract_id and votes.id = this_option_id; -$function$ -; - -CREATE OR REPLACE FUNCTION public.get_rating(user_id text) - RETURNS TABLE(count bigint, rating numeric) - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.get_rating (user_id text) returns table (count bigint, rating numeric) language sql immutable parallel SAFE as $function$ WITH -- find average of each user's reviews @@ -482,14 +419,14 @@ AS $function$ -- squash with sigmoid, multiply by 5 5 / (1 + POW(2.71828, -10*(rating.rating-0.5))) AS rating FROM total_count,rating; -$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$ +$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 contracts where @@ -498,26 +435,19 @@ where and not (group_slugs && ignore_slugs) order by last_updated_time desc limit max -$function$ -; - -CREATE OR REPLACE FUNCTION public.get_user_bet_contracts(this_user_id text, this_limit integer) - RETURNS TABLE(data json) - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.get_user_bet_contracts (this_user_id text, this_limit integer) returns table (data json) language sql immutable parallel SAFE as $function$ select c.data from contracts c join user_contract_metrics ucm on c.id = ucm.contract_id where ucm.user_id = this_user_id limit this_limit; -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.get_user_group_id_for_current_user() - RETURNS text - LANGUAGE plpgsql -AS $function$ +create +or replace function public.get_user_group_id_for_current_user () returns text language plpgsql as $function$ DECLARE user_group_id text; BEGIN @@ -528,25 +458,19 @@ BEGIN RETURN user_group_id; END; -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.get_user_manalink_claims(creator_id text) - RETURNS TABLE(manalink_id text, claimant_id text, ts bigint) - LANGUAGE sql -AS $function$ +create +or replace function public.get_user_manalink_claims (creator_id text) returns table (manalink_id text, claimant_id text, ts bigint) language sql as $function$ select mc.manalink_id, (tx.data)->>'toId' as claimant_id, ((tx.data)->'createdTime')::bigint as ts from manalink_claims as mc join manalinks as m on mc.manalink_id = m.id join txns as tx on mc.txn_id = tx.id where m.creator_id = creator_id -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.get_user_topic_interests_2(p_user_id text) - RETURNS TABLE(group_id text, score numeric) - LANGUAGE plpgsql -AS $function$ +create +or replace function public.get_user_topic_interests_2 (p_user_id text) returns table (group_id text, score numeric) language plpgsql as $function$ begin return query select @@ -562,14 +486,10 @@ begin jsonb_each(latest_record.group_ids_to_activity) as kv order by score desc; end; -$function$ -; - -CREATE OR REPLACE FUNCTION public.get_your_contract_ids(uid text) - RETURNS TABLE(contract_id text) - LANGUAGE sql - STABLE PARALLEL SAFE -AS $function$ with your_liked_contracts as ( +$function$; + +create +or replace function public.get_your_contract_ids (uid text) returns table (contract_id text) language sql stable parallel SAFE as $function$ with your_liked_contracts as ( select content_id as contract_id from user_reactions where user_id = uid @@ -583,14 +503,10 @@ select contract_id from your_liked_contracts union select contract_id -from your_followed_contracts $function$ -; - -CREATE OR REPLACE FUNCTION public.get_your_contract_ids(uid text, n integer, start integer) - RETURNS TABLE(contract_id text) - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +from your_followed_contracts $function$; + +create +or replace function public.get_your_contract_ids (uid text, n integer, start integer) returns table (contract_id text) language sql immutable parallel SAFE as $function$ with your_bet_on_contracts as ( select contract_id from user_contract_metrics @@ -612,28 +528,20 @@ AS $function$ select contract_id from your_followed_contracts limit n offset start -$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$ +$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$ +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$ with your_bet_on_contracts as ( select contract_id, (data->>'lastBetTime')::bigint as ts @@ -678,14 +586,10 @@ from recent_unique_contract_ids left join contracts on contracts.id = contract_id where data is not null order by max_ts desc -limit n offset start $function$ -; - -CREATE OR REPLACE FUNCTION public.has_moderator_or_above_role(this_group_id text, this_user_id text) - RETURNS boolean - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +limit n offset start $function$; + +create +or replace function public.has_moderator_or_above_role (this_group_id text, this_user_id text) returns boolean language sql immutable parallel SAFE as $function$ select EXISTS ( SELECT 1 FROM group_members @@ -694,13 +598,10 @@ select EXISTS ( and member_id = this_user_id and (role='admin' or role='moderator') ) - ) $function$ -; + ) $function$; -CREATE OR REPLACE FUNCTION public.install_available_extensions_and_test() - RETURNS boolean - LANGUAGE plpgsql -AS $function$ +create +or replace function public.install_available_extensions_and_test () returns boolean language plpgsql as $function$ DECLARE extension_name TEXT; allowed_extentions TEXT[] := string_to_array(current_setting('supautils.privileged_extensions'), ','); BEGIN @@ -719,24 +620,21 @@ BEGIN RAISE notice 'EXTENSION TESTS COMPLETED..'; return true; END; -$function$ -; - -CREATE OR REPLACE FUNCTION public.is_admin(input_string text) - RETURNS boolean - LANGUAGE plpgsql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.is_admin (input_string text) returns boolean language plpgsql immutable parallel SAFE as $function$ DECLARE -- @Austin, @JamesGrugett, @SG, @DavidChee, @Alice, @ian, @IngaWei, @mqp, @Sinclair, @ManifoldPolitics, @baraki strings TEXT[] := ARRAY[ 'igi2zGXsfxYPgB0DJTXVJVmwCOr2', - 'tlmGNz9kjXc2EteizMORes4qvWl2', - 'uglwf3YKOZNGjjEXKc5HampOFRE2', - 'qJHrvvGfGsYiHZkGY6XjVfIMj233', + '5LZ4LgYuySdL1huCWe7bti02ghx2', + 'tlmGNz9kjXc2EteizMORes4qvWl2', + 'uglwf3YKOZNGjjEXKc5HampOFRE2', + 'qJHrvvGfGsYiHZkGY6XjVfIMj233', 'AJwLWoo3xue32XIiAVrL5SyR1WB2', -- ian 'GRwzCexe5PM6ThrSsodKZT9ziln2', - '62TNqzdBx7X2q621HltsJm8UFht2', + '62TNqzdBx7X2q621HltsJm8UFht2', '0k1suGSJKVUnHbCPEhHNpgZPkUP2', 'vuI5upWB8yU00rP7yxj95J2zd952', 'vUks7InCtYhBFrdLQhqXFUBHD4D2', @@ -746,14 +644,10 @@ DECLARE BEGIN RETURN input_string = ANY(strings); END; -$function$ -; - -CREATE OR REPLACE FUNCTION public.is_group_member(this_group_id text, this_user_id text) - RETURNS boolean - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.is_group_member (this_group_id text, this_user_id text) returns boolean language sql immutable parallel SAFE as $function$ select EXISTS ( SELECT 1 FROM group_members @@ -761,50 +655,31 @@ select EXISTS ( group_id = this_group_id and member_id = this_user_id ) - ) $function$ -; - -CREATE OR REPLACE FUNCTION public.is_valid_contract(ct contracts) - RETURNS boolean - LANGUAGE sql - STABLE PARALLEL SAFE -AS $function$ + ) $function$; + +create +or replace function public.is_valid_contract (ct contracts) returns boolean language sql stable parallel SAFE as $function$ select ct.resolution_time is null and ct.visibility = 'public' - and ((ct.close_time > now() + interval '10 minutes') or ct.close_time is null) $function$ -; - -CREATE OR REPLACE FUNCTION public.jsonb_array_to_text_array(_js jsonb) - RETURNS text[] - LANGUAGE sql - IMMUTABLE PARALLEL SAFE STRICT -AS $function$ + and ((ct.close_time > now() + interval '10 minutes') or ct.close_time is null) $function$; + +create +or replace function public.jsonb_array_to_text_array (_js jsonb) returns text[] language sql immutable parallel SAFE strict as $function$ select array(select jsonb_array_elements_text(_js)) -$function$ -; - -CREATE OR REPLACE FUNCTION public.millis_interval(start_millis bigint, end_millis bigint) - RETURNS interval - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.millis_interval (start_millis bigint, end_millis bigint) returns interval language sql immutable parallel SAFE as $function$ select millis_to_ts(end_millis) - millis_to_ts(start_millis) -$function$ -; - -CREATE OR REPLACE FUNCTION public.millis_to_ts(millis bigint) - RETURNS timestamp with time zone - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.millis_to_ts (millis bigint) returns timestamp with time zone language sql immutable parallel SAFE as $function$ select to_timestamp(millis / 1000.0) -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.pgrst_ddl_watch() - RETURNS event_trigger - LANGUAGE plpgsql -AS $function$ +create +or replace function public.pgrst_ddl_watch () returns event_trigger language plpgsql as $function$ DECLARE cmd record; BEGIN @@ -828,13 +703,10 @@ BEGIN NOTIFY pgrst, 'reload schema'; END IF; END LOOP; -END; $function$ -; +END; $function$; -CREATE OR REPLACE FUNCTION public.pgrst_drop_watch() - RETURNS event_trigger - LANGUAGE plpgsql -AS $function$ +create +or replace function public.pgrst_drop_watch () returns event_trigger language plpgsql as $function$ DECLARE obj record; BEGIN @@ -856,26 +728,27 @@ BEGIN NOTIFY pgrst, 'reload schema'; END IF; END LOOP; -END; $function$ -; - -CREATE OR REPLACE FUNCTION public.profit_leaderboard(limit_n integer) - RETURNS TABLE(user_id text, profit numeric, name text, username text, avatar_url text) - LANGUAGE sql - STABLE PARALLEL SAFE -AS $function$ +END; $function$; + +create +or replace function public.profit_leaderboard (limit_n integer) returns table ( + user_id text, + profit numeric, + name text, + username text, + avatar_url text +) language sql stable parallel SAFE as $function$ select p.user_id, coalesce(p.profit, p.balance + p.spice_balance + p.investment_value - p.total_deposits) as profit, u.name, u.username, u.data->>'avatarUrl' as avatar_url from user_portfolio_history_latest p join users u on p.user_id = u.id order by profit desc limit limit_n -$function$ -; - -CREATE OR REPLACE FUNCTION public.profit_rank(uid text, excluded_ids text[] DEFAULT ARRAY[]::text[]) - RETURNS integer - LANGUAGE sql - STABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.profit_rank ( + uid text, + excluded_ids text[] default array[]::text[] +) returns integer language sql stable parallel SAFE as $function$ select count(*) + 1 from user_portfolio_history_latest where not user_id = any(excluded_ids) @@ -884,13 +757,10 @@ where not user_id = any(excluded_ids) from user_portfolio_history_latest u where u.user_id = uid ) -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.random_alphanumeric(length integer) - RETURNS text - LANGUAGE plpgsql -AS $function$ +create +or replace function public.random_alphanumeric (length integer) returns text language plpgsql as $function$ DECLARE result TEXT; BEGIN @@ -906,27 +776,19 @@ BEGIN RETURN result; END; -$function$ -; - -CREATE OR REPLACE FUNCTION public.recently_liked_contract_counts(since bigint) - RETURNS TABLE(contract_id text, n integer) - LANGUAGE sql - STABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.recently_liked_contract_counts (since bigint) returns table (contract_id text, n integer) language sql stable parallel SAFE as $function$ select content_id as contract_id, count(*) as n from user_reactions where content_type = 'contract' and public.ts_to_millis(created_time) > since -group by contract_id $function$ -; - -CREATE OR REPLACE FUNCTION public.sample_resolved_bets(trader_threshold integer, p numeric) - RETURNS TABLE(prob numeric, is_yes boolean) - LANGUAGE sql - STABLE PARALLEL SAFE -AS $function$ +group by contract_id $function$; + +create +or replace function public.sample_resolved_bets (trader_threshold integer, p numeric) returns table (prob numeric, is_yes boolean) language sql stable parallel SAFE as $function$ select 0.5 * ((contract_bets.prob_before)::numeric + (contract_bets.prob_after)::numeric) as prob, ((contracts.resolution)::text = 'YES')::boolean as is_yes from contract_bets @@ -938,13 +800,10 @@ where and (contracts.data->>'uniqueBettorCount')::int >= trader_threshold and amount > 0 and random() < p -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.save_user_topics_blank(p_user_id text) - RETURNS void - LANGUAGE sql -AS $function$ +create +or replace function public.save_user_topics_blank (p_user_id text) returns void language sql as $function$ with topic_embedding as ( select avg(embedding) as average @@ -963,13 +822,14 @@ values ( ) on conflict (user_id) do update set topics = excluded.topics, topic_embedding = excluded.topic_embedding; -$function$ -; - -CREATE OR REPLACE FUNCTION public.search_contract_embeddings(query_embedding vector, similarity_threshold double precision, match_count integer) - RETURNS TABLE(contract_id text, similarity double precision) - LANGUAGE plpgsql -AS $function$ begin return query +$function$; + +create +or replace function public.search_contract_embeddings ( + query_embedding vector, + similarity_threshold double precision, + match_count integer +) returns table (contract_id text, similarity double precision) language plpgsql as $function$ begin return query select contract_embeddings.contract_id as contract_id, 1 - ( contract_embeddings.embedding <=> query_embedding @@ -981,13 +841,10 @@ AS $function$ begin return query order by contract_embeddings.embedding <=> query_embedding limit match_count; end; -$function$ -; +$function$; -CREATE OR REPLACE FUNCTION public.test() - RETURNS void - LANGUAGE plpgsql -AS $function$ +create +or replace function public.test () returns void language plpgsql as $function$ BEGIN RAISE LOG 'Beginning Test: %', CURRENT_TIMESTAMP; NOTIFY pgrst, 'reload schema'; @@ -997,31 +854,17 @@ BEGIN WHEN others THEN RAISE EXCEPTION 'An error occurred: %', SQLERRM; END; -$function$ -; - -CREATE OR REPLACE FUNCTION public.to_jsonb(jsonb) - RETURNS jsonb - LANGUAGE sql - IMMUTABLE PARALLEL SAFE STRICT -AS $function$ select $1 $function$ -; - -CREATE OR REPLACE FUNCTION public.ts_to_millis(ts timestamp with time zone) - RETURNS bigint - LANGUAGE sql - IMMUTABLE PARALLEL SAFE -AS $function$ +$function$; + +create +or replace function public.to_jsonb (jsonb) returns jsonb language sql immutable parallel SAFE strict as $function$ select $1 $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 -$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 -$function$ -; +$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 +$function$; diff --git a/backend/supabase/gidx_receipts.sql b/backend/supabase/gidx_receipts.sql index 6e9ee64985..b5657eb618 100644 --- a/backend/supabase/gidx_receipts.sql +++ b/backend/supabase/gidx_receipts.sql @@ -1,41 +1,46 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS gidx_receipts ( - amount numeric(20,2), - callback_data jsonb, - created_time timestamp with time zone DEFAULT now() NOT NULL, - currency text, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - merchant_session_id text, - merchant_transaction_id text NOT NULL, - payment_amount_type text, - payment_data jsonb, - payment_method_type text, - payment_status_code text, - payment_status_message text, - reason_codes text[], - service_type text, - session_id text NOT NULL, - session_score integer, - status text, - status_code integer, - transaction_status_code text, - transaction_status_message text, - txn_id text, - user_id text -); +create table if not exists + gidx_receipts ( + amount numeric(20, 2), + callback_data jsonb, + created_time timestamp with time zone default now() not null, + currency text, + id bigint primary key generated always as identity not null, + merchant_session_id text, + merchant_transaction_id text not null, + payment_amount_type text, + payment_data jsonb, + payment_method_type text, + payment_status_code text, + payment_status_message text, + reason_codes text[], + service_type text, + session_id text not null, + session_score integer, + status text, + status_code integer, + transaction_status_code text, + transaction_status_message text, + txn_id text, + user_id text + ); -- Foreign Keys -ALTER TABLE gidx_receipts ADD CONSTRAINT gidx_receipts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); - +alter table gidx_receipts +add constraint gidx_receipts_user_id_fkey foreign key (user_id) references users (id); -- Row Level Security -ALTER TABLE gidx_receipts ENABLE ROW LEVEL SECURITY; +alter table gidx_receipts enable row level security; + -- Indexes -DROP INDEX IF EXISTS cash_out_receipts_merchant_transaction_id_idx; -CREATE INDEX cash_out_receipts_merchant_transaction_id_idx ON public.gidx_receipts USING btree (merchant_transaction_id); -DROP INDEX IF EXISTS cash_out_receipts_user_id_idx; -CREATE INDEX cash_out_receipts_user_id_idx ON public.gidx_receipts USING btree (user_id); -DROP INDEX IF EXISTS gidx_receipts_pkey; -CREATE UNIQUE INDEX gidx_receipts_pkey ON public.gidx_receipts USING btree (id); +drop index if exists cash_out_receipts_merchant_transaction_id_idx; + +create index cash_out_receipts_merchant_transaction_id_idx on public.gidx_receipts using btree (merchant_transaction_id); + +drop index if exists cash_out_receipts_user_id_idx; + +create index cash_out_receipts_user_id_idx on public.gidx_receipts using btree (user_id); + +drop index if exists gidx_receipts_pkey; +create unique index gidx_receipts_pkey on public.gidx_receipts using btree (id); diff --git a/backend/supabase/group_contracts.sql b/backend/supabase/group_contracts.sql index 3d9ce978e4..7121019177 100644 --- a/backend/supabase/group_contracts.sql +++ b/backend/supabase/group_contracts.sql @@ -1,26 +1,41 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS group_contracts ( - contract_id text NOT NULL, - group_id text NOT NULL, - CONSTRAINT PRIMARY KEY (group_id, contract_id) -); +create table if not exists + group_contracts ( + contract_id text not null, + group_id text not null, + constraint primary key (group_id, contract_id) + ); -- Foreign Keys -ALTER TABLE group_contracts ADD CONSTRAINT group_contracts_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON UPDATE CASCADE; - +alter table group_contracts +add constraint group_contracts_group_id_fkey foreign key (group_id) references groups (id) on update cascade; -- Row Level Security -ALTER TABLE group_contracts ENABLE ROW LEVEL SECURITY; +alter table group_contracts enable row level security; + -- Policies -DROP POLICY IF EXISTS "Enable read access for bets on markets user can access" ON group_contracts; -CREATE POLICY "Enable read access for bets on markets user can access" ON group_contracts FOR SELECT USING ((EXISTS ( SELECT 1 - FROM groups - WHERE (groups.id = group_contracts.group_id)))) ; +drop policy if exists "Enable read access for bets on markets user can access" on group_contracts; + +create policy "Enable read access for bets on markets user can access" on group_contracts for +select + using ( + ( + exists ( + select + 1 + from + groups + where + (groups.id = group_contracts.group_id) + ) + ) + ); -- Indexes -DROP INDEX IF EXISTS group_contracts_contract_id; -CREATE INDEX group_contracts_contract_id ON public.group_contracts USING btree (contract_id); -DROP INDEX IF EXISTS group_contracts_pkey; -CREATE UNIQUE INDEX group_contracts_pkey ON public.group_contracts USING btree (group_id, contract_id); +drop index if exists group_contracts_contract_id; + +create index group_contracts_contract_id on public.group_contracts using btree (contract_id); + +drop index if exists group_contracts_pkey; +create unique index group_contracts_pkey on public.group_contracts using btree (group_id, contract_id); diff --git a/backend/supabase/group_embeddings.sql b/backend/supabase/group_embeddings.sql index 7ef8ffea71..1037723911 100644 --- a/backend/supabase/group_embeddings.sql +++ b/backend/supabase/group_embeddings.sql @@ -1,25 +1,30 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS group_embeddings ( - created_time timestamp without time zone DEFAULT now() NOT NULL, - embedding vector(1536) NOT NULL, - group_id text PRIMARY KEY NOT NULL -); +create table if not exists + group_embeddings ( + created_time timestamp without time zone default now() not null, + embedding vector (1536) not null, + group_id text primary key not null + ); -- Foreign Keys -ALTER TABLE group_embeddings ADD CONSTRAINT public_group_embeddings_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON UPDATE CASCADE ON DELETE CASCADE; - +alter table group_embeddings +add constraint public_group_embeddings_group_id_fkey foreign key (group_id) references groups (id) on update cascade on delete cascade; -- Row Level Security -ALTER TABLE group_embeddings ENABLE ROW LEVEL SECURITY; +alter table group_embeddings enable row level security; + -- Policies -DROP POLICY IF EXISTS "admin write access" ON group_embeddings; -CREATE POLICY "admin write access" ON group_embeddings FOR ALL TO service_role ; +drop policy if exists "admin write access" on group_embeddings; + +create policy "admin write access" on group_embeddings for all to service_role; + +drop policy if exists "public read" on group_embeddings; -DROP POLICY IF EXISTS "public read" ON group_embeddings; -CREATE POLICY "public read" ON group_embeddings FOR SELECT USING (true) ; +create policy "public read" on group_embeddings for +select + using (true); -- Indexes -DROP INDEX IF EXISTS group_embeddings_pkey; -CREATE UNIQUE INDEX group_embeddings_pkey ON public.group_embeddings USING btree (group_id); +drop index if exists group_embeddings_pkey; +create unique index group_embeddings_pkey on public.group_embeddings using btree (group_id); diff --git a/backend/supabase/group_groups.sql b/backend/supabase/group_groups.sql index ac31f0b472..923e77fe9e 100644 --- a/backend/supabase/group_groups.sql +++ b/backend/supabase/group_groups.sql @@ -1,23 +1,29 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS group_groups ( - bottom_id text NOT NULL, - top_id text NOT NULL, - CONSTRAINT PRIMARY KEY (top_id, bottom_id) -); +create table if not exists + group_groups ( + bottom_id text not null, + top_id text not null, + constraint primary key (top_id, bottom_id) + ); -- Foreign Keys -ALTER TABLE group_groups ADD CONSTRAINT group_groups_bottom_id_fkey FOREIGN KEY (bottom_id) REFERENCES groups(id) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE group_groups ADD CONSTRAINT group_groups_top_id_fkey FOREIGN KEY (top_id) REFERENCES groups(id) ON UPDATE CASCADE ON DELETE CASCADE; +alter table group_groups +add constraint group_groups_bottom_id_fkey foreign key (bottom_id) references groups (id) on update cascade on delete cascade; +alter table group_groups +add constraint group_groups_top_id_fkey foreign key (top_id) references groups (id) on update cascade on delete cascade; -- Row Level Security -ALTER TABLE group_groups ENABLE ROW LEVEL SECURITY; +alter table group_groups enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON group_groups; -CREATE POLICY "public read" ON group_groups FOR SELECT USING (true) ; +drop policy if exists "public read" on group_groups; + +create policy "public read" on group_groups for +select + using (true); -- Indexes -DROP INDEX IF EXISTS group_groups_top_id_bottom_id_pkey; -CREATE UNIQUE INDEX group_groups_top_id_bottom_id_pkey ON public.group_groups USING btree (top_id, bottom_id); +drop index if exists group_groups_top_id_bottom_id_pkey; +create unique index group_groups_top_id_bottom_id_pkey on public.group_groups using btree (top_id, bottom_id); diff --git a/backend/supabase/group_invites.sql b/backend/supabase/group_invites.sql index e474a0c83e..7cd5c21689 100644 --- a/backend/supabase/group_invites.sql +++ b/backend/supabase/group_invites.sql @@ -1,36 +1,38 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS group_invites ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - duration interval DEFAULT '7 days'::interval, - expire_time timestamp with time zone, - group_id text NOT NULL, - id text PRIMARY KEY DEFAULT random_alphanumeric(12) NOT NULL, - is_forever boolean GENERATED ALWAYS AS ( -CASE - WHEN duration IS NULL THEN true - ELSE false -END) STORED, - is_max_uses_reached boolean GENERATED ALWAYS AS ( -CASE - WHEN max_uses IS NULL THEN false - ELSE uses >= max_uses -END) STORED, - max_uses numeric, - uses numeric DEFAULT 0 NOT NULL -); +create table if not exists + group_invites ( + created_time timestamp with time zone default now() not null, + duration interval default '7 days'::interval, + expire_time timestamp with time zone, + group_id text not null, + id text primary key default random_alphanumeric (12) not null, + is_forever boolean generated always as ( + case + when duration is null then true + else false + end + ) stored, + is_max_uses_reached boolean generated always as ( + case + when max_uses is null then false + else uses >= max_uses + end + ) stored, + max_uses numeric, + uses numeric default 0 not null + ); -- Foreign Keys -ALTER TABLE group_invites ADD CONSTRAINT public_group_invites_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON UPDATE CASCADE ON DELETE CASCADE; +alter table group_invites +add constraint public_group_invites_group_id_fkey foreign key (group_id) references groups (id) on update cascade on delete cascade; -- Triggers -CREATE TRIGGER populate_group_invites_expire_time BEFORE INSERT ON public.group_invites FOR EACH ROW EXECUTE FUNCTION set_expire_time(); +create trigger populate_group_invites_expire_time before insert on public.group_invites for each row +execute function set_expire_time (); -- Functions -CREATE OR REPLACE FUNCTION public.set_expire_time() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ +create +or replace function public.set_expire_time () returns trigger language plpgsql as $function$ BEGIN IF NEW.duration IS NULL THEN NEW.expire_time = NULL; @@ -39,16 +41,19 @@ BEGIN END IF; RETURN NEW; END; -$function$ -; +$function$; -- Row Level Security -ALTER TABLE group_invites ENABLE ROW LEVEL SECURITY; +alter table group_invites enable row level security; + -- Policies -DROP POLICY IF EXISTS "Enable read access for admin" ON group_invites; -CREATE POLICY "Enable read access for admin" ON group_invites FOR SELECT TO service_role USING (true) ; +drop policy if exists "Enable read access for admin" on group_invites; + +create policy "Enable read access for admin" on group_invites for +select + to service_role using (true); -- Indexes -DROP INDEX IF EXISTS group_invites_pkey; -CREATE UNIQUE INDEX group_invites_pkey ON public.group_invites USING btree (id); +drop index if exists group_invites_pkey; +create unique index group_invites_pkey on public.group_invites using btree (id); diff --git a/backend/supabase/group_members.sql b/backend/supabase/group_members.sql index ef309498e5..e75493f4cf 100644 --- a/backend/supabase/group_members.sql +++ b/backend/supabase/group_members.sql @@ -1,51 +1,57 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS group_members ( - created_time timestamp with time zone DEFAULT now(), - group_id text NOT NULL, - member_id text NOT NULL, - role text DEFAULT 'member'::text NOT NULL, - CONSTRAINT PRIMARY KEY (group_id, member_id) -); +create table if not exists + group_members ( + created_time timestamp with time zone default now(), + group_id text not null, + member_id text not null, + role text default 'member'::text not null, + constraint primary key (group_id, member_id) + ); -- Foreign Keys -ALTER TABLE group_members ADD CONSTRAINT public_group_members_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON UPDATE CASCADE; +alter table group_members +add constraint public_group_members_group_id_fkey foreign key (group_id) references groups (id) on update cascade; -- Triggers -CREATE TRIGGER decrement_group BEFORE DELETE ON public.group_members FOR EACH ROW EXECUTE FUNCTION decrement_group_members(); -CREATE TRIGGER increment_group AFTER INSERT ON public.group_members FOR EACH ROW EXECUTE FUNCTION increment_group_members(); +create trigger decrement_group before delete on public.group_members for each row +execute function decrement_group_members (); + +create trigger increment_group +after insert on public.group_members for each row +execute function increment_group_members (); -- Functions -CREATE OR REPLACE FUNCTION public.decrement_group_members() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ begin +create +or replace function public.decrement_group_members () returns trigger language plpgsql as $function$ begin update groups set total_members = total_members - 1 where id = old.group_id; return old; -end $function$ -; +end $function$; -CREATE OR REPLACE FUNCTION public.increment_group_members() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ begin +create +or replace function public.increment_group_members () returns trigger language plpgsql as $function$ begin update groups set total_members = total_members + 1 where id = new.group_id; return new; -end $function$ -; +end $function$; -- Row Level Security -ALTER TABLE group_members ENABLE ROW LEVEL SECURITY; +alter table group_members enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON group_members; -CREATE POLICY "public read" ON group_members FOR SELECT USING (true) ; +drop policy if exists "public read" on group_members; + +create policy "public read" on group_members for +select + using (true); -DROP POLICY IF EXISTS "user can leave" ON group_members; -CREATE POLICY "user can leave" ON group_members FOR DELETE USING ((member_id = firebase_uid())) ; +drop policy if exists "user can leave" on group_members; + +create policy "user can leave" on group_members for delete using ((member_id = firebase_uid ())); -- Indexes -DROP INDEX IF EXISTS group_members_member_id_idx; -CREATE INDEX group_members_member_id_idx ON public.group_members USING btree (member_id); -DROP INDEX IF EXISTS group_members_pkey; -CREATE UNIQUE INDEX group_members_pkey ON public.group_members USING btree (group_id, member_id); +drop index if exists group_members_member_id_idx; + +create index group_members_member_id_idx on public.group_members using btree (member_id); + +drop index if exists group_members_pkey; +create unique index group_members_pkey on public.group_members using btree (group_id, member_id); diff --git a/backend/supabase/groups.sql b/backend/supabase/groups.sql index e272b7c0e9..fd1aff49cc 100644 --- a/backend/supabase/groups.sql +++ b/backend/supabase/groups.sql @@ -1,34 +1,42 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS groups ( - about jsonb, - banner_url text, - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_id text, - id text PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, - importance_score numeric DEFAULT 0, - name text NOT NULL, - name_fts tsvector GENERATED ALWAYS AS (to_tsvector('english'::regconfig, name)) STORED, - privacy_status text, - slug text NOT NULL, - total_members numeric DEFAULT 0 -); - - +create table if not exists + groups ( + about jsonb, + banner_url text, + created_time timestamp with time zone default now() not null, + creator_id text, + id text primary key default uuid_generate_v4 () not null, + importance_score numeric default 0, + name text not null, + name_fts tsvector generated always as (to_tsvector('english'::regconfig, name)) stored, + privacy_status text, + slug text not null, + total_members numeric default 0 + ); -- Row Level Security -ALTER TABLE groups ENABLE ROW LEVEL SECURITY; +alter table groups enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON groups; -CREATE POLICY "public read" ON groups FOR SELECT USING (true) ; +drop policy if exists "public read" on groups; + +create policy "public read" on groups for +select + using (true); -- Indexes -DROP INDEX IF EXISTS group_slug; -CREATE INDEX group_slug ON public.groups USING btree (slug); -DROP INDEX IF EXISTS groups_pkey; -CREATE UNIQUE INDEX groups_pkey ON public.groups USING btree (id); -DROP INDEX IF EXISTS privacy_status_idx; -CREATE INDEX privacy_status_idx ON public.groups USING btree (privacy_status); -DROP INDEX IF EXISTS total_members; -CREATE INDEX total_members ON public.groups USING btree (total_members DESC); +drop index if exists group_slug; + +create index group_slug on public.groups using btree (slug); + +drop index if exists groups_pkey; + +create unique index groups_pkey on public.groups using btree (id); + +drop index if exists privacy_status_idx; + +create index privacy_status_idx on public.groups using btree (privacy_status); + +drop index if exists total_members; +create index total_members on public.groups using btree (total_members desc); diff --git a/backend/supabase/kyc_bonus_rewards.sql b/backend/supabase/kyc_bonus_rewards.sql index f877c5fa84..2d2a19b24a 100644 --- a/backend/supabase/kyc_bonus_rewards.sql +++ b/backend/supabase/kyc_bonus_rewards.sql @@ -1,24 +1,28 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS kyc_bonus_rewards ( - claim_time timestamp with time zone, - claimed boolean DEFAULT false, - created_time timestamp with time zone DEFAULT now(), - reward_amount numeric NOT NULL, - user_id text PRIMARY KEY NOT NULL -); +create table if not exists + kyc_bonus_rewards ( + claim_time timestamp with time zone, + claimed boolean default false, + created_time timestamp with time zone default now(), + reward_amount numeric not null, + user_id text primary key not null + ); -- Foreign Keys -ALTER TABLE kyc_bonus_rewards ADD CONSTRAINT kyc_bonus_rewards_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); - +alter table kyc_bonus_rewards +add constraint kyc_bonus_rewards_user_id_fkey foreign key (user_id) references users (id); -- Row Level Security -ALTER TABLE kyc_bonus_rewards ENABLE ROW LEVEL SECURITY; +alter table kyc_bonus_rewards enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON kyc_bonus_rewards; -CREATE POLICY "public read" ON kyc_bonus_rewards FOR SELECT USING (true) ; +drop policy if exists "public read" on kyc_bonus_rewards; + +create policy "public read" on kyc_bonus_rewards for +select + using (true); -- Indexes -DROP INDEX IF EXISTS kyc_bonus_rewards_pkey; -CREATE UNIQUE INDEX kyc_bonus_rewards_pkey ON public.kyc_bonus_rewards USING btree (user_id); +drop index if exists kyc_bonus_rewards_pkey; +create unique index kyc_bonus_rewards_pkey on public.kyc_bonus_rewards using btree (user_id); diff --git a/backend/supabase/league_chats.sql b/backend/supabase/league_chats.sql index 97fac3f27f..ab78139f70 100644 --- a/backend/supabase/league_chats.sql +++ b/backend/supabase/league_chats.sql @@ -1,26 +1,30 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS league_chats ( - channel_id text NOT NULL, - cohort text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - division integer NOT NULL, - id serial NOT NULL, - owner_id text, - season integer NOT NULL -); - - +create table if not exists + league_chats ( + channel_id text not null, + cohort text not null, + created_time timestamp with time zone default now() not null, + division integer not null, + id serial not null, + owner_id text, + season integer not null + ); -- Row Level Security -ALTER TABLE league_chats ENABLE ROW LEVEL SECURITY; +alter table league_chats enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON league_chats; -CREATE POLICY "public read" ON league_chats FOR SELECT USING (true) ; +drop policy if exists "public read" on league_chats; + +create policy "public read" on league_chats for +select + using (true); -- Indexes -DROP INDEX IF EXISTS league_chats_pkey; -CREATE UNIQUE INDEX league_chats_pkey ON public.league_chats USING btree (id); -DROP INDEX IF EXISTS league_chats_season_division_cohort_key; -CREATE UNIQUE INDEX league_chats_season_division_cohort_key ON public.league_chats USING btree (season, division, cohort); +drop index if exists league_chats_pkey; + +create unique index league_chats_pkey on public.league_chats using btree (id); + +drop index if exists league_chats_season_division_cohort_key; +create unique index league_chats_season_division_cohort_key on public.league_chats using btree (season, division, cohort); diff --git a/backend/supabase/leagues.sql b/backend/supabase/leagues.sql index 2a8195c835..489d9646e0 100644 --- a/backend/supabase/leagues.sql +++ b/backend/supabase/leagues.sql @@ -1,28 +1,32 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS leagues ( - cohort text NOT NULL, - created_time timestamp without time zone DEFAULT now() NOT NULL, - division integer NOT NULL, - id uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, - mana_earned numeric DEFAULT 0.0 NOT NULL, - mana_earned_breakdown jsonb DEFAULT '{}'::jsonb NOT NULL, - rank_snapshot integer, - season integer NOT NULL, - user_id text NOT NULL -); - - +create table if not exists + leagues ( + cohort text not null, + created_time timestamp without time zone default now() not null, + division integer not null, + id uuid primary key default gen_random_uuid () not null, + mana_earned numeric default 0.0 not null, + mana_earned_breakdown jsonb default '{}'::jsonb not null, + rank_snapshot integer, + season integer not null, + user_id text not null + ); -- Row Level Security -ALTER TABLE leagues ENABLE ROW LEVEL SECURITY; +alter table leagues enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON leagues; -CREATE POLICY "public read" ON leagues FOR SELECT USING (true) ; +drop policy if exists "public read" on leagues; + +create policy "public read" on leagues for +select + using (true); -- Indexes -DROP INDEX IF EXISTS leagues_pkey; -CREATE UNIQUE INDEX leagues_pkey ON public.leagues USING btree (id); -DROP INDEX IF EXISTS unique_user_id_season; -CREATE UNIQUE INDEX unique_user_id_season ON public.leagues USING btree (user_id, season); +drop index if exists leagues_pkey; + +create unique index leagues_pkey on public.leagues using btree (id); + +drop index if exists unique_user_id_season; +create unique index unique_user_id_season on public.leagues using btree (user_id, season); diff --git a/backend/supabase/love_answers.sql b/backend/supabase/love_answers.sql index 588da5b0ad..a5137a34b5 100644 --- a/backend/supabase/love_answers.sql +++ b/backend/supabase/love_answers.sql @@ -1,39 +1,54 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + love_answers ( + created_time timestamp with time zone default now() not null, + creator_id text not null, + free_response text, + id bigint primary key generated always as identity not null, + integer integer, + multiple_choice integer, + question_id bigint not null + ); -CREATE TABLE IF NOT EXISTS love_answers ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_id text NOT NULL, - free_response text, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - integer integer, - multiple_choice integer, - question_id bigint NOT NULL -); +-- Row Level Security +alter table love_answers enable row level security; +-- Policies +drop policy if exists "public read" on love_answers; +create policy "public read" on love_answers for +select + using (true); --- Row Level Security -ALTER TABLE love_answers ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "public read" ON love_answers; -CREATE POLICY "public read" ON love_answers FOR SELECT USING (true) ; +drop policy if exists "self delete" on love_answers; + +create policy "self delete" on love_answers for delete using ((creator_id = firebase_uid ())); + +drop policy if exists "self insert" on love_answers; -DROP POLICY IF EXISTS "self delete" ON love_answers; -CREATE POLICY "self delete" ON love_answers FOR DELETE USING ((creator_id = firebase_uid())) ; +create policy "self insert" on love_answers for insert +with + check ((creator_id = firebase_uid ())); -DROP POLICY IF EXISTS "self insert" ON love_answers; -CREATE POLICY "self insert" ON love_answers FOR INSERT WITH CHECK ((creator_id = firebase_uid())); +drop policy if exists "self update" on love_answers; -DROP POLICY IF EXISTS "self update" ON love_answers; -CREATE POLICY "self update" ON love_answers FOR UPDATE USING ((creator_id = firebase_uid())) ; +create policy "self update" on love_answers +for update + using ((creator_id = firebase_uid ())); -- Indexes -DROP INDEX IF EXISTS love_answers_creator_id_created_time_idx; -CREATE INDEX love_answers_creator_id_created_time_idx ON public.love_answers USING btree (creator_id, created_time DESC); -DROP INDEX IF EXISTS love_answers_pkey; -CREATE UNIQUE INDEX love_answers_pkey ON public.love_answers USING btree (id); -DROP INDEX IF EXISTS love_answers_question_creator_unique; -CREATE UNIQUE INDEX love_answers_question_creator_unique ON public.love_answers USING btree (question_id, creator_id); -DROP INDEX IF EXISTS love_answers_question_id_idx; -CREATE INDEX love_answers_question_id_idx ON public.love_answers USING btree (question_id); +drop index if exists love_answers_creator_id_created_time_idx; + +create index love_answers_creator_id_created_time_idx on public.love_answers using btree (creator_id, created_time desc); + +drop index if exists love_answers_pkey; + +create unique index love_answers_pkey on public.love_answers using btree (id); + +drop index if exists love_answers_question_creator_unique; + +create unique index love_answers_question_creator_unique on public.love_answers using btree (question_id, creator_id); + +drop index if exists love_answers_question_id_idx; +create index love_answers_question_id_idx on public.love_answers using btree (question_id); diff --git a/backend/supabase/love_compatibility_answers.sql b/backend/supabase/love_compatibility_answers.sql index 6e3feebcc5..dc534551b5 100644 --- a/backend/supabase/love_compatibility_answers.sql +++ b/backend/supabase/love_compatibility_answers.sql @@ -1,40 +1,55 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + love_compatibility_answers ( + created_time timestamp with time zone default now() not null, + creator_id text not null, + explanation text, + id bigint primary key generated always as identity not null, + importance integer not null, + multiple_choice integer not null, + pref_choices integer[] not null, + question_id bigint not null + ); -CREATE TABLE IF NOT EXISTS love_compatibility_answers ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_id text NOT NULL, - explanation text, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - importance integer NOT NULL, - multiple_choice integer NOT NULL, - pref_choices integer[] NOT NULL, - question_id bigint NOT NULL -); +-- Row Level Security +alter table love_compatibility_answers enable row level security; +-- Policies +drop policy if exists "public read" on love_compatibility_answers; +create policy "public read" on love_compatibility_answers for +select + using (true); --- Row Level Security -ALTER TABLE love_compatibility_answers ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "public read" ON love_compatibility_answers; -CREATE POLICY "public read" ON love_compatibility_answers FOR SELECT USING (true) ; +drop policy if exists "self delete" on love_compatibility_answers; + +create policy "self delete" on love_compatibility_answers for delete using ((creator_id = firebase_uid ())); + +drop policy if exists "self insert" on love_compatibility_answers; -DROP POLICY IF EXISTS "self delete" ON love_compatibility_answers; -CREATE POLICY "self delete" ON love_compatibility_answers FOR DELETE USING ((creator_id = firebase_uid())) ; +create policy "self insert" on love_compatibility_answers for insert +with + check ((creator_id = firebase_uid ())); -DROP POLICY IF EXISTS "self insert" ON love_compatibility_answers; -CREATE POLICY "self insert" ON love_compatibility_answers FOR INSERT WITH CHECK ((creator_id = firebase_uid())); +drop policy if exists "self update" on love_compatibility_answers; -DROP POLICY IF EXISTS "self update" ON love_compatibility_answers; -CREATE POLICY "self update" ON love_compatibility_answers FOR UPDATE USING ((creator_id = firebase_uid())) ; +create policy "self update" on love_compatibility_answers +for update + using ((creator_id = firebase_uid ())); -- Indexes -DROP INDEX IF EXISTS love_compatibility_answers_creator_id_created_time_idx; -CREATE INDEX love_compatibility_answers_creator_id_created_time_idx ON public.love_compatibility_answers USING btree (creator_id, created_time DESC); -DROP INDEX IF EXISTS love_compatibility_answers_pkey; -CREATE UNIQUE INDEX love_compatibility_answers_pkey ON public.love_compatibility_answers USING btree (id); -DROP INDEX IF EXISTS love_compatibility_answers_question_creator_unique; -CREATE UNIQUE INDEX love_compatibility_answers_question_creator_unique ON public.love_compatibility_answers USING btree (question_id, creator_id); -DROP INDEX IF EXISTS love_compatibility_answers_question_id_idx; -CREATE INDEX love_compatibility_answers_question_id_idx ON public.love_compatibility_answers USING btree (question_id); +drop index if exists love_compatibility_answers_creator_id_created_time_idx; + +create index love_compatibility_answers_creator_id_created_time_idx on public.love_compatibility_answers using btree (creator_id, created_time desc); + +drop index if exists love_compatibility_answers_pkey; + +create unique index love_compatibility_answers_pkey on public.love_compatibility_answers using btree (id); + +drop index if exists love_compatibility_answers_question_creator_unique; + +create unique index love_compatibility_answers_question_creator_unique on public.love_compatibility_answers using btree (question_id, creator_id); + +drop index if exists love_compatibility_answers_question_id_idx; +create index love_compatibility_answers_question_id_idx on public.love_compatibility_answers using btree (question_id); diff --git a/backend/supabase/love_likes.sql b/backend/supabase/love_likes.sql index b8fc364522..80c6557ab4 100644 --- a/backend/supabase/love_likes.sql +++ b/backend/supabase/love_likes.sql @@ -1,24 +1,28 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS love_likes ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_id text NOT NULL, - like_id text DEFAULT random_alphanumeric(12) NOT NULL, - target_id text NOT NULL, - CONSTRAINT PRIMARY KEY (creator_id, like_id) -); - - +create table if not exists + love_likes ( + created_time timestamp with time zone default now() not null, + creator_id text not null, + like_id text default random_alphanumeric (12) not null, + target_id text not null, + constraint primary key (creator_id, like_id) + ); -- Row Level Security -ALTER TABLE love_likes ENABLE ROW LEVEL SECURITY; +alter table love_likes enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON love_likes; -CREATE POLICY "public read" ON love_likes FOR SELECT USING (true) ; +drop policy if exists "public read" on love_likes; + +create policy "public read" on love_likes for +select + using (true); -- Indexes -DROP INDEX IF EXISTS love_likes_pkey; -CREATE UNIQUE INDEX love_likes_pkey ON public.love_likes USING btree (creator_id, like_id); -DROP INDEX IF EXISTS user_likes_target_id_raw; -CREATE INDEX user_likes_target_id_raw ON public.love_likes USING btree (target_id); +drop index if exists love_likes_pkey; + +create unique index love_likes_pkey on public.love_likes using btree (creator_id, like_id); + +drop index if exists user_likes_target_id_raw; +create index user_likes_target_id_raw on public.love_likes using btree (target_id); diff --git a/backend/supabase/love_questions.sql b/backend/supabase/love_questions.sql index 0999d4c263..24ae76809a 100644 --- a/backend/supabase/love_questions.sql +++ b/backend/supabase/love_questions.sql @@ -1,24 +1,24 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS love_questions ( - answer_type text DEFAULT 'free_response'::text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_id text NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - importance_score numeric DEFAULT 0 NOT NULL, - multiple_choice_options jsonb, - question text NOT NULL -); - - +create table if not exists + love_questions ( + answer_type text default 'free_response'::text not null, + created_time timestamp with time zone default now() not null, + creator_id text not null, + id bigint primary key generated always as identity not null, + importance_score numeric default 0 not null, + multiple_choice_options jsonb, + question text not null + ); -- Row Level Security -ALTER TABLE love_questions ENABLE ROW LEVEL SECURITY; +alter table love_questions enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON love_questions; -CREATE POLICY "public read" ON love_questions FOR ALL USING (true) ; +drop policy if exists "public read" on love_questions; + +create policy "public read" on love_questions for all using (true); -- Indexes -DROP INDEX IF EXISTS love_questions_pkey; -CREATE UNIQUE INDEX love_questions_pkey ON public.love_questions USING btree (id); +drop index if exists love_questions_pkey; +create unique index love_questions_pkey on public.love_questions using btree (id); diff --git a/backend/supabase/love_ships.sql b/backend/supabase/love_ships.sql index ed1a93614f..1d43ff29ca 100644 --- a/backend/supabase/love_ships.sql +++ b/backend/supabase/love_ships.sql @@ -1,27 +1,33 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS love_ships ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_id text NOT NULL, - ship_id text DEFAULT random_alphanumeric(12) NOT NULL, - target1_id text NOT NULL, - target2_id text NOT NULL, - CONSTRAINT PRIMARY KEY (creator_id, ship_id) -); - - +create table if not exists + love_ships ( + created_time timestamp with time zone default now() not null, + creator_id text not null, + ship_id text default random_alphanumeric (12) not null, + target1_id text not null, + target2_id text not null, + constraint primary key (creator_id, ship_id) + ); -- Row Level Security -ALTER TABLE love_ships ENABLE ROW LEVEL SECURITY; +alter table love_ships enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON love_ships; -CREATE POLICY "public read" ON love_ships FOR SELECT USING (true) ; +drop policy if exists "public read" on love_ships; + +create policy "public read" on love_ships for +select + using (true); -- Indexes -DROP INDEX IF EXISTS love_ships_pkey; -CREATE UNIQUE INDEX love_ships_pkey ON public.love_ships USING btree (creator_id, ship_id); -DROP INDEX IF EXISTS love_ships_target1_id; -CREATE INDEX love_ships_target1_id ON public.love_ships USING btree (target1_id); -DROP INDEX IF EXISTS love_ships_target2_id; -CREATE INDEX love_ships_target2_id ON public.love_ships USING btree (target2_id); +drop index if exists love_ships_pkey; + +create unique index love_ships_pkey on public.love_ships using btree (creator_id, ship_id); + +drop index if exists love_ships_target1_id; + +create index love_ships_target1_id on public.love_ships using btree (target1_id); + +drop index if exists love_ships_target2_id; +create index love_ships_target2_id on public.love_ships using btree (target2_id); diff --git a/backend/supabase/love_stars.sql b/backend/supabase/love_stars.sql index e2431de627..e87db943f8 100644 --- a/backend/supabase/love_stars.sql +++ b/backend/supabase/love_stars.sql @@ -1,22 +1,24 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS love_stars ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_id text NOT NULL, - star_id text DEFAULT random_alphanumeric(12) NOT NULL, - target_id text NOT NULL, - CONSTRAINT PRIMARY KEY (creator_id, star_id) -); - - +create table if not exists + love_stars ( + created_time timestamp with time zone default now() not null, + creator_id text not null, + star_id text default random_alphanumeric (12) not null, + target_id text not null, + constraint primary key (creator_id, star_id) + ); -- Row Level Security -ALTER TABLE love_stars ENABLE ROW LEVEL SECURITY; +alter table love_stars enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON love_stars; -CREATE POLICY "public read" ON love_stars FOR SELECT USING (true) ; +drop policy if exists "public read" on love_stars; + +create policy "public read" on love_stars for +select + using (true); -- Indexes -DROP INDEX IF EXISTS love_stars_pkey; -CREATE UNIQUE INDEX love_stars_pkey ON public.love_stars USING btree (creator_id, star_id); +drop index if exists love_stars_pkey; +create unique index love_stars_pkey on public.love_stars using btree (creator_id, star_id); diff --git a/backend/supabase/love_waitlist.sql b/backend/supabase/love_waitlist.sql index cfc1e31e5d..2ad884b33b 100644 --- a/backend/supabase/love_waitlist.sql +++ b/backend/supabase/love_waitlist.sql @@ -1,20 +1,22 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS love_waitlist ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - email text NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL -); - - +create table if not exists + love_waitlist ( + created_time timestamp with time zone default now() not null, + email text not null, + id bigint primary key generated always as identity not null + ); -- Row Level Security -ALTER TABLE love_waitlist ENABLE ROW LEVEL SECURITY; +alter table love_waitlist enable row level security; + -- Policies -DROP POLICY IF EXISTS "anon insert" ON love_waitlist; -CREATE POLICY "anon insert" ON love_waitlist FOR INSERT WITH CHECK (true); +drop policy if exists "anon insert" on love_waitlist; + +create policy "anon insert" on love_waitlist for insert +with + check (true); -- Indexes -DROP INDEX IF EXISTS love_waitlist_pkey; -CREATE UNIQUE INDEX love_waitlist_pkey ON public.love_waitlist USING btree (id); +drop index if exists love_waitlist_pkey; +create unique index love_waitlist_pkey on public.love_waitlist using btree (id); diff --git a/backend/supabase/lover_comments.sql b/backend/supabase/lover_comments.sql index f8ee27d589..461d913a76 100644 --- a/backend/supabase/lover_comments.sql +++ b/backend/supabase/lover_comments.sql @@ -1,29 +1,31 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS lover_comments ( - content jsonb NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - hidden boolean DEFAULT false NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - on_user_id text NOT NULL, - reply_to_comment_id bigint, - user_avatar_url text NOT NULL, - user_id text NOT NULL, - user_name text NOT NULL, - user_username text NOT NULL -); - - +create table if not exists + lover_comments ( + content jsonb not null, + created_time timestamp with time zone default now() not null, + hidden boolean default false not null, + id bigint primary key generated always as identity not null, + on_user_id text not null, + reply_to_comment_id bigint, + user_avatar_url text not null, + user_id text not null, + user_name text not null, + user_username text not null + ); -- Row Level Security -ALTER TABLE lover_comments ENABLE ROW LEVEL SECURITY; +alter table lover_comments enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON lover_comments; -CREATE POLICY "public read" ON lover_comments FOR ALL USING (true) ; +drop policy if exists "public read" on lover_comments; + +create policy "public read" on lover_comments for all using (true); -- Indexes -DROP INDEX IF EXISTS lover_comments_pkey; -CREATE UNIQUE INDEX lover_comments_pkey ON public.lover_comments USING btree (id); -DROP INDEX IF EXISTS lover_comments_user_id_idx; -CREATE INDEX lover_comments_user_id_idx ON public.lover_comments USING btree (on_user_id); +drop index if exists lover_comments_pkey; + +create unique index lover_comments_pkey on public.lover_comments using btree (id); + +drop index if exists lover_comments_user_id_idx; +create index lover_comments_user_id_idx on public.lover_comments using btree (on_user_id); diff --git a/backend/supabase/lovers.sql b/backend/supabase/lovers.sql index 79767c5ec8..60df151e70 100644 --- a/backend/supabase/lovers.sql +++ b/backend/supabase/lovers.sql @@ -1,66 +1,76 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + lovers ( + age integer default 18 not null, + bio json, + born_in_location text, + city text not null, + city_latitude numeric(9, 6), + city_longitude numeric(9, 6), + comments_enabled boolean default true not null, + company text, + country text, + created_time timestamp with time zone default now() not null, + drinks_per_month integer, + education_level text, + ethnicity text[], + gender text not null, + geodb_city_id text, + has_kids integer, + height_in_inches integer, + id bigint primary key generated always as identity not null, + is_smoker boolean, + is_vegetarian_or_vegan boolean, + last_online_time timestamp with time zone default now() not null, + looking_for_matches boolean default true not null, + messaging_status text default 'open'::text not null, + occupation text, + occupation_title text, + photo_urls text[], + pinned_url text, + political_beliefs text[], + pref_age_max integer default 100 not null, + pref_age_min integer default 18 not null, + pref_gender text[] not null, + pref_relation_styles text[] not null, + referred_by_username text, + region_code text, + religious_belief_strength integer, + religious_beliefs text, + twitter text, + university text, + user_id text not null, + visibility text default 'public'::text not null, + wants_kids_strength integer default 0 not null, + website text + ); -CREATE TABLE IF NOT EXISTS lovers ( - age integer DEFAULT 18 NOT NULL, - bio json, - born_in_location text, - city text NOT NULL, - city_latitude numeric(9,6), - city_longitude numeric(9,6), - comments_enabled boolean DEFAULT true NOT NULL, - company text, - country text, - created_time timestamp with time zone DEFAULT now() NOT NULL, - drinks_per_month integer, - education_level text, - ethnicity text[], - gender text NOT NULL, - geodb_city_id text, - has_kids integer, - height_in_inches integer, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - is_smoker boolean, - is_vegetarian_or_vegan boolean, - last_online_time timestamp with time zone DEFAULT now() NOT NULL, - looking_for_matches boolean DEFAULT true NOT NULL, - messaging_status text DEFAULT 'open'::text NOT NULL, - occupation text, - occupation_title text, - photo_urls text[], - pinned_url text, - political_beliefs text[], - pref_age_max integer DEFAULT 100 NOT NULL, - pref_age_min integer DEFAULT 18 NOT NULL, - pref_gender text[] NOT NULL, - pref_relation_styles text[] NOT NULL, - referred_by_username text, - region_code text, - religious_belief_strength integer, - religious_beliefs text, - twitter text, - university text, - user_id text NOT NULL, - visibility text DEFAULT 'public'::text NOT NULL, - wants_kids_strength integer DEFAULT 0 NOT NULL, - website text -); +-- Row Level Security +alter table lovers enable row level security; +-- Policies +drop policy if exists "public read" on lovers; +create policy "public read" on lovers for +select + using (true); --- Row Level Security -ALTER TABLE lovers ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "public read" ON lovers; -CREATE POLICY "public read" ON lovers FOR SELECT USING (true) ; +drop policy if exists "self update" on lovers; -DROP POLICY IF EXISTS "self update" ON lovers; -CREATE POLICY "self update" ON lovers FOR UPDATE WITH CHECK ((user_id = firebase_uid())); +create policy "self update" on lovers +for update +with + check ((user_id = firebase_uid ())); -- Indexes -DROP INDEX IF EXISTS lovers_pkey; -CREATE UNIQUE INDEX lovers_pkey ON public.lovers USING btree (id); -DROP INDEX IF EXISTS lovers_user_id_idx; -CREATE INDEX lovers_user_id_idx ON public.lovers USING btree (user_id); -DROP INDEX IF EXISTS unique_user_id; -CREATE UNIQUE INDEX unique_user_id ON public.lovers USING btree (user_id); +drop index if exists lovers_pkey; + +create unique index lovers_pkey on public.lovers using btree (id); + +drop index if exists lovers_user_id_idx; + +create index lovers_user_id_idx on public.lovers using btree (user_id); + +drop index if exists unique_user_id; +create unique index unique_user_id on public.lovers using btree (user_id); diff --git a/backend/supabase/mana_supply_stats.sql b/backend/supabase/mana_supply_stats.sql index 4f964cfbee..c02734b063 100644 --- a/backend/supabase/mana_supply_stats.sql +++ b/backend/supabase/mana_supply_stats.sql @@ -1,36 +1,38 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS mana_supply_stats ( - amm_cash_liquidity numeric DEFAULT 0 NOT NULL, - amm_liquidity numeric NOT NULL, - balance numeric NOT NULL, - cash_balance numeric DEFAULT 0 NOT NULL, - cash_investment_value numeric DEFAULT 0 NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - end_time timestamp with time zone NOT NULL, - full_investment_value numeric, - full_loan_total numeric, - full_mana_balance numeric, - full_spice_balance numeric, - full_total_mana_value numeric, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - investment_value numeric NOT NULL, - loan_total numeric NOT NULL, - spice_balance numeric NOT NULL, - start_time timestamp with time zone NOT NULL, - total_cash_value numeric DEFAULT 0 NOT NULL, - total_value numeric NOT NULL -); - - +create table if not exists + mana_supply_stats ( + amm_cash_liquidity numeric default 0 not null, + amm_liquidity numeric not null, + balance numeric not null, + cash_balance numeric default 0 not null, + cash_investment_value numeric default 0 not null, + created_time timestamp with time zone default now() not null, + end_time timestamp with time zone not null, + full_investment_value numeric, + full_loan_total numeric, + full_mana_balance numeric, + full_spice_balance numeric, + full_total_mana_value numeric, + id bigint primary key generated always as identity not null, + investment_value numeric not null, + loan_total numeric not null, + spice_balance numeric not null, + start_time timestamp with time zone not null, + total_cash_value numeric default 0 not null, + total_value numeric not null + ); -- Row Level Security -ALTER TABLE mana_supply_stats ENABLE ROW LEVEL SECURITY; +alter table mana_supply_stats enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON mana_supply_stats; -CREATE POLICY "public read" ON mana_supply_stats FOR SELECT USING (true) ; +drop policy if exists "public read" on mana_supply_stats; + +create policy "public read" on mana_supply_stats for +select + using (true); -- Indexes -DROP INDEX IF EXISTS mana_supply_stats_pkey; -CREATE UNIQUE INDEX mana_supply_stats_pkey ON public.mana_supply_stats USING btree (id); +drop index if exists mana_supply_stats_pkey; +create unique index mana_supply_stats_pkey on public.mana_supply_stats using btree (id); diff --git a/backend/supabase/manachan_tweets.sql b/backend/supabase/manachan_tweets.sql index 4a6b07cf58..3799f9fe60 100644 --- a/backend/supabase/manachan_tweets.sql +++ b/backend/supabase/manachan_tweets.sql @@ -1,24 +1,26 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS manachan_tweets ( - cost numeric, - created_time numeric, - id text PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, - tweet text, - tweet_id text, - user_id text, - username text -); - - +create table if not exists + manachan_tweets ( + cost numeric, + created_time numeric, + id text primary key default uuid_generate_v4 () not null, + tweet text, + tweet_id text, + user_id text, + username text + ); -- Row Level Security -ALTER TABLE manachan_tweets ENABLE ROW LEVEL SECURITY; +alter table manachan_tweets enable row level security; + -- Policies -DROP POLICY IF EXISTS "Enable read access for all users" ON manachan_tweets; -CREATE POLICY "Enable read access for all users" ON manachan_tweets FOR SELECT USING (true) ; +drop policy if exists "Enable read access for all users" on manachan_tweets; + +create policy "Enable read access for all users" on manachan_tweets for +select + using (true); -- Indexes -DROP INDEX IF EXISTS manachan_tweets_pkey; -CREATE UNIQUE INDEX manachan_tweets_pkey ON public.manachan_tweets USING btree (id); +drop index if exists manachan_tweets_pkey; +create unique index manachan_tweets_pkey on public.manachan_tweets using btree (id); diff --git a/backend/supabase/manalink_claims.sql b/backend/supabase/manalink_claims.sql index 108f17acbc..c9ff3f484d 100644 --- a/backend/supabase/manalink_claims.sql +++ b/backend/supabase/manalink_claims.sql @@ -1,20 +1,22 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS manalink_claims ( - manalink_id text NOT NULL, - txn_id text NOT NULL, - CONSTRAINT PRIMARY KEY (manalink_id, txn_id) -); - - +create table if not exists + manalink_claims ( + manalink_id text not null, + txn_id text not null, + constraint primary key (manalink_id, txn_id) + ); -- Row Level Security -ALTER TABLE manalink_claims ENABLE ROW LEVEL SECURITY; +alter table manalink_claims enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON manalink_claims; -CREATE POLICY "public read" ON manalink_claims FOR SELECT USING (true) ; +drop policy if exists "public read" on manalink_claims; + +create policy "public read" on manalink_claims for +select + using (true); -- Indexes -DROP INDEX IF EXISTS manalink_claims_pkey; -CREATE UNIQUE INDEX manalink_claims_pkey ON public.manalink_claims USING btree (manalink_id, txn_id); +drop index if exists manalink_claims_pkey; +create unique index manalink_claims_pkey on public.manalink_claims using btree (manalink_id, txn_id); diff --git a/backend/supabase/manalinks.sql b/backend/supabase/manalinks.sql index e927e3bc63..00d5dc612d 100644 --- a/backend/supabase/manalinks.sql +++ b/backend/supabase/manalinks.sql @@ -1,26 +1,30 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS manalinks ( - amount numeric NOT NULL, - created_time timestamp with time zone DEFAULT now(), - creator_id text NOT NULL, - expires_time timestamp with time zone, - id text PRIMARY KEY DEFAULT random_alphanumeric(8) NOT NULL, - max_uses numeric, - message text -); - - +create table if not exists + manalinks ( + amount numeric not null, + created_time timestamp with time zone default now(), + creator_id text not null, + expires_time timestamp with time zone, + id text primary key default random_alphanumeric (8) not null, + max_uses numeric, + message text + ); -- Row Level Security -ALTER TABLE manalinks ENABLE ROW LEVEL SECURITY; +alter table manalinks enable row level security; + -- Policies -DROP POLICY IF EXISTS "Enable read access for admin" ON manalinks; -CREATE POLICY "Enable read access for admin" ON manalinks FOR SELECT TO service_role USING (true) ; +drop policy if exists "Enable read access for admin" on manalinks; + +create policy "Enable read access for admin" on manalinks for +select + to service_role using (true); -- Indexes -DROP INDEX IF EXISTS manalinks_creator_id; -CREATE INDEX manalinks_creator_id ON public.manalinks USING btree (creator_id); -DROP INDEX IF EXISTS manalinks_pkey; -CREATE UNIQUE INDEX manalinks_pkey ON public.manalinks USING btree (id); +drop index if exists manalinks_creator_id; + +create index manalinks_creator_id on public.manalinks using btree (creator_id); + +drop index if exists manalinks_pkey; +create unique index manalinks_pkey on public.manalinks using btree (id); diff --git a/backend/supabase/market_ads.sql b/backend/supabase/market_ads.sql index a1d3b9b6e0..dafe897ae9 100644 --- a/backend/supabase/market_ads.sql +++ b/backend/supabase/market_ads.sql @@ -1,31 +1,38 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS market_ads ( - cost_per_view numeric NOT NULL, - created_at timestamp without time zone DEFAULT now() NOT NULL, - embedding vector(1536) NOT NULL, - funds numeric NOT NULL, - id text PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, - market_id text NOT NULL, - user_id text NOT NULL -); +create table if not exists + market_ads ( + cost_per_view numeric not null, + created_at timestamp without time zone default now() not null, + embedding vector (1536) not null, + funds numeric not null, + id text primary key default uuid_generate_v4 () not null, + market_id text not null, + user_id text not null + ); -- Foreign Keys -ALTER TABLE market_ads ADD CONSTRAINT market_ads_market_id_fkey FOREIGN KEY (market_id) REFERENCES contracts(id); - +alter table market_ads +add constraint market_ads_market_id_fkey foreign key (market_id) references contracts (id); -- Row Level Security -ALTER TABLE market_ads ENABLE ROW LEVEL SECURITY; +alter table market_ads enable row level security; + -- Policies -DROP POLICY IF EXISTS "admin write access" ON market_ads; -CREATE POLICY "admin write access" ON market_ads FOR ALL TO service_role ; +drop policy if exists "admin write access" on market_ads; + +create policy "admin write access" on market_ads for all to service_role; -DROP POLICY IF EXISTS "public read" ON market_ads; -CREATE POLICY "public read" ON market_ads FOR SELECT USING (true) ; +drop policy if exists "public read" on market_ads; + +create policy "public read" on market_ads for +select + using (true); -- Indexes -DROP INDEX IF EXISTS market_ad_cost; -CREATE INDEX market_ad_cost ON public.market_ads USING btree (cost_per_view DESC); -DROP INDEX IF EXISTS market_ads_pkey; -CREATE UNIQUE INDEX market_ads_pkey ON public.market_ads USING btree (id); +drop index if exists market_ad_cost; + +create index market_ad_cost on public.market_ads using btree (cost_per_view desc); + +drop index if exists market_ads_pkey; +create unique index market_ads_pkey on public.market_ads using btree (id); diff --git a/backend/supabase/mod_reports.sql b/backend/supabase/mod_reports.sql index e1b7656b57..0dce26a16d 100644 --- a/backend/supabase/mod_reports.sql +++ b/backend/supabase/mod_reports.sql @@ -1,18 +1,20 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + mod_reports ( + comment_id text not null, + contract_id text not null, + created_time timestamp with time zone default now() not null, + mod_note text, + report_id serial not null, + status status_type default 'new'::status_type not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS mod_reports ( - comment_id text NOT NULL, - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - mod_note text, - report_id serial NOT NULL, - status status_type DEFAULT 'new'::status_type NOT NULL, - user_id text NOT NULL -); - +-- Indexes +drop index if exists mod_reports_pkey; +create unique index mod_reports_pkey on public.mod_reports using btree (report_id); --- Indexes -DROP INDEX IF EXISTS mod_reports_pkey; -CREATE UNIQUE INDEX mod_reports_pkey ON public.mod_reports USING btree (report_id); +drop index if exists mod_status; +create index mod_status on public.mod_reports using btree (status); diff --git a/backend/supabase/news.sql b/backend/supabase/news.sql index 2dc89071ab..16124deac8 100644 --- a/backend/supabase/news.sql +++ b/backend/supabase/news.sql @@ -1,30 +1,32 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS news ( - author text, - contract_ids text[], - created_time timestamp without time zone DEFAULT now() NOT NULL, - description text, - group_ids text[], - id serial NOT NULL, - image_url text, - published_time timestamp without time zone NOT NULL, - source_id text, - source_name text, - title text NOT NULL, - title_embedding vector(1536) NOT NULL, - url text NOT NULL -); - - +create table if not exists + news ( + author text, + contract_ids text[], + created_time timestamp without time zone default now() not null, + description text, + group_ids text[], + id serial not null, + image_url text, + published_time timestamp without time zone not null, + source_id text, + source_name text, + title text not null, + title_embedding vector (1536) not null, + url text not null + ); -- Row Level Security -ALTER TABLE news ENABLE ROW LEVEL SECURITY; +alter table news enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON news; -CREATE POLICY "public read" ON news FOR SELECT USING (true) ; +drop policy if exists "public read" on news; + +create policy "public read" on news for +select + using (true); -- Indexes -DROP INDEX IF EXISTS news_pkey; -CREATE UNIQUE INDEX news_pkey ON public.news USING btree (id); +drop index if exists news_pkey; +create unique index news_pkey on public.news using btree (id); diff --git a/backend/supabase/old_post_comments.sql b/backend/supabase/old_post_comments.sql index cd0bca75c9..880a977e99 100644 --- a/backend/supabase/old_post_comments.sql +++ b/backend/supabase/old_post_comments.sql @@ -1,42 +1,48 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS old_post_comments ( - comment_id text DEFAULT uuid_generate_v4() NOT NULL, - created_time timestamp with time zone DEFAULT now(), - data jsonb NOT NULL, - fs_updated_time timestamp without time zone, - post_id text NOT NULL, - user_id text, - CONSTRAINT PRIMARY KEY (post_id, comment_id) -); - +create table if not exists + old_post_comments ( + comment_id text default uuid_generate_v4 () not null, + created_time timestamp with time zone default now(), + data jsonb not null, + fs_updated_time timestamp without time zone, + post_id text not null, + user_id text, + constraint primary key (post_id, comment_id) + ); -- Triggers -CREATE TRIGGER post_comment_populate BEFORE INSERT OR UPDATE ON public.old_post_comments FOR EACH ROW EXECUTE FUNCTION post_comment_populate_cols(); +create trigger post_comment_populate before insert +or +update on public.old_post_comments for each row +execute function post_comment_populate_cols (); -- Functions -CREATE OR REPLACE FUNCTION public.post_comment_populate_cols() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ begin +create +or replace function public.post_comment_populate_cols () returns trigger language plpgsql as $function$ begin if new.data is not null then new.visibility := (new.data)->>'visibility'; new.user_id := (new.data)->>'userId'; end if; return new; -end $function$ -; +end $function$; -- Row Level Security -ALTER TABLE old_post_comments ENABLE ROW LEVEL SECURITY; +alter table old_post_comments enable row level security; + -- Policies -DROP POLICY IF EXISTS "auth read" ON old_post_comments; -CREATE POLICY "auth read" ON old_post_comments FOR SELECT TO service_role USING (true) ; +drop policy if exists "auth read" on old_post_comments; + +create policy "auth read" on old_post_comments for +select + to service_role using (true); + +drop policy if exists "user can insert" on old_post_comments; -DROP POLICY IF EXISTS "user can insert" ON old_post_comments; -CREATE POLICY "user can insert" ON old_post_comments FOR INSERT WITH CHECK (true); +create policy "user can insert" on old_post_comments for insert +with + check (true); -- Indexes -DROP INDEX IF EXISTS post_comments_pkey; -CREATE UNIQUE INDEX post_comments_pkey ON public.old_post_comments USING btree (post_id, comment_id); +drop index if exists post_comments_pkey; +create unique index post_comments_pkey on public.old_post_comments using btree (post_id, comment_id); diff --git a/backend/supabase/old_posts.sql b/backend/supabase/old_posts.sql index a75d632dbe..204ef2a73a 100644 --- a/backend/supabase/old_posts.sql +++ b/backend/supabase/old_posts.sql @@ -1,41 +1,46 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS old_posts ( - created_time timestamp with time zone DEFAULT now(), - creator_id text, - data jsonb NOT NULL, - group_id text, - id text PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, - visibility text -); +create table if not exists + old_posts ( + created_time timestamp with time zone default now(), + creator_id text, + data jsonb not null, + group_id text, + id text primary key default uuid_generate_v4 () not null, + visibility text + ); -- Foreign Keys -ALTER TABLE old_posts ADD CONSTRAINT public_old_posts_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON UPDATE CASCADE ON DELETE CASCADE; +alter table old_posts +add constraint public_old_posts_group_id_fkey foreign key (group_id) references groups (id) on update cascade on delete cascade; -- Triggers -CREATE TRIGGER post_populate BEFORE INSERT OR UPDATE ON public.old_posts FOR EACH ROW EXECUTE FUNCTION post_populate_cols(); +create trigger post_populate before insert +or +update on public.old_posts for each row +execute function post_populate_cols (); -- Functions -CREATE OR REPLACE FUNCTION public.post_populate_cols() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ begin +create +or replace function public.post_populate_cols () returns trigger language plpgsql as $function$ begin if new.data is not null then new.visibility := (new.data)->>'visibility'; new.group_id := (new.data)->>'groupId'; new.creator_id := (new.data)->>'creatorId'; end if; return new; -end $function$ -; +end $function$; -- Row Level Security -ALTER TABLE old_posts ENABLE ROW LEVEL SECURITY; +alter table old_posts enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON old_posts; -CREATE POLICY "public read" ON old_posts FOR SELECT USING (true) ; +drop policy if exists "public read" on old_posts; + +create policy "public read" on old_posts for +select + using (true); -- Indexes -DROP INDEX IF EXISTS posts_pkey; -CREATE UNIQUE INDEX posts_pkey ON public.old_posts USING btree (id); +drop index if exists posts_pkey; +create unique index posts_pkey on public.old_posts using btree (id); diff --git a/backend/supabase/platform_calibration.sql b/backend/supabase/platform_calibration.sql index 86a61d60b2..791dd1ea63 100644 --- a/backend/supabase/platform_calibration.sql +++ b/backend/supabase/platform_calibration.sql @@ -1,20 +1,22 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS platform_calibration ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - data jsonb NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL -); - - +create table if not exists + platform_calibration ( + created_time timestamp with time zone default now() not null, + data jsonb not null, + id bigint primary key generated always as identity not null + ); -- Row Level Security -ALTER TABLE platform_calibration ENABLE ROW LEVEL SECURITY; +alter table platform_calibration enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON platform_calibration; -CREATE POLICY "public read" ON platform_calibration FOR SELECT USING (true) ; +drop policy if exists "public read" on platform_calibration; + +create policy "public read" on platform_calibration for +select + using (true); -- Indexes -DROP INDEX IF EXISTS platform_calibration_pkey; -CREATE UNIQUE INDEX platform_calibration_pkey ON public.platform_calibration USING btree (id); +drop index if exists platform_calibration_pkey; +create unique index platform_calibration_pkey on public.platform_calibration using btree (id); diff --git a/backend/supabase/portfolios.sql b/backend/supabase/portfolios.sql index d6cac315f3..15b7f3ff26 100644 --- a/backend/supabase/portfolios.sql +++ b/backend/supabase/portfolios.sql @@ -1,23 +1,25 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS portfolios ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_id text NOT NULL, - id text PRIMARY KEY NOT NULL, - items jsonb NOT NULL, - name text NOT NULL, - slug text NOT NULL -); - - +create table if not exists + portfolios ( + created_time timestamp with time zone default now() not null, + creator_id text not null, + id text primary key not null, + items jsonb not null, + name text not null, + slug text not null + ); -- Row Level Security -ALTER TABLE portfolios ENABLE ROW LEVEL SECURITY; +alter table portfolios enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON portfolios; -CREATE POLICY "public read" ON portfolios FOR SELECT USING (true) ; +drop policy if exists "public read" on portfolios; + +create policy "public read" on portfolios for +select + using (true); -- Indexes -DROP INDEX IF EXISTS portfolios_pkey; -CREATE UNIQUE INDEX portfolios_pkey ON public.portfolios USING btree (id); +drop index if exists portfolios_pkey; +create unique index portfolios_pkey on public.portfolios using btree (id); diff --git a/backend/supabase/posts.sql b/backend/supabase/posts.sql index 0261d2099c..7bcad41cd3 100644 --- a/backend/supabase/posts.sql +++ b/backend/supabase/posts.sql @@ -1,32 +1,40 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS posts ( - bet_id text, - contract_comment_id text, - contract_id text, - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - user_avatar_url text NOT NULL, - user_id text NOT NULL, - user_name text NOT NULL, - user_username text NOT NULL -); - - +create table if not exists + posts ( + bet_id text, + contract_comment_id text, + contract_id text, + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + user_avatar_url text not null, + user_id text not null, + user_name text not null, + user_username text not null + ); -- Row Level Security -ALTER TABLE posts ENABLE ROW LEVEL SECURITY; +alter table posts enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON posts; -CREATE POLICY "public read" ON posts FOR SELECT USING (true) ; +drop policy if exists "public read" on posts; + +create policy "public read" on posts for +select + using (true); -- Indexes -DROP INDEX IF EXISTS posts_pkey1; -CREATE UNIQUE INDEX posts_pkey1 ON public.posts USING btree (id); -DROP INDEX IF EXISTS reposts_contract; -CREATE INDEX reposts_contract ON public.posts USING btree (contract_id); -DROP INDEX IF EXISTS reposts_contract_comment; -CREATE INDEX reposts_contract_comment ON public.posts USING btree (contract_comment_id); -DROP INDEX IF EXISTS reposts_user; -CREATE INDEX reposts_user ON public.posts USING btree (user_id); +drop index if exists posts_pkey1; + +create unique index posts_pkey1 on public.posts using btree (id); + +drop index if exists reposts_contract; + +create index reposts_contract on public.posts using btree (contract_id); + +drop index if exists reposts_contract_comment; + +create index reposts_contract_comment on public.posts using btree (contract_comment_id); + +drop index if exists reposts_user; +create index reposts_user on public.posts using btree (user_id); diff --git a/backend/supabase/private_user_message_channel_members.sql b/backend/supabase/private_user_message_channel_members.sql index 15eae3ca91..b5838a4170 100644 --- a/backend/supabase/private_user_message_channel_members.sql +++ b/backend/supabase/private_user_message_channel_members.sql @@ -1,24 +1,27 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + private_user_message_channel_members ( + channel_id bigint not null, + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + notify_after_time timestamp with time zone default now() not null, + role text default 'member'::text not null, + status text default 'proposed'::text not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS private_user_message_channel_members ( - channel_id bigint NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - notify_after_time timestamp with time zone DEFAULT now() NOT NULL, - role text DEFAULT 'member'::text NOT NULL, - status text DEFAULT 'proposed'::text NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table private_user_message_channel_members enable row level security; +-- Indexes +drop index if exists private_user_message_channel_members_pkey; +create unique index private_user_message_channel_members_pkey on public.private_user_message_channel_members using btree (id); --- Row Level Security -ALTER TABLE private_user_message_channel_members ENABLE ROW LEVEL SECURITY; --- Indexes -DROP INDEX IF EXISTS private_user_message_channel_members_pkey; -CREATE UNIQUE INDEX private_user_message_channel_members_pkey ON public.private_user_message_channel_members USING btree (id); -DROP INDEX IF EXISTS pumcm_members_idx; -CREATE INDEX pumcm_members_idx ON public.private_user_message_channel_members USING btree (channel_id, user_id); -DROP INDEX IF EXISTS unique_user_channel; -CREATE UNIQUE INDEX unique_user_channel ON public.private_user_message_channel_members USING btree (channel_id, user_id); +drop index if exists pumcm_members_idx; + +create index pumcm_members_idx on public.private_user_message_channel_members using btree (channel_id, user_id); + +drop index if exists unique_user_channel; +create unique index unique_user_channel on public.private_user_message_channel_members using btree (channel_id, user_id); diff --git a/backend/supabase/private_user_message_channels.sql b/backend/supabase/private_user_message_channels.sql index 5270c1b8d1..075a658e1b 100644 --- a/backend/supabase/private_user_message_channels.sql +++ b/backend/supabase/private_user_message_channels.sql @@ -1,21 +1,21 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS private_user_message_channels ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - last_updated_time timestamp with time zone DEFAULT now() NOT NULL, - title text -); - - +create table if not exists + private_user_message_channels ( + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + last_updated_time timestamp with time zone default now() not null, + title text + ); -- Row Level Security -ALTER TABLE private_user_message_channels ENABLE ROW LEVEL SECURITY; +alter table private_user_message_channels enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON private_user_message_channels; -CREATE POLICY "public read" ON private_user_message_channels FOR ALL USING (true) ; +drop policy if exists "public read" on private_user_message_channels; + +create policy "public read" on private_user_message_channels for all using (true); -- Indexes -DROP INDEX IF EXISTS private_user_message_channels_pkey; -CREATE UNIQUE INDEX private_user_message_channels_pkey ON public.private_user_message_channels USING btree (id); +drop index if exists private_user_message_channels_pkey; +create unique index private_user_message_channels_pkey on public.private_user_message_channels using btree (id); diff --git a/backend/supabase/private_user_messages.sql b/backend/supabase/private_user_messages.sql index 6985d1f5f5..fd997d8e53 100644 --- a/backend/supabase/private_user_messages.sql +++ b/backend/supabase/private_user_messages.sql @@ -1,21 +1,22 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + private_user_messages ( + channel_id bigint not null, + content jsonb not null, + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + user_id text not null, + visibility text default 'private'::text not null + ); -CREATE TABLE IF NOT EXISTS private_user_messages ( - channel_id bigint NOT NULL, - content jsonb NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - user_id text NOT NULL, - visibility text DEFAULT 'private'::text NOT NULL -); +-- Row Level Security +alter table private_user_messages enable row level security; +-- Indexes +drop index if exists private_user_messages_channel_id_idx; +create index private_user_messages_channel_id_idx on public.private_user_messages using btree (channel_id, created_time desc); --- Row Level Security -ALTER TABLE private_user_messages ENABLE ROW LEVEL SECURITY; --- Indexes -DROP INDEX IF EXISTS private_user_messages_channel_id_idx; -CREATE INDEX private_user_messages_channel_id_idx ON public.private_user_messages USING btree (channel_id, created_time DESC); -DROP INDEX IF EXISTS private_user_messages_pkey; -CREATE UNIQUE INDEX private_user_messages_pkey ON public.private_user_messages USING btree (id); +drop index if exists private_user_messages_pkey; +create unique index private_user_messages_pkey on public.private_user_messages using btree (id); diff --git a/backend/supabase/private_user_phone_numbers.sql b/backend/supabase/private_user_phone_numbers.sql index 117fed724e..03003c1bf3 100644 --- a/backend/supabase/private_user_phone_numbers.sql +++ b/backend/supabase/private_user_phone_numbers.sql @@ -1,22 +1,25 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + private_user_phone_numbers ( + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + last_updated_time timestamp with time zone default now() not null, + phone_number text not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS private_user_phone_numbers ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - last_updated_time timestamp with time zone DEFAULT now() NOT NULL, - phone_number text NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table private_user_phone_numbers enable row level security; +-- Indexes +drop index if exists private_user_phone_numbers_pkey; +create unique index private_user_phone_numbers_pkey on public.private_user_phone_numbers using btree (id); --- Row Level Security -ALTER TABLE private_user_phone_numbers ENABLE ROW LEVEL SECURITY; --- Indexes -DROP INDEX IF EXISTS private_user_phone_numbers_pkey; -CREATE UNIQUE INDEX private_user_phone_numbers_pkey ON public.private_user_phone_numbers USING btree (id); -DROP INDEX IF EXISTS unique_phone_number_user_id; -CREATE UNIQUE INDEX unique_phone_number_user_id ON public.private_user_phone_numbers USING btree (user_id); -DROP INDEX IF EXISTS unique_user_phone_number; -CREATE UNIQUE INDEX unique_user_phone_number ON public.private_user_phone_numbers USING btree (phone_number); +drop index if exists unique_phone_number_user_id; + +create unique index unique_phone_number_user_id on public.private_user_phone_numbers using btree (user_id); + +drop index if exists unique_user_phone_number; +create unique index unique_user_phone_number on public.private_user_phone_numbers using btree (phone_number); diff --git a/backend/supabase/private_user_seen_message_channels.sql b/backend/supabase/private_user_seen_message_channels.sql index 95e70ac552..41d63df861 100644 --- a/backend/supabase/private_user_seen_message_channels.sql +++ b/backend/supabase/private_user_seen_message_channels.sql @@ -1,26 +1,43 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + private_user_seen_message_channels ( + channel_id bigint not null, + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS private_user_seen_message_channels ( - channel_id bigint NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table private_user_seen_message_channels enable row level security; +-- Policies +drop policy if exists "private member insert" on private_user_seen_message_channels; +create policy "private member insert" on private_user_seen_message_channels for insert +with + check ( + ( + (firebase_uid () is not null) + and can_access_private_messages (channel_id, firebase_uid ()) + ) + ); --- Row Level Security -ALTER TABLE private_user_seen_message_channels ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "private member insert" ON private_user_seen_message_channels; -CREATE POLICY "private member insert" ON private_user_seen_message_channels FOR INSERT WITH CHECK (((firebase_uid() IS NOT NULL) AND can_access_private_messages(channel_id, firebase_uid()))); +drop policy if exists "private member read" on private_user_seen_message_channels; -DROP POLICY IF EXISTS "private member read" ON private_user_seen_message_channels; -CREATE POLICY "private member read" ON private_user_seen_message_channels FOR SELECT USING (((firebase_uid() IS NOT NULL) AND can_access_private_messages(channel_id, firebase_uid()))) ; +create policy "private member read" on private_user_seen_message_channels for +select + using ( + ( + (firebase_uid () is not null) + and can_access_private_messages (channel_id, firebase_uid ()) + ) + ); -- Indexes -DROP INDEX IF EXISTS private_user_seen_message_channels_pkey; -CREATE UNIQUE INDEX private_user_seen_message_channels_pkey ON public.private_user_seen_message_channels USING btree (id); -DROP INDEX IF EXISTS user_seen_private_messages_created_time_desc_idx; -CREATE INDEX user_seen_private_messages_created_time_desc_idx ON public.private_user_seen_message_channels USING btree (user_id, channel_id, created_time DESC); +drop index if exists private_user_seen_message_channels_pkey; + +create unique index private_user_seen_message_channels_pkey on public.private_user_seen_message_channels using btree (id); + +drop index if exists user_seen_private_messages_created_time_desc_idx; +create index user_seen_private_messages_created_time_desc_idx on public.private_user_seen_message_channels using btree (user_id, channel_id, created_time desc); diff --git a/backend/supabase/private_users.sql b/backend/supabase/private_users.sql index 5b9254b3d4..cf982dcbfa 100644 --- a/backend/supabase/private_users.sql +++ b/backend/supabase/private_users.sql @@ -1,23 +1,27 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS private_users ( - data jsonb NOT NULL, - id text PRIMARY KEY NOT NULL, - weekly_portfolio_email_sent boolean DEFAULT false, - weekly_trending_email_sent boolean DEFAULT false -); - - +create table if not exists + private_users ( + data jsonb not null, + id text primary key not null, + weekly_portfolio_email_sent boolean default false, + weekly_trending_email_sent boolean default false + ); -- Row Level Security -ALTER TABLE private_users ENABLE ROW LEVEL SECURITY; +alter table private_users enable row level security; + -- Policies -DROP POLICY IF EXISTS "private read" ON private_users; -CREATE POLICY "private read" ON private_users FOR SELECT USING ((firebase_uid() = id)) ; +drop policy if exists "private read" on private_users; + +create policy "private read" on private_users for +select + using ((firebase_uid () = id)); -- Indexes -DROP INDEX IF EXISTS private_users_data_api_key; -CREATE INDEX private_users_data_api_key ON public.private_users USING btree (((data ->> 'apiKey'::text))); -DROP INDEX IF EXISTS private_users_pkey; -CREATE UNIQUE INDEX private_users_pkey ON public.private_users USING btree (id); +drop index if exists private_users_data_api_key; + +create index private_users_data_api_key on public.private_users using btree (((data ->> 'apiKey'::text))); + +drop index if exists private_users_pkey; +create unique index private_users_pkey on public.private_users using btree (id); diff --git a/backend/supabase/push_notification_tickets.sql b/backend/supabase/push_notification_tickets.sql index 9377edda78..b94b9a9dda 100644 --- a/backend/supabase/push_notification_tickets.sql +++ b/backend/supabase/push_notification_tickets.sql @@ -1,22 +1,23 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + push_notification_tickets ( + created_time timestamp with time zone default now() not null, + id text primary key not null, + notification_id text not null, + receipt_error text, + receipt_status text not null, + status text not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS push_notification_tickets ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - id text PRIMARY KEY NOT NULL, - notification_id text NOT NULL, - receipt_error text, - receipt_status text NOT NULL, - status text NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table push_notification_tickets enable row level security; +-- Indexes +drop index if exists push_notification_tickets_pkey; +create unique index push_notification_tickets_pkey on public.push_notification_tickets using btree (id); --- Row Level Security -ALTER TABLE push_notification_tickets ENABLE ROW LEVEL SECURITY; --- Indexes -DROP INDEX IF EXISTS push_notification_tickets_pkey; -CREATE UNIQUE INDEX push_notification_tickets_pkey ON public.push_notification_tickets USING btree (id); -DROP INDEX IF EXISTS push_notification_tickets_status; -CREATE INDEX push_notification_tickets_status ON public.push_notification_tickets USING btree (receipt_status); +drop index if exists push_notification_tickets_status; +create index push_notification_tickets_status on public.push_notification_tickets using btree (receipt_status); diff --git a/backend/supabase/q_and_a.sql b/backend/supabase/q_and_a.sql index 005827b37e..0cbe70a361 100644 --- a/backend/supabase/q_and_a.sql +++ b/backend/supabase/q_and_a.sql @@ -1,24 +1,26 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS q_and_a ( - bounty numeric NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - deleted boolean DEFAULT false NOT NULL, - description text NOT NULL, - id text PRIMARY KEY NOT NULL, - question text NOT NULL, - user_id text NOT NULL -); - - +create table if not exists + q_and_a ( + bounty numeric not null, + created_time timestamp with time zone default now() not null, + deleted boolean default false not null, + description text not null, + id text primary key not null, + question text not null, + user_id text not null + ); -- Row Level Security -ALTER TABLE q_and_a ENABLE ROW LEVEL SECURITY; +alter table q_and_a enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON q_and_a; -CREATE POLICY "public read" ON q_and_a FOR SELECT USING (true) ; +drop policy if exists "public read" on q_and_a; + +create policy "public read" on q_and_a for +select + using (true); -- Indexes -DROP INDEX IF EXISTS q_and_a_pkey; -CREATE UNIQUE INDEX q_and_a_pkey ON public.q_and_a USING btree (id); +drop index if exists q_and_a_pkey; +create unique index q_and_a_pkey on public.q_and_a using btree (id); diff --git a/backend/supabase/q_and_a_answers.sql b/backend/supabase/q_and_a_answers.sql index 8e0504b542..c6a2b53d65 100644 --- a/backend/supabase/q_and_a_answers.sql +++ b/backend/supabase/q_and_a_answers.sql @@ -1,24 +1,26 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS q_and_a_answers ( - award numeric DEFAULT 0.0 NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - deleted boolean DEFAULT false NOT NULL, - id text PRIMARY KEY NOT NULL, - q_and_a_id text NOT NULL, - text text NOT NULL, - user_id text NOT NULL -); - - +create table if not exists + q_and_a_answers ( + award numeric default 0.0 not null, + created_time timestamp with time zone default now() not null, + deleted boolean default false not null, + id text primary key not null, + q_and_a_id text not null, + text text not null, + user_id text not null + ); -- Row Level Security -ALTER TABLE q_and_a_answers ENABLE ROW LEVEL SECURITY; +alter table q_and_a_answers enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON q_and_a_answers; -CREATE POLICY "public read" ON q_and_a_answers FOR SELECT USING (true) ; +drop policy if exists "public read" on q_and_a_answers; + +create policy "public read" on q_and_a_answers for +select + using (true); -- Indexes -DROP INDEX IF EXISTS q_and_a_answers_pkey; -CREATE UNIQUE INDEX q_and_a_answers_pkey ON public.q_and_a_answers USING btree (id); +drop index if exists q_and_a_answers_pkey; +create unique index q_and_a_answers_pkey on public.q_and_a_answers using btree (id); diff --git a/backend/supabase/redemption_status.sql b/backend/supabase/redemption_status.sql index c700d3f2b8..3beaebfa3e 100644 --- a/backend/supabase/redemption_status.sql +++ b/backend/supabase/redemption_status.sql @@ -1,22 +1,23 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS redemption_status ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - session_id text NOT NULL, - status text NOT NULL, - transaction_id text NOT NULL, - txn_id text NOT NULL, - user_id text NOT NULL -); +create table if not exists + redemption_status ( + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + session_id text not null, + status text not null, + transaction_id text not null, + txn_id text not null, + user_id text not null + ); -- Foreign Keys -ALTER TABLE redemption_status ADD CONSTRAINT redemption_status_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); - +alter table redemption_status +add constraint redemption_status_user_id_fkey foreign key (user_id) references users (id); -- Row Level Security -ALTER TABLE redemption_status ENABLE ROW LEVEL SECURITY; +alter table redemption_status enable row level security; + -- Indexes -DROP INDEX IF EXISTS redemption_status_pkey; -CREATE UNIQUE INDEX redemption_status_pkey ON public.redemption_status USING btree (id); +drop index if exists redemption_status_pkey; +create unique index redemption_status_pkey on public.redemption_status using btree (id); diff --git a/backend/supabase/reports.sql b/backend/supabase/reports.sql index 524b392754..ccf0430b75 100644 --- a/backend/supabase/reports.sql +++ b/backend/supabase/reports.sql @@ -1,20 +1,20 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS reports ( - content_id text NOT NULL, - content_owner_id text NOT NULL, - content_type text NOT NULL, - created_time timestamp with time zone DEFAULT now(), - description text, - id text DEFAULT uuid_generate_v4() NOT NULL, - parent_id text, - parent_type text, - user_id text NOT NULL -); +create table if not exists + reports ( + content_id text not null, + content_owner_id text not null, + content_type text not null, + created_time timestamp with time zone default now(), + description text, + id text default uuid_generate_v4 () not null, + parent_id text, + parent_type text, + user_id text not null + ); -- Foreign Keys -ALTER TABLE reports ADD CONSTRAINT reports_content_owner_id_fkey FOREIGN KEY (content_owner_id) REFERENCES users(id); -ALTER TABLE reports ADD CONSTRAINT reports_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); - - +alter table reports +add constraint reports_content_owner_id_fkey foreign key (content_owner_id) references users (id); +alter table reports +add constraint reports_user_id_fkey foreign key (user_id) references users (id); diff --git a/backend/supabase/reviews.sql b/backend/supabase/reviews.sql index 9b1a56ecc0..08ffdf88eb 100644 --- a/backend/supabase/reviews.sql +++ b/backend/supabase/reviews.sql @@ -1,18 +1,16 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS reviews ( - content jsonb, - created_time timestamp with time zone DEFAULT now() NOT NULL, - market_id text NOT NULL, - rating numeric NOT NULL, - reviewer_id text NOT NULL, - vendor_id text NOT NULL, - CONSTRAINT PRIMARY KEY (reviewer_id, market_id) -); - - +create table if not exists + reviews ( + content jsonb, + created_time timestamp with time zone default now() not null, + market_id text not null, + rating numeric not null, + reviewer_id text not null, + vendor_id text not null, + constraint primary key (reviewer_id, market_id) + ); -- Indexes -DROP INDEX IF EXISTS reviews_pkey; -CREATE UNIQUE INDEX reviews_pkey ON public.reviews USING btree (reviewer_id, market_id); +drop index if exists reviews_pkey; +create unique index reviews_pkey on public.reviews using btree (reviewer_id, market_id); diff --git a/backend/supabase/scheduler_info.sql b/backend/supabase/scheduler_info.sql index 33ddc26ef7..a8d6d313d9 100644 --- a/backend/supabase/scheduler_info.sql +++ b/backend/supabase/scheduler_info.sql @@ -1,24 +1,26 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS scheduler_info ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - job_name text NOT NULL, - last_end_time timestamp with time zone, - last_start_time timestamp with time zone -); - - +create table if not exists + scheduler_info ( + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + job_name text not null, + last_end_time timestamp with time zone, + last_start_time timestamp with time zone + ); -- Row Level Security -ALTER TABLE scheduler_info ENABLE ROW LEVEL SECURITY; +alter table scheduler_info enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON scheduler_info; -CREATE POLICY "public read" ON scheduler_info FOR ALL USING (true) ; +drop policy if exists "public read" on scheduler_info; + +create policy "public read" on scheduler_info for all using (true); -- Indexes -DROP INDEX IF EXISTS scheduler_info_job_name_key; -CREATE UNIQUE INDEX scheduler_info_job_name_key ON public.scheduler_info USING btree (job_name); -DROP INDEX IF EXISTS scheduler_info_pkey; -CREATE UNIQUE INDEX scheduler_info_pkey ON public.scheduler_info USING btree (id); +drop index if exists scheduler_info_job_name_key; + +create unique index scheduler_info_job_name_key on public.scheduler_info using btree (job_name); + +drop index if exists scheduler_info_pkey; +create unique index scheduler_info_pkey on public.scheduler_info using btree (id); diff --git a/backend/supabase/sent_emails.sql b/backend/supabase/sent_emails.sql index 91023e2a75..97bdde3ab2 100644 --- a/backend/supabase/sent_emails.sql +++ b/backend/supabase/sent_emails.sql @@ -1,19 +1,20 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + sent_emails ( + created_time timestamp with time zone default now() not null, + email_template_id text not null, + id bigint primary key generated always as identity not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS sent_emails ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - email_template_id text NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table sent_emails enable row level security; +-- Indexes +drop index if exists one_time_emails_user_id; +create index one_time_emails_user_id on public.sent_emails using btree (user_id, email_template_id); --- Row Level Security -ALTER TABLE sent_emails ENABLE ROW LEVEL SECURITY; --- Indexes -DROP INDEX IF EXISTS one_time_emails_user_id; -CREATE INDEX one_time_emails_user_id ON public.sent_emails USING btree (user_id, email_template_id); -DROP INDEX IF EXISTS sent_emails_pkey; -CREATE UNIQUE INDEX sent_emails_pkey ON public.sent_emails USING btree (id); +drop index if exists sent_emails_pkey; +create unique index sent_emails_pkey on public.sent_emails using btree (id); diff --git a/backend/supabase/stats.sql b/backend/supabase/stats.sql index 328f36adc4..d427c7346f 100644 --- a/backend/supabase/stats.sql +++ b/backend/supabase/stats.sql @@ -1,19 +1,21 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS stats ( - daily_values numeric[], - title text PRIMARY KEY NOT NULL -); - - +create table if not exists + stats ( + daily_values numeric[], + title text primary key not null + ); -- Row Level Security -ALTER TABLE stats ENABLE ROW LEVEL SECURITY; +alter table stats enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON stats; -CREATE POLICY "public read" ON stats FOR SELECT USING (true) ; +drop policy if exists "public read" on stats; + +create policy "public read" on stats for +select + using (true); -- Indexes -DROP INDEX IF EXISTS stats_pkey; -CREATE UNIQUE INDEX stats_pkey ON public.stats USING btree (title); +drop index if exists stats_pkey; +create unique index stats_pkey on public.stats using btree (title); diff --git a/backend/supabase/system_trading_status.sql b/backend/supabase/system_trading_status.sql index a508e9ec1a..69b1d07ab5 100644 --- a/backend/supabase/system_trading_status.sql +++ b/backend/supabase/system_trading_status.sql @@ -1,19 +1,21 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS system_trading_status ( - status boolean NOT NULL, - token text PRIMARY KEY NOT NULL -); - - +create table if not exists + system_trading_status ( + status boolean not null, + token text primary key not null + ); -- Row Level Security -ALTER TABLE system_trading_status ENABLE ROW LEVEL SECURITY; +alter table system_trading_status enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON system_trading_status; -CREATE POLICY "public read" ON system_trading_status FOR SELECT USING (true) ; +drop policy if exists "public read" on system_trading_status; + +create policy "public read" on system_trading_status for +select + using (true); -- Indexes -DROP INDEX IF EXISTS system_trading_status_pkey; -CREATE UNIQUE INDEX system_trading_status_pkey ON public.system_trading_status USING btree (token); +drop index if exists system_trading_status_pkey; +create unique index system_trading_status_pkey on public.system_trading_status using btree (token); diff --git a/backend/supabase/topic_embeddings.sql b/backend/supabase/topic_embeddings.sql index fd8a400396..4ea543065c 100644 --- a/backend/supabase/topic_embeddings.sql +++ b/backend/supabase/topic_embeddings.sql @@ -1,23 +1,26 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + topic_embeddings ( + created_at timestamp without time zone default now() not null, + embedding vector (1536) not null, + topic text primary key not null + ); -CREATE TABLE IF NOT EXISTS topic_embeddings ( - created_at timestamp without time zone DEFAULT now() NOT NULL, - embedding vector(1536) NOT NULL, - topic text PRIMARY KEY NOT NULL -); +-- Row Level Security +alter table topic_embeddings enable row level security; +-- Policies +drop policy if exists "admin write access" on topic_embeddings; +create policy "admin write access" on topic_embeddings for all to service_role; --- Row Level Security -ALTER TABLE topic_embeddings ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "admin write access" ON topic_embeddings; -CREATE POLICY "admin write access" ON topic_embeddings FOR ALL TO service_role ; +drop policy if exists "public read" on topic_embeddings; -DROP POLICY IF EXISTS "public read" ON topic_embeddings; -CREATE POLICY "public read" ON topic_embeddings FOR SELECT USING (true) ; +create policy "public read" on topic_embeddings for +select + using (true); -- Indexes -DROP INDEX IF EXISTS topic_embeddings_pkey; -CREATE UNIQUE INDEX topic_embeddings_pkey ON public.topic_embeddings USING btree (topic); +drop index if exists topic_embeddings_pkey; +create unique index topic_embeddings_pkey on public.topic_embeddings using btree (topic); diff --git a/backend/supabase/tv_schedule.sql b/backend/supabase/tv_schedule.sql index c2d08e4626..c0820b3d2e 100644 --- a/backend/supabase/tv_schedule.sql +++ b/backend/supabase/tv_schedule.sql @@ -1,21 +1,19 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS tv_schedule ( - contract_id text NOT NULL, - creator_id text NOT NULL, - end_time timestamp with time zone NOT NULL, - id serial NOT NULL, - is_featured boolean DEFAULT false, - schedule_created_time timestamp with time zone DEFAULT now(), - source text NOT NULL, - start_time timestamp with time zone NOT NULL, - stream_id text NOT NULL, - title text NOT NULL -); - - +create table if not exists + tv_schedule ( + contract_id text not null, + creator_id text not null, + end_time timestamp with time zone not null, + id serial not null, + is_featured boolean default false, + schedule_created_time timestamp with time zone default now(), + source text not null, + start_time timestamp with time zone not null, + stream_id text not null, + title text not null + ); -- Indexes -DROP INDEX IF EXISTS tv_schedule_pkey; -CREATE UNIQUE INDEX tv_schedule_pkey ON public.tv_schedule USING btree (id); +drop index if exists tv_schedule_pkey; +create unique index tv_schedule_pkey on public.tv_schedule using btree (id); diff --git a/backend/supabase/txn_summary_stats.sql b/backend/supabase/txn_summary_stats.sql index 6bff4e4c0f..8747e571c5 100644 --- a/backend/supabase/txn_summary_stats.sql +++ b/backend/supabase/txn_summary_stats.sql @@ -1,27 +1,29 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS txn_summary_stats ( - category text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - end_time timestamp with time zone NOT NULL, - from_type text NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - quest_type text, - start_time timestamp with time zone NOT NULL, - to_type text NOT NULL, - token text NOT NULL, - total_amount numeric NOT NULL -); - - +create table if not exists + txn_summary_stats ( + category text not null, + created_time timestamp with time zone default now() not null, + end_time timestamp with time zone not null, + from_type text not null, + id bigint primary key generated always as identity not null, + quest_type text, + start_time timestamp with time zone not null, + to_type text not null, + token text not null, + total_amount numeric not null + ); -- Row Level Security -ALTER TABLE txn_summary_stats ENABLE ROW LEVEL SECURITY; +alter table txn_summary_stats enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON txn_summary_stats; -CREATE POLICY "public read" ON txn_summary_stats FOR SELECT USING (true) ; +drop policy if exists "public read" on txn_summary_stats; + +create policy "public read" on txn_summary_stats for +select + using (true); -- Indexes -DROP INDEX IF EXISTS txn_summary_stats_pkey; -CREATE UNIQUE INDEX txn_summary_stats_pkey ON public.txn_summary_stats USING btree (id); +drop index if exists txn_summary_stats_pkey; +create unique index txn_summary_stats_pkey on public.txn_summary_stats using btree (id); diff --git a/backend/supabase/txns.sql b/backend/supabase/txns.sql index a83f0a3222..8800d6481a 100644 --- a/backend/supabase/txns.sql +++ b/backend/supabase/txns.sql @@ -1,37 +1,60 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS txns ( - amount numeric NOT NULL, - category text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - data jsonb NOT NULL, - from_id text NOT NULL, - from_type text NOT NULL, - id text PRIMARY KEY DEFAULT random_alphanumeric(8) NOT NULL, - to_id text NOT NULL, - to_type text NOT NULL, - token text DEFAULT 'M$'::text NOT NULL CONSTRAINT txns_token_check CHECK ((token = ANY (ARRAY['M$'::text, 'CASH'::text, 'SHARE'::text, 'SPICE'::text]))) -); - - +create table if not exists + txns ( + amount numeric not null, + category text not null, + created_time timestamp with time zone default now() not null, + data jsonb not null, + from_id text not null, + from_type text not null, + id text primary key default random_alphanumeric (8) not null, + to_id text not null, + to_type text not null, + token text default 'M$'::text not null constraint txns_token_check check ( + ( + token = any ( + array[ + 'M$'::text, + 'CASH'::text, + 'SHARE'::text, + 'SPICE'::text + ] + ) + ) + ) + ); -- Row Level Security -ALTER TABLE txns ENABLE ROW LEVEL SECURITY; +alter table txns enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON txns; -CREATE POLICY "public read" ON txns FOR SELECT USING (true) ; +drop policy if exists "public read" on txns; + +create policy "public read" on txns for +select + using (true); -- Indexes -DROP INDEX IF EXISTS txns_category_native; -CREATE INDEX txns_category_native ON public.txns USING btree (category); -DROP INDEX IF EXISTS txns_category_to_id; -CREATE INDEX txns_category_to_id ON public.txns USING btree (category, to_id); -DROP INDEX IF EXISTS txns_category_to_id_from_id; -CREATE INDEX txns_category_to_id_from_id ON public.txns USING btree (category, to_id, from_id); -DROP INDEX IF EXISTS txns_from_created_time; -CREATE INDEX txns_from_created_time ON public.txns USING btree (from_id, created_time); -DROP INDEX IF EXISTS txns_pkey; -CREATE UNIQUE INDEX txns_pkey ON public.txns USING btree (id); -DROP INDEX IF EXISTS txns_to_created_time; -CREATE INDEX txns_to_created_time ON public.txns USING btree (to_id, created_time); +drop index if exists txns_category_native; + +create index txns_category_native on public.txns using btree (category); + +drop index if exists txns_category_to_id; + +create index txns_category_to_id on public.txns using btree (category, to_id); + +drop index if exists txns_category_to_id_from_id; + +create index txns_category_to_id_from_id on public.txns using btree (category, to_id, from_id); + +drop index if exists txns_from_created_time; + +create index txns_from_created_time on public.txns using btree (from_id, created_time); + +drop index if exists txns_pkey; + +create unique index txns_pkey on public.txns using btree (id); + +drop index if exists txns_to_created_time; +create index txns_to_created_time on public.txns using btree (to_id, created_time); diff --git a/backend/supabase/user_comment_view_events.sql b/backend/supabase/user_comment_view_events.sql index 64995d7985..f2698f2f23 100644 --- a/backend/supabase/user_comment_view_events.sql +++ b/backend/supabase/user_comment_view_events.sql @@ -1,20 +1,21 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + user_comment_view_events ( + comment_id text not null, + contract_id text not null, + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS user_comment_view_events ( - comment_id text NOT NULL, - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table user_comment_view_events enable row level security; +-- Indexes +drop index if exists user_comment_view_events_pkey; +create unique index user_comment_view_events_pkey on public.user_comment_view_events using btree (id); --- Row Level Security -ALTER TABLE user_comment_view_events ENABLE ROW LEVEL SECURITY; --- Indexes -DROP INDEX IF EXISTS user_comment_view_events_pkey; -CREATE UNIQUE INDEX user_comment_view_events_pkey ON public.user_comment_view_events USING btree (id); -DROP INDEX IF EXISTS user_comment_view_events_user_id_created_time; -CREATE INDEX user_comment_view_events_user_id_created_time ON public.user_comment_view_events USING btree (user_id, created_time DESC); +drop index if exists user_comment_view_events_user_id_created_time; +create index user_comment_view_events_user_id_created_time on public.user_comment_view_events using btree (user_id, created_time desc); diff --git a/backend/supabase/user_contract_interactions.sql b/backend/supabase/user_contract_interactions.sql index 0733579d2e..f32df63a4f 100644 --- a/backend/supabase/user_contract_interactions.sql +++ b/backend/supabase/user_contract_interactions.sql @@ -1,27 +1,30 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + user_contract_interactions ( + bet_group_id text, + bet_id text, + comment_id text, + contract_id text not null, + created_time timestamp with time zone default now() not null, + feed_reasons text[], + feed_type text, + id bigint primary key generated always as identity not null, + name text not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS user_contract_interactions ( - bet_group_id text, - bet_id text, - comment_id text, - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - feed_reasons text[], - feed_type text, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - name text NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table user_contract_interactions enable row level security; +-- Indexes +drop index if exists user_contract_interactions_name_contract_id_user_id; +create index user_contract_interactions_name_contract_id_user_id on public.user_contract_interactions using btree (name, contract_id, user_id); --- Row Level Security -ALTER TABLE user_contract_interactions ENABLE ROW LEVEL SECURITY; --- Indexes -DROP INDEX IF EXISTS user_contract_interactions_name_contract_id_user_id; -CREATE INDEX user_contract_interactions_name_contract_id_user_id ON public.user_contract_interactions USING btree (name, contract_id, user_id); -DROP INDEX IF EXISTS user_contract_interactions_pkey; -CREATE UNIQUE INDEX user_contract_interactions_pkey ON public.user_contract_interactions USING btree (id); -DROP INDEX IF EXISTS user_contract_interactions_user_id_created_time; -CREATE INDEX user_contract_interactions_user_id_created_time ON public.user_contract_interactions USING btree (user_id, created_time DESC); +drop index if exists user_contract_interactions_pkey; + +create unique index user_contract_interactions_pkey on public.user_contract_interactions using btree (id); + +drop index if exists user_contract_interactions_user_id_created_time; +create index user_contract_interactions_user_id_created_time on public.user_contract_interactions using btree (user_id, created_time desc); diff --git a/backend/supabase/user_contract_metrics.sql b/backend/supabase/user_contract_metrics.sql index ee16230c76..c230b5be35 100644 --- a/backend/supabase/user_contract_metrics.sql +++ b/backend/supabase/user_contract_metrics.sql @@ -8,12 +8,11 @@ create table if not exists has_shares boolean, has_yes_shares boolean, id bigint primary key generated always as identity not null, - loan numeric default 0 not null, profit numeric, - profit_adjustment numeric, total_shares_no numeric, total_shares_yes numeric, - user_id text not null + user_id text not null, + loan numeric default 0 ); -- Triggers @@ -53,11 +52,11 @@ BEGIN UPDATE user_contract_metrics SET data = data || jsonb_build_object( - 'hasYesShares', sum_has_yes_shares, - 'hasNoShares', sum_has_no_shares, - 'hasShares', sum_has_shares, - 'loan', sum_loan - ), + 'hasYesShares', sum_has_yes_shares, + 'hasNoShares', sum_has_no_shares, + 'hasShares', sum_has_shares, + 'loan', sum_loan + ), has_yes_shares = sum_has_yes_shares, has_no_shares = sum_has_no_shares, has_shares = sum_has_shares, @@ -92,6 +91,12 @@ drop index if exists contract_metrics_answer_id; create index contract_metrics_answer_id on public.user_contract_metrics using btree (contract_id, answer_id); +drop index if exists user_contract_metrics_contract_profit_null; + +create index concurrently user_contract_metrics_contract_profit_null on public.user_contract_metrics using btree (contract_id, profit) +where + answer_id is null; + drop index if exists unique_user_contract_answer; create unique index unique_user_contract_answer on public.user_contract_metrics using btree ( @@ -100,12 +105,6 @@ create unique index unique_user_contract_answer on public.user_contract_metrics coalesce(answer_id, ''::text) ); -drop index if exists user_contract_metrics_contract_profit_null; - -create index user_contract_metrics_contract_profit_null on public.user_contract_metrics using btree (contract_id, profit) -where - (answer_id is null); - drop index if exists user_contract_metrics_pkey; create unique index user_contract_metrics_pkey on public.user_contract_metrics using btree (id); diff --git a/backend/supabase/user_contract_views.sql b/backend/supabase/user_contract_views.sql index 31d57bf51d..08c874b424 100644 --- a/backend/supabase/user_contract_views.sql +++ b/backend/supabase/user_contract_views.sql @@ -1,34 +1,59 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS user_contract_views ( - card_views bigint DEFAULT 0 NOT NULL CONSTRAINT user_contract_views_card_views_check CHECK ((card_views >= 0)), - contract_id text NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - last_card_view_ts timestamp with time zone, - last_page_view_ts timestamp with time zone, - last_promoted_view_ts timestamp with time zone, - page_views bigint DEFAULT 0 NOT NULL CONSTRAINT user_contract_views_page_views_check CHECK ((page_views >= 0)), - promoted_views bigint DEFAULT 0 NOT NULL CONSTRAINT user_contract_views_promoted_views_check CHECK ((promoted_views >= 0)), - user_id text, - CONSTRAINT user_contract_views_check CHECK ((((promoted_views + card_views) + page_views) > 0)), - CONSTRAINT user_contract_views_check1 CHECK (((last_page_view_ts IS NOT NULL) OR (last_card_view_ts IS NOT NULL) OR (last_promoted_view_ts IS NOT NULL))) -); - - +create table if not exists + user_contract_views ( + card_views bigint default 0 not null constraint user_contract_views_card_views_check check ((card_views >= 0)), + contract_id text not null, + id bigint primary key generated always as identity not null, + last_card_view_ts timestamp with time zone, + last_page_view_ts timestamp with time zone, + last_promoted_view_ts timestamp with time zone, + page_views bigint default 0 not null constraint user_contract_views_page_views_check check ((page_views >= 0)), + promoted_views bigint default 0 not null constraint user_contract_views_promoted_views_check check ((promoted_views >= 0)), + user_id text, + constraint user_contract_views_check check ( + (((promoted_views + card_views) + page_views) > 0) + ), + constraint user_contract_views_check1 check ( + ( + (last_page_view_ts is not null) + or (last_card_view_ts is not null) + or (last_promoted_view_ts is not null) + ) + ) + ); -- Row Level Security -ALTER TABLE user_contract_views ENABLE ROW LEVEL SECURITY; +alter table user_contract_views enable row level security; + -- Policies -DROP POLICY IF EXISTS "self and admin read" ON user_contract_views; -CREATE POLICY "self and admin read" ON user_contract_views FOR SELECT USING (((user_id = firebase_uid()) OR is_admin(firebase_uid()))) ; +drop policy if exists "self and admin read" on user_contract_views; + +create policy "self and admin read" on user_contract_views for +select + using ( + ( + (user_id = firebase_uid ()) + or is_admin (firebase_uid ()) + ) + ); -- Indexes -DROP INDEX IF EXISTS user_contract_views_contract_id; -CREATE INDEX user_contract_views_contract_id ON public.user_contract_views USING btree (contract_id, user_id); -DROP INDEX IF EXISTS user_contract_views_pkey; -CREATE UNIQUE INDEX user_contract_views_pkey ON public.user_contract_views USING btree (id); -DROP INDEX IF EXISTS user_contract_views_user_contract_ts; -CREATE INDEX user_contract_views_user_contract_ts ON public.user_contract_views USING btree (user_id, contract_id) INCLUDE (last_page_view_ts, last_promoted_view_ts, last_card_view_ts); -DROP INDEX IF EXISTS user_contract_views_user_id; -CREATE UNIQUE INDEX user_contract_views_user_id ON public.user_contract_views USING btree (user_id, contract_id) NULLS NOT DISTINCT; +drop index if exists user_contract_views_contract_id; + +create index user_contract_views_contract_id on public.user_contract_views using btree (contract_id, user_id); + +drop index if exists user_contract_views_pkey; + +create unique index user_contract_views_pkey on public.user_contract_views using btree (id); + +drop index if exists user_contract_views_user_contract_ts; + +create index user_contract_views_user_contract_ts on public.user_contract_views using btree (user_id, contract_id) include ( + last_page_view_ts, + last_promoted_view_ts, + last_card_view_ts +); + +drop index if exists user_contract_views_user_id; +create unique index user_contract_views_user_id on public.user_contract_views using btree (user_id, contract_id) nulls not distinct; diff --git a/backend/supabase/user_disinterests.sql b/backend/supabase/user_disinterests.sql index d729c17c32..e0e7b17f70 100644 --- a/backend/supabase/user_disinterests.sql +++ b/backend/supabase/user_disinterests.sql @@ -1,28 +1,34 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS user_disinterests ( - comment_id text, - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - creator_id text NOT NULL, - feed_id bigint, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - user_id text NOT NULL -); - - +create table if not exists + user_disinterests ( + comment_id text, + contract_id text not null, + created_time timestamp with time zone default now() not null, + creator_id text not null, + feed_id bigint, + id bigint primary key generated always as identity not null, + user_id text not null + ); -- Row Level Security -ALTER TABLE user_disinterests ENABLE ROW LEVEL SECURITY; +alter table user_disinterests enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON user_disinterests; -CREATE POLICY "public read" ON user_disinterests FOR SELECT USING (true) ; +drop policy if exists "public read" on user_disinterests; + +create policy "public read" on user_disinterests for +select + using (true); -- Indexes -DROP INDEX IF EXISTS user_disinterests_pkey; -CREATE UNIQUE INDEX user_disinterests_pkey ON public.user_disinterests USING btree (id); -DROP INDEX IF EXISTS user_disinterests_user_id; -CREATE INDEX user_disinterests_user_id ON public.user_disinterests USING btree (user_id); -DROP INDEX IF EXISTS user_disinterests_user_id_contract_id; -CREATE INDEX user_disinterests_user_id_contract_id ON public.user_disinterests USING btree (user_id, contract_id); +drop index if exists user_disinterests_pkey; + +create unique index user_disinterests_pkey on public.user_disinterests using btree (id); + +drop index if exists user_disinterests_user_id; + +create index user_disinterests_user_id on public.user_disinterests using btree (user_id); + +drop index if exists user_disinterests_user_id_contract_id; +create index user_disinterests_user_id_contract_id on public.user_disinterests using btree (user_id, contract_id); diff --git a/backend/supabase/user_embeddings.sql b/backend/supabase/user_embeddings.sql index 787d83b6e0..0283ce7013 100644 --- a/backend/supabase/user_embeddings.sql +++ b/backend/supabase/user_embeddings.sql @@ -1,25 +1,28 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + user_embeddings ( + contract_view_embedding vector (1536), + created_at timestamp without time zone default now() not null, + disinterest_embedding vector (1536), + interest_embedding vector (1536) not null, + user_id text primary key not null + ); -CREATE TABLE IF NOT EXISTS user_embeddings ( - contract_view_embedding vector(1536), - created_at timestamp without time zone DEFAULT now() NOT NULL, - disinterest_embedding vector(1536), - interest_embedding vector(1536) NOT NULL, - user_id text PRIMARY KEY NOT NULL -); +-- Row Level Security +alter table user_embeddings enable row level security; +-- Policies +drop policy if exists "admin write access" on user_embeddings; +create policy "admin write access" on user_embeddings for all to service_role; --- Row Level Security -ALTER TABLE user_embeddings ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "admin write access" ON user_embeddings; -CREATE POLICY "admin write access" ON user_embeddings FOR ALL TO service_role ; +drop policy if exists "public read" on user_embeddings; -DROP POLICY IF EXISTS "public read" ON user_embeddings; -CREATE POLICY "public read" ON user_embeddings FOR SELECT USING (true) ; +create policy "public read" on user_embeddings for +select + using (true); -- Indexes -DROP INDEX IF EXISTS user_embeddings_pkey; -CREATE UNIQUE INDEX user_embeddings_pkey ON public.user_embeddings USING btree (user_id); +drop index if exists user_embeddings_pkey; +create unique index user_embeddings_pkey on public.user_embeddings using btree (user_id); diff --git a/backend/supabase/user_events.sql b/backend/supabase/user_events.sql index 3d4194de3f..ed8b4f0aab 100644 --- a/backend/supabase/user_events.sql +++ b/backend/supabase/user_events.sql @@ -1,30 +1,42 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + user_events ( + ad_id text, + comment_id text, + contract_id text, + data jsonb not null, + id bigint primary key generated always as identity not null, + name text not null, + ts timestamp with time zone default now() not null, + user_id text + ); -CREATE TABLE IF NOT EXISTS user_events ( - ad_id text, - comment_id text, - contract_id text, - data jsonb NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - name text NOT NULL, - ts timestamp with time zone DEFAULT now() NOT NULL, - user_id text -); +-- Row Level Security +alter table user_events enable row level security; +-- Policies +drop policy if exists "self and admin read" on user_events; +create policy "self and admin read" on user_events for +select + using ( + ( + (user_id = firebase_uid ()) + or is_admin (firebase_uid ()) + ) + ); --- Row Level Security -ALTER TABLE user_events ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "self and admin read" ON user_events; -CREATE POLICY "self and admin read" ON user_events FOR SELECT USING (((user_id = firebase_uid()) OR is_admin(firebase_uid()))) ; +drop policy if exists "user can insert" on user_events; -DROP POLICY IF EXISTS "user can insert" ON user_events; -CREATE POLICY "user can insert" ON user_events FOR INSERT WITH CHECK (true); +create policy "user can insert" on user_events for insert +with + check (true); -- Indexes -DROP INDEX IF EXISTS user_events_pkey; -CREATE UNIQUE INDEX user_events_pkey ON public.user_events USING btree (id); -DROP INDEX IF EXISTS user_events_ts; -CREATE INDEX user_events_ts ON public.user_events USING btree (ts DESC); +drop index if exists user_events_pkey; + +create unique index user_events_pkey on public.user_events using btree (id); + +drop index if exists user_events_ts; +create index user_events_ts on public.user_events using btree (ts desc); diff --git a/backend/supabase/user_follows.sql b/backend/supabase/user_follows.sql index de3f5f7085..4489a158e3 100644 --- a/backend/supabase/user_follows.sql +++ b/backend/supabase/user_follows.sql @@ -1,21 +1,23 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS user_follows ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - follow_id text NOT NULL, - user_id text NOT NULL, - CONSTRAINT PRIMARY KEY (user_id, follow_id) -); - - +create table if not exists + user_follows ( + created_time timestamp with time zone default now() not null, + follow_id text not null, + user_id text not null, + constraint primary key (user_id, follow_id) + ); -- Row Level Security -ALTER TABLE user_follows ENABLE ROW LEVEL SECURITY; +alter table user_follows enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON user_follows; -CREATE POLICY "public read" ON user_follows FOR SELECT USING (true) ; +drop policy if exists "public read" on user_follows; + +create policy "public read" on user_follows for +select + using (true); -- Indexes -DROP INDEX IF EXISTS user_follows_pkey; -CREATE UNIQUE INDEX user_follows_pkey ON public.user_follows USING btree (user_id, follow_id); +drop index if exists user_follows_pkey; +create unique index user_follows_pkey on public.user_follows using btree (user_id, follow_id); diff --git a/backend/supabase/user_monitor_status.sql b/backend/supabase/user_monitor_status.sql index 022b93a6d2..e9d741f57e 100644 --- a/backend/supabase/user_monitor_status.sql +++ b/backend/supabase/user_monitor_status.sql @@ -1,24 +1,27 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS user_monitor_status ( - created_time timestamp with time zone DEFAULT now(), - data jsonb NOT NULL, - fraud_confidence_score integer, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - identity_confidence_score integer, - reason_codes text[], - user_id text NOT NULL -); +create table if not exists + user_monitor_status ( + created_time timestamp with time zone default now(), + data jsonb not null, + fraud_confidence_score integer, + id bigint primary key generated always as identity not null, + identity_confidence_score integer, + reason_codes text[], + user_id text not null + ); -- Foreign Keys -ALTER TABLE user_monitor_status ADD CONSTRAINT user_monitor_status_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); - +alter table user_monitor_status +add constraint user_monitor_status_user_id_fkey foreign key (user_id) references users (id); -- Row Level Security -ALTER TABLE user_monitor_status ENABLE ROW LEVEL SECURITY; +alter table user_monitor_status enable row level security; + -- Indexes -DROP INDEX IF EXISTS idx_user_monitor_status_user_id; -CREATE INDEX idx_user_monitor_status_user_id ON public.user_monitor_status USING btree (user_id, created_time DESC); -DROP INDEX IF EXISTS user_monitor_status_pkey; -CREATE UNIQUE INDEX user_monitor_status_pkey ON public.user_monitor_status USING btree (id); +drop index if exists idx_user_monitor_status_user_id; + +create index idx_user_monitor_status_user_id on public.user_monitor_status using btree (user_id, created_time desc); + +drop index if exists user_monitor_status_pkey; +create unique index user_monitor_status_pkey on public.user_monitor_status using btree (id); diff --git a/backend/supabase/user_notifications.sql b/backend/supabase/user_notifications.sql index 2e09b9ad10..36ffefd38e 100644 --- a/backend/supabase/user_notifications.sql +++ b/backend/supabase/user_notifications.sql @@ -1,25 +1,34 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS user_notifications ( - data jsonb NOT NULL, - notification_id text NOT NULL, - user_id text NOT NULL, - CONSTRAINT PRIMARY KEY (user_id, notification_id) -); - - +create table if not exists + user_notifications ( + data jsonb not null, + notification_id text not null, + user_id text not null, + constraint primary key (user_id, notification_id) + ); -- Row Level Security -ALTER TABLE user_notifications ENABLE ROW LEVEL SECURITY; +alter table user_notifications enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON user_notifications; -CREATE POLICY "public read" ON user_notifications FOR SELECT USING (true) ; +drop policy if exists "public read" on user_notifications; + +create policy "public read" on user_notifications for +select + using (true); -- Indexes -DROP INDEX IF EXISTS user_notifications_notification_id; -CREATE INDEX user_notifications_notification_id ON public.user_notifications USING btree (notification_id, user_id); -DROP INDEX IF EXISTS user_notifications_pkey; -CREATE UNIQUE INDEX user_notifications_pkey ON public.user_notifications USING btree (user_id, notification_id); -DROP INDEX IF EXISTS user_notifications_user_id_created_time; -CREATE INDEX user_notifications_user_id_created_time ON public.user_notifications USING btree (user_id, (((data -> 'createdTime'::text))::bigint) DESC); +drop index if exists user_notifications_notification_id; +create index user_notifications_notification_id on public.user_notifications using btree (notification_id, user_id); + +drop index if exists user_notifications_pkey; + +create unique index user_notifications_pkey on public.user_notifications using btree (user_id, notification_id); + +drop index if exists user_notifications_user_id_created_time; + +create index user_notifications_user_id_created_time on public.user_notifications using btree ( + user_id, + (((data -> 'createdTime'::text))::bigint) desc +); diff --git a/backend/supabase/user_portfolio_history.sql b/backend/supabase/user_portfolio_history.sql index c78b58fa6d..2f4bd7231b 100644 --- a/backend/supabase/user_portfolio_history.sql +++ b/backend/supabase/user_portfolio_history.sql @@ -1,29 +1,28 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS user_portfolio_history ( - balance numeric, - cash_balance numeric DEFAULT 0 NOT NULL, - cash_investment_value numeric DEFAULT 0 NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - investment_value numeric, - loan_total numeric, - profit numeric, - spice_balance numeric DEFAULT 0 NOT NULL, - total_cash_deposits numeric DEFAULT 0 NOT NULL, - total_deposits numeric, - ts timestamp without time zone, - user_id text NOT NULL -); - +create table if not exists + user_portfolio_history ( + balance numeric, + cash_balance numeric default 0 not null, + cash_investment_value numeric default 0 not null, + id bigint primary key generated always as identity not null, + investment_value numeric, + loan_total numeric, + profit numeric, + spice_balance numeric default 0 not null, + total_cash_deposits numeric default 0 not null, + total_deposits numeric, + ts timestamp without time zone, + user_id text not null + ); -- Triggers -CREATE TRIGGER user_portfolio_history_insert AFTER INSERT ON public.user_portfolio_history FOR EACH ROW EXECUTE FUNCTION update_user_portfolio_history_latest(); +create trigger user_portfolio_history_insert +after insert on public.user_portfolio_history for each row +execute function update_user_portfolio_history_latest (); -- Functions -CREATE OR REPLACE FUNCTION public.update_user_portfolio_history_latest() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ +create +or replace function public.update_user_portfolio_history_latest () returns trigger language plpgsql as $function$ begin insert into user_portfolio_history_latest (user_id, ts, investment_value, cash_investment_value, balance, total_deposits, total_cash_deposits, cash_balance, spice_balance, loan_total, profit, last_calculated) values (new.user_id, new.ts, new.investment_value, new.cash_investment_value, new.balance, new.total_deposits, new.total_cash_deposits, new.cash_balance, new.spice_balance, new.loan_total, new.profit, new.ts) @@ -42,18 +41,23 @@ begin where user_portfolio_history_latest.ts < excluded.ts; return new; end; -$function$ -; +$function$; -- Row Level Security -ALTER TABLE user_portfolio_history ENABLE ROW LEVEL SECURITY; +alter table user_portfolio_history enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON user_portfolio_history; -CREATE POLICY "public read" ON user_portfolio_history FOR SELECT USING (true) ; +drop policy if exists "public read" on user_portfolio_history; + +create policy "public read" on user_portfolio_history for +select + using (true); -- Indexes -DROP INDEX IF EXISTS user_portfolio_history_pkey; -CREATE UNIQUE INDEX user_portfolio_history_pkey ON public.user_portfolio_history USING btree (id); -DROP INDEX IF EXISTS user_portfolio_history_user_ts; -CREATE INDEX user_portfolio_history_user_ts ON public.user_portfolio_history USING btree (user_id, ts DESC); +drop index if exists user_portfolio_history_pkey; + +create unique index user_portfolio_history_pkey on public.user_portfolio_history using btree (id); + +drop index if exists user_portfolio_history_user_ts; +create index user_portfolio_history_user_ts on public.user_portfolio_history using btree (user_id, ts desc); diff --git a/backend/supabase/user_portfolio_history_latest.sql b/backend/supabase/user_portfolio_history_latest.sql index 6118f0850b..0db9e2fe87 100644 --- a/backend/supabase/user_portfolio_history_latest.sql +++ b/backend/supabase/user_portfolio_history_latest.sql @@ -1,23 +1,21 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS user_portfolio_history_latest ( - balance numeric NOT NULL, - cash_balance numeric DEFAULT 0.0 NOT NULL, - cash_investment_value numeric DEFAULT 0.0 NOT NULL, - investment_value numeric NOT NULL, - last_calculated timestamp with time zone NOT NULL, - loan_total numeric, - profit numeric, - spice_balance numeric DEFAULT 0.0 NOT NULL, - total_cash_deposits numeric DEFAULT 0.0 NOT NULL, - total_deposits numeric NOT NULL, - ts timestamp without time zone NOT NULL, - user_id text PRIMARY KEY NOT NULL -); - - +create table if not exists + user_portfolio_history_latest ( + balance numeric not null, + cash_balance numeric default 0.0 not null, + cash_investment_value numeric default 0.0 not null, + investment_value numeric not null, + last_calculated timestamp with time zone not null, + loan_total numeric, + profit numeric, + spice_balance numeric default 0.0 not null, + total_cash_deposits numeric default 0.0 not null, + total_deposits numeric not null, + ts timestamp without time zone not null, + user_id text primary key not null + ); -- Indexes -DROP INDEX IF EXISTS user_portfolio_history_latest_pkey; -CREATE UNIQUE INDEX user_portfolio_history_latest_pkey ON public.user_portfolio_history_latest USING btree (user_id); +drop index if exists user_portfolio_history_latest_pkey; +create unique index user_portfolio_history_latest_pkey on public.user_portfolio_history_latest using btree (user_id); diff --git a/backend/supabase/user_quest_metrics.sql b/backend/supabase/user_quest_metrics.sql index c71dc7cc02..792fc740c0 100644 --- a/backend/supabase/user_quest_metrics.sql +++ b/backend/supabase/user_quest_metrics.sql @@ -1,22 +1,24 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS user_quest_metrics ( - idempotency_key text, - score_id text NOT NULL, - score_value numeric NOT NULL, - user_id text NOT NULL, - CONSTRAINT PRIMARY KEY (user_id, score_id) -); - - +create table if not exists + user_quest_metrics ( + idempotency_key text, + score_id text not null, + score_value numeric not null, + user_id text not null, + constraint primary key (user_id, score_id) + ); -- Row Level Security -ALTER TABLE user_quest_metrics ENABLE ROW LEVEL SECURITY; +alter table user_quest_metrics enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON user_quest_metrics; -CREATE POLICY "public read" ON user_quest_metrics FOR SELECT USING (true) ; +drop policy if exists "public read" on user_quest_metrics; + +create policy "public read" on user_quest_metrics for +select + using (true); -- Indexes -DROP INDEX IF EXISTS user_quest_metrics_pkey; -CREATE UNIQUE INDEX user_quest_metrics_pkey ON public.user_quest_metrics USING btree (user_id, score_id); +drop index if exists user_quest_metrics_pkey; +create unique index user_quest_metrics_pkey on public.user_quest_metrics using btree (user_id, score_id); diff --git a/backend/supabase/user_reactions.sql b/backend/supabase/user_reactions.sql index 9e3a6627dd..9b60e8fd9e 100644 --- a/backend/supabase/user_reactions.sql +++ b/backend/supabase/user_reactions.sql @@ -1,27 +1,31 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS user_reactions ( - content_id text NOT NULL, - content_owner_id text NOT NULL, - content_type text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - reaction_id text DEFAULT random_alphanumeric(12) NOT NULL, - reaction_type text DEFAULT 'like'::text NOT NULL, - user_id text NOT NULL, - CONSTRAINT PRIMARY KEY (user_id, reaction_id) -); - - +create table if not exists + user_reactions ( + content_id text not null, + content_owner_id text not null, + content_type text not null, + created_time timestamp with time zone default now() not null, + reaction_id text default random_alphanumeric (12) not null, + reaction_type text default 'like'::text not null, + user_id text not null, + constraint primary key (user_id, reaction_id) + ); -- Row Level Security -ALTER TABLE user_reactions ENABLE ROW LEVEL SECURITY; +alter table user_reactions enable row level security; + -- Policies -DROP POLICY IF EXISTS "public read" ON user_reactions; -CREATE POLICY "public read" ON user_reactions FOR SELECT USING (true) ; +drop policy if exists "public read" on user_reactions; + +create policy "public read" on user_reactions for +select + using (true); -- Indexes -DROP INDEX IF EXISTS user_reactions_content_id_raw; -CREATE INDEX user_reactions_content_id_raw ON public.user_reactions USING btree (content_id); -DROP INDEX IF EXISTS user_reactions_pkey; -CREATE UNIQUE INDEX user_reactions_pkey ON public.user_reactions USING btree (user_id, reaction_id); +drop index if exists user_reactions_content_id_raw; + +create index user_reactions_content_id_raw on public.user_reactions using btree (content_id); + +drop index if exists user_reactions_pkey; +create unique index user_reactions_pkey on public.user_reactions using btree (user_id, reaction_id); diff --git a/backend/supabase/user_seen_chats.sql b/backend/supabase/user_seen_chats.sql index 4677306df3..61002b8f46 100644 --- a/backend/supabase/user_seen_chats.sql +++ b/backend/supabase/user_seen_chats.sql @@ -1,26 +1,33 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + user_seen_chats ( + channel_id text not null, + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS user_seen_chats ( - channel_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table user_seen_chats enable row level security; +-- Policies +drop policy if exists "public read" on user_seen_chats; +create policy "public read" on user_seen_chats for +select + using (true); --- Row Level Security -ALTER TABLE user_seen_chats ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "public read" ON user_seen_chats; -CREATE POLICY "public read" ON user_seen_chats FOR SELECT USING (true) ; +drop policy if exists "user can insert" on user_seen_chats; -DROP POLICY IF EXISTS "user can insert" ON user_seen_chats; -CREATE POLICY "user can insert" ON user_seen_chats FOR INSERT WITH CHECK (true); +create policy "user can insert" on user_seen_chats for insert +with + check (true); -- Indexes -DROP INDEX IF EXISTS user_seen_chats_created_time_desc_idx; -CREATE INDEX user_seen_chats_created_time_desc_idx ON public.user_seen_chats USING btree (user_id, channel_id, created_time DESC); -DROP INDEX IF EXISTS user_seen_chats_pkey; -CREATE UNIQUE INDEX user_seen_chats_pkey ON public.user_seen_chats USING btree (id); +drop index if exists user_seen_chats_created_time_desc_idx; + +create index user_seen_chats_created_time_desc_idx on public.user_seen_chats using btree (user_id, channel_id, created_time desc); + +drop index if exists user_seen_chats_pkey; +create unique index user_seen_chats_pkey on public.user_seen_chats using btree (id); diff --git a/backend/supabase/user_topic_interests.sql b/backend/supabase/user_topic_interests.sql index b6a4e85d4f..095decf340 100644 --- a/backend/supabase/user_topic_interests.sql +++ b/backend/supabase/user_topic_interests.sql @@ -1,19 +1,20 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + user_topic_interests ( + created_time timestamp with time zone default now() not null, + group_ids_to_activity jsonb not null, + id bigint primary key generated always as identity not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS user_topic_interests ( - created_time timestamp with time zone DEFAULT now() NOT NULL, - group_ids_to_activity jsonb NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table user_topic_interests enable row level security; +-- Indexes +drop index if exists user_topic_interests_created_time; +create index user_topic_interests_created_time on public.user_topic_interests using btree (user_id, created_time desc); --- Row Level Security -ALTER TABLE user_topic_interests ENABLE ROW LEVEL SECURITY; --- Indexes -DROP INDEX IF EXISTS user_topic_interests_created_time; -CREATE INDEX user_topic_interests_created_time ON public.user_topic_interests USING btree (user_id, created_time DESC); -DROP INDEX IF EXISTS user_topic_interests_pkey; -CREATE UNIQUE INDEX user_topic_interests_pkey ON public.user_topic_interests USING btree (id); +drop index if exists user_topic_interests_pkey; +create unique index user_topic_interests_pkey on public.user_topic_interests using btree (id); diff --git a/backend/supabase/user_topics.sql b/backend/supabase/user_topics.sql index 839ed7248b..17662d6170 100644 --- a/backend/supabase/user_topics.sql +++ b/backend/supabase/user_topics.sql @@ -1,24 +1,29 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + user_topics ( + created_at timestamp without time zone default now() not null, + topic_embedding vector (1536) not null, + topics text[] not null, + user_id text primary key not null + ); -CREATE TABLE IF NOT EXISTS user_topics ( - created_at timestamp without time zone DEFAULT now() NOT NULL, - topic_embedding vector(1536) NOT NULL, - topics text[] NOT NULL, - user_id text PRIMARY KEY NOT NULL -); +-- Row Level Security +alter table user_topics enable row level security; +-- Policies +drop policy if exists "public read" on user_topics; +create policy "public read" on user_topics for +select + using (true); --- Row Level Security -ALTER TABLE user_topics ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "public read" ON user_topics; -CREATE POLICY "public read" ON user_topics FOR SELECT USING (true) ; +drop policy if exists "public write access" on user_topics; -DROP POLICY IF EXISTS "public write access" ON user_topics; -CREATE POLICY "public write access" ON user_topics FOR INSERT WITH CHECK (true); +create policy "public write access" on user_topics for insert +with + check (true); -- Indexes -DROP INDEX IF EXISTS user_topics_pkey; -CREATE UNIQUE INDEX user_topics_pkey ON public.user_topics USING btree (user_id); +drop index if exists user_topics_pkey; +create unique index user_topics_pkey on public.user_topics using btree (user_id); diff --git a/backend/supabase/user_view_events.sql b/backend/supabase/user_view_events.sql index 12321a87db..fb30aa2852 100644 --- a/backend/supabase/user_view_events.sql +++ b/backend/supabase/user_view_events.sql @@ -1,24 +1,27 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + user_view_events ( + ad_id text, + comment_id text, + contract_id text, + created_time timestamp with time zone default now() not null, + id bigint primary key generated always as identity not null, + name text not null, + user_id text not null + ); -CREATE TABLE IF NOT EXISTS user_view_events ( - ad_id text, - comment_id text, - contract_id text, - created_time timestamp with time zone DEFAULT now() NOT NULL, - id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL, - name text NOT NULL, - user_id text NOT NULL -); +-- Row Level Security +alter table user_view_events enable row level security; +-- Indexes +drop index if exists user_view_events_contract_id_name_created_time; +create index user_view_events_contract_id_name_created_time on public.user_view_events using btree (contract_id, name, created_time desc); --- Row Level Security -ALTER TABLE user_view_events ENABLE ROW LEVEL SECURITY; --- Indexes -DROP INDEX IF EXISTS user_view_events_contract_id_name_created_time; -CREATE INDEX user_view_events_contract_id_name_created_time ON public.user_view_events USING btree (contract_id, name, created_time DESC); -DROP INDEX IF EXISTS user_view_events_name_contract_id_user_id; -CREATE INDEX user_view_events_name_contract_id_user_id ON public.user_view_events USING btree (user_id, contract_id, name); -DROP INDEX IF EXISTS user_view_events_pkey; -CREATE UNIQUE INDEX user_view_events_pkey ON public.user_view_events USING btree (id); +drop index if exists user_view_events_name_contract_id_user_id; + +create index user_view_events_name_contract_id_user_id on public.user_view_events using btree (user_id, contract_id, name); + +drop index if exists user_view_events_pkey; +create unique index user_view_events_pkey on public.user_view_events using btree (id); diff --git a/backend/supabase/users.sql b/backend/supabase/users.sql index 7f1e37121d..73d750e12a 100644 --- a/backend/supabase/users.sql +++ b/backend/supabase/users.sql @@ -1,39 +1,59 @@ -- This file is autogenerated from regen-schema.ts +create table if not exists + users ( + balance numeric default 0 not null, + cash_balance numeric default 0 not null, + created_time timestamp with time zone default now() not null, + data jsonb not null, + id text primary key default random_alphanumeric (12) not null, + name text not null, + name_username_vector tsvector generated always as ( + to_tsvector( + 'english'::regconfig, + (name || ' '::text) || username + ) + ) stored, + spice_balance numeric default 0 not null, + total_cash_deposits numeric default 0 not null, + total_deposits numeric default 0 not null, + username text not null + ); -CREATE TABLE IF NOT EXISTS users ( - balance numeric DEFAULT 0 NOT NULL, - cash_balance numeric DEFAULT 0 NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - data jsonb NOT NULL, - id text PRIMARY KEY DEFAULT random_alphanumeric(12) NOT NULL, - name text NOT NULL, - name_username_vector tsvector GENERATED ALWAYS AS (to_tsvector('english'::regconfig, (name || ' '::text) || username)) STORED, - resolved_profit_adjustment numeric, - spice_balance numeric DEFAULT 0 NOT NULL, - total_cash_deposits numeric DEFAULT 0 NOT NULL, - total_deposits numeric DEFAULT 0 NOT NULL, - username text NOT NULL +-- Row Level Security +alter table users enable row level security; + +-- Policies +drop policy if exists "public read" on users; + +create policy "public read" on users for +select + using (true); + +-- Indexes +drop index if exists user_referrals_idx; + +create index user_referrals_idx on public.users using btree (((data ->> 'referredByUserId'::text))) +where + ((data ->> 'referredByUserId'::text) is not null); + +drop index if exists user_username_idx; + +create index user_username_idx on public.users using btree (username); + +drop index if exists users_betting_streak_idx; + +create index users_betting_streak_idx on public.users using btree ( + (((data -> 'currentBettingStreak'::text))::integer) ); +drop index if exists users_created_time; +create index users_created_time on public.users using btree (created_time desc); --- Row Level Security -ALTER TABLE users ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "public read" ON users; -CREATE POLICY "public read" ON users FOR SELECT USING (true) ; +drop index if exists users_name_idx; --- Indexes -DROP INDEX IF EXISTS user_referrals_idx; -CREATE INDEX user_referrals_idx ON public.users USING btree (((data ->> 'referredByUserId'::text))) WHERE ((data ->> 'referredByUserId'::text) IS NOT NULL); -DROP INDEX IF EXISTS user_username_idx; -CREATE INDEX user_username_idx ON public.users USING btree (username); -DROP INDEX IF EXISTS users_betting_streak_idx; -CREATE INDEX users_betting_streak_idx ON public.users USING btree ((((data -> 'currentBettingStreak'::text))::integer)); -DROP INDEX IF EXISTS users_created_time; -CREATE INDEX users_created_time ON public.users USING btree (created_time DESC); -DROP INDEX IF EXISTS users_name_idx; -CREATE INDEX users_name_idx ON public.users USING btree (name); -DROP INDEX IF EXISTS users_pkey; -CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id); +create index users_name_idx on public.users using btree (name); + +drop index if exists users_pkey; +create unique index users_pkey on public.users using btree (id); diff --git a/backend/supabase/views.sql b/backend/supabase/views.sql index f3a7d59653..427da62c3d 100644 --- a/backend/supabase/views.sql +++ b/backend/supabase/views.sql @@ -1,54 +1,113 @@ -- This file is autogenerated from regen-schema.ts +create or replace view + final_pp_balances as +select + txns.from_id as user_id, + txns.amount +from + txns +where + ( + (txns.category = 'CONSUME_SPICE'::text) + and ( + ((txns.data -> 'data'::text) ->> 'isLast'::text) is not null + ) + ); -CREATE OR REPLACE VIEW final_pp_balances AS - SELECT txns.from_id AS user_id, - txns.amount - FROM txns - WHERE ((txns.category = 'CONSUME_SPICE'::text) AND (((txns.data -> 'data'::text) ->> 'isLast'::text) IS NOT NULL)); +create or replace view + group_role as +select + gm.member_id, + gp.id as group_id, + gp.name as group_name, + gp.slug as group_slug, + gp.creator_id, + gp.total_members, + users.name, + users.username, + (users.data ->> 'avatarUrl'::text) as avatar_url, + gm.role, + ts_to_millis (gm.created_time) as createdtime, + gp.privacy_status +from + ( + ( + group_members gm + join groups gp on ((gp.id = gm.group_id)) + ) + join users on ((users.id = gm.member_id)) + ); -CREATE OR REPLACE VIEW group_role AS - SELECT gm.member_id, - gp.id AS group_id, - gp.name AS group_name, - gp.slug AS group_slug, - gp.creator_id, - gp.total_members, - users.name, - users.username, - (users.data ->> 'avatarUrl'::text) AS avatar_url, - gm.role, - ts_to_millis(gm.created_time) AS createdtime, - gp.privacy_status - FROM ((group_members gm - JOIN groups gp ON ((gp.id = gm.group_id))) - JOIN users ON ((users.id = gm.member_id))); - -CREATE OR REPLACE VIEW user_league_info AS - SELECT leagues.season, - leagues.division, - leagues.cohort, - leagues.user_id, - leagues.mana_earned, - leagues.created_time, - leagues.mana_earned_breakdown, - leagues.rank_snapshot, - (row_number() OVER (PARTITION BY leagues.season, leagues.division, leagues.cohort ORDER BY leagues.mana_earned DESC))::integer AS rank - FROM leagues; - -CREATE OR REPLACE VIEW user_referrals_profit AS - SELECT subquery.id, - subquery.total_referrals, - subquery.total_referred_profit, - subquery.total_referred_cash_profit, - rank() OVER (ORDER BY subquery.total_referrals DESC) AS rank - FROM ( SELECT referrer.id, - count(*) AS total_referrals, - sum((((uphl.balance + uphl.spice_balance) + uphl.investment_value) - uphl.total_deposits)) AS total_referred_profit, - sum(((uphl.cash_balance + uphl.cash_investment_value) - uphl.total_cash_deposits)) AS total_referred_cash_profit - FROM ((users referred - JOIN users referrer ON ((referrer.id = (referred.data ->> 'referredByUserId'::text)))) - JOIN user_portfolio_history_latest uphl ON ((referred.id = uphl.user_id))) - WHERE ((referred.data ->> 'referredByUserId'::text) IS NOT NULL) - GROUP BY referrer.id) subquery - ORDER BY subquery.total_referrals DESC; +create or replace view + user_league_info as +select + leagues.season, + leagues.division, + leagues.cohort, + leagues.user_id, + leagues.mana_earned, + leagues.created_time, + leagues.mana_earned_breakdown, + leagues.rank_snapshot, + ( + row_number() over ( + partition by + leagues.season, + leagues.division, + leagues.cohort + order by + leagues.mana_earned desc + ) + )::integer as rank +from + leagues; +create or replace view + user_referrals_profit as +select + subquery.id, + subquery.total_referrals, + subquery.total_referred_profit, + subquery.total_referred_cash_profit, + rank() over ( + order by + subquery.total_referrals desc + ) as rank +from + ( + select + referrer.id, + count(*) as total_referrals, + sum( + ( + ( + (uphl.balance + uphl.spice_balance) + uphl.investment_value + ) - uphl.total_deposits + ) + ) as total_referred_profit, + sum( + ( + (uphl.cash_balance + uphl.cash_investment_value) - uphl.total_cash_deposits + ) + ) as total_referred_cash_profit + from + ( + ( + users referred + join users referrer on ( + ( + referrer.id = (referred.data ->> 'referredByUserId'::text) + ) + ) + ) + join user_portfolio_history_latest uphl on ((referred.id = uphl.user_id)) + ) + where + ( + (referred.data ->> 'referredByUserId'::text) is not null + ) + group by + referrer.id + ) subquery +order by + subquery.total_referrals desc; diff --git a/backend/supabase/votes.sql b/backend/supabase/votes.sql index 4d4244dae9..93df31c735 100644 --- a/backend/supabase/votes.sql +++ b/backend/supabase/votes.sql @@ -1,22 +1,14 @@ -- This file is autogenerated from regen-schema.ts - -CREATE TABLE IF NOT EXISTS votes ( - contract_id text NOT NULL, - created_time timestamp with time zone DEFAULT now() NOT NULL, - id text NOT NULL, - user_id text NOT NULL, - CONSTRAINT PRIMARY KEY (id, contract_id, user_id) -); - - - --- Row Level Security -ALTER TABLE votes ENABLE ROW LEVEL SECURITY; --- Policies -DROP POLICY IF EXISTS "Enable read access for all users" ON votes; -CREATE POLICY "Enable read access for all users" ON votes FOR SELECT USING (true) ; +create table if not exists + votes ( + contract_id text not null, + created_time timestamp with time zone default now() not null, + id text not null, + user_id text not null, + constraint primary key (id, contract_id, user_id) + ); -- Indexes -DROP INDEX IF EXISTS votes_pkey; -CREATE UNIQUE INDEX votes_pkey ON public.votes USING btree (id, contract_id, user_id); +drop index if exists votes_pkey; +create unique index votes_pkey on public.votes using btree (id, contract_id, user_id);