Skip to content

Commit

Permalink
revert supabase automatic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ingawei committed Dec 6, 2024
1 parent 3618e97 commit 93967fe
Show file tree
Hide file tree
Showing 93 changed files with 2,767 additions and 2,346 deletions.
76 changes: 41 additions & 35 deletions backend/supabase/answers.sql
Original file line number Diff line number Diff line change
@@ -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);
36 changes: 19 additions & 17 deletions backend/supabase/audit_events.sql
Original file line number Diff line number Diff line change
@@ -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);
65 changes: 36 additions & 29 deletions backend/supabase/chart_annotations.sql
Original file line number Diff line number Diff line change
@@ -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);
28 changes: 28 additions & 0 deletions backend/supabase/chat_messages.sql
Original file line number Diff line number Diff line change
@@ -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);
129 changes: 77 additions & 52 deletions backend/supabase/contract_bets.sql
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Loading

0 comments on commit 93967fe

Please sign in to comment.