Skip to content

Commit

Permalink
run regen-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sipec committed Jul 10, 2024
1 parent c77bb6e commit 2c6094c
Show file tree
Hide file tree
Showing 126 changed files with 4,660 additions and 2,705 deletions.
76 changes: 44 additions & 32 deletions backend/supabase/answers.sql
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
-- This file is autogenerated from regen-schema.ts
create table if not exists
answers (
id text not null primary key default random alphanumeric (12),
index int, -- Order of the answer in the list
contract_id text, -- Associated contract
user_id text, -- Creator of the answer
id text default random_alphanumeric (12) not null,
contract_id text,
user_id text,
text text,
created_time timestamptz default now(),
-- Mechanism props
pool_yes numeric, -- YES shares in the pool
pool_no numeric, -- NO shares in the pool
prob numeric, -- Probability of YES computed from pool_yes and pool_no
total_liquidity numeric default 0, -- for historical reasons, this the total subsidy amount added in M
subsidy_pool numeric default 0, -- current value of subsidy pool in M
created_time timestamp with time zone default now(),
pool_yes numeric,
pool_no numeric,
prob numeric,
data jsonb not null,
text_fts tsvector generated always as (to_tsvector('english', text)) stored,
prob_change_day numeric default 0, -- change in prob in the last 24h
prob_change_week numeric default 0, -- change in prob in the last week
prob_change_month numeric default 0 -- change in prob in the last month
index integer,
total_liquidity numeric default 0,
subsidy_pool numeric default 0,
text_fts tsvector generated always as (to_tsvector('english'::regconfig, text)) stored,
prob_change_day numeric default 0,
prob_change_week numeric default 0,
prob_change_month numeric default 0
);

create index if not exists answer_text_fts on answers using gin (text_fts);

create index if not exists answer_contract_id on answers (contract_id);

alter table answers enable row level security;

drop policy if exists "public read" on answers;

create policy "public read" on answers for
select
using (true);
-- Triggers
create trigger answers_populate before insert
or
update on public.answers for each row
execute function answers_populate_cols ();

-- Functions
create
or replace function answers_populate_cols () returns trigger language plpgsql as $$
or replace function public.answers_populate_cols () returns trigger language plpgsql as $function$
begin
if new.data is not null then
new.index := ((new.data) ->> 'index')::int;
Expand All @@ -53,9 +48,26 @@ begin
end if;
return new;
end
$$;
$function$;

create trigger answers_populate before insert
or
update on answers for each row
execute function answers_populate_cols ();
-- Policies
alter table answers enable row level security;

drop policy if exists "public read" on answers;

create policy "public read" on answers for
select
using (true);

-- Indexes
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);
17 changes: 12 additions & 5 deletions backend/supabase/audit_events.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
-- This file is autogenerated from regen-schema.ts
create table if not exists
audit_events (
id bigint generated always as identity primary key,
created_time timestamptz not null default now(),
id bigint not null,
created_time timestamp with time zone default now() not null,
name text not null,
user_id text not null,
contract_id text null,
comment_id text null,
data jsonb null
contract_id text,
comment_id text,
data jsonb
);

-- Policies
alter table audit_events enable row level security;

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);
51 changes: 32 additions & 19 deletions backend/supabase/chart_annotations.sql
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
-- This file is autogenerated from regen-schema.ts
create table if not exists
chart_annotations (
id bigint generated always as identity primary key,
created_time timestamptz not null default now(),
chart_annotations (
id bigint not null,
created_time timestamp with time zone default now() not null,
event_time bigint not null,
contract_id text not null,
creator_id text not null,
creator_username text not null,
creator_name text not null,
creator_avatar_url text not null,
up_votes integer not null default 0,
down_votes integer not null default 0,
up_votes integer default 0 not null,
down_votes integer default 0 not null,
comment_id text,
thumbnail_url text,
external_url text,
text text,
answer_id text,
user_username text,
user_name text,
user_avatar_url text,
user_id text,
prob_change numeric,
constraint chart_annotations_prob_change_check check (
(
(prob_change >= ('-1'::integer)::numeric)
and (prob_change <= (1)::numeric)
)
)
);

prob_change numeric null check (prob_change >= -1 and prob_change <= 1),
user_username text null,
user_name text null,
user_avatar_url text null,
user_id text null,
comment_id text null,
answer_id text null,
thumbnail_url text null,
external_url text null,
text text null
);
-- Policies
alter table chart_annotations enable row level security;

drop policy if exists "public read" on chart_annotations;

create policy "public read" on chart_annotations using (true);
create policy "public read" on chart_annotations for all using (true);

create index if not exists contract_annotations_event_time
on chart_annotations (contract_id, event_time asc);
-- 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);
33 changes: 17 additions & 16 deletions backend/supabase/chat_messages.sql
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@

-- This file is autogenerated from regen-schema.ts
create table if not exists
chat_messages (
id serial primary key,
user_id text not null,
channel_id text not null,
content jsonb not null,
created_time timestamptz not null default now()
);
chat_messages (
id integer not null,
user_id text not null,
channel_id text not null,
content jsonb not null,
created_time timestamp with time zone default now() not null
);

-- Policies
alter table chat_messages enable row level security;

drop policy if exists "public read" on chat_messages;

create policy "public read" on chat_messages for
select
using (true);
create index if not exists chat_messages_channel_id
on chat_messages (channel_id, id desc);
select
using (true);

-- Indexes
drop index if exists chat_messages_pkey;

alter table chat_messages
cluster on chat_messages_channel_id;
create unique index chat_messages_pkey on public.chat_messages using btree (id);

alter publication supabase_realtime
add table chat_messages;
drop index if exists chat_messages_channel_id;

create index chat_messages_channel_id on public.chat_messages using btree (channel_id, id desc);
94 changes: 0 additions & 94 deletions backend/supabase/comments/functions.sql

This file was deleted.

2 changes: 0 additions & 2 deletions backend/supabase/comments/indexes.sql

This file was deleted.

17 changes: 0 additions & 17 deletions backend/supabase/comments/triggers.sql

This file was deleted.

Loading

0 comments on commit 2c6094c

Please sign in to comment.