predikt/oracle/backend/supabase/contract_comments.sql
caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

78 lines
2.4 KiB
PL/PgSQL

-- 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,
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 ();
-- Functions
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
when new.data ? 'createdTime' then millis_to_ts(((new.data)->>'createdTime')::bigint)
else null
end;
end if;
return new;
end $function$;
-- 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);
-- 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_public_created_time_idx;
create index contract_comments_public_created_time_idx on public.contract_comments using btree (created_time desc)
where
(visibility = 'public'::text);
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);