predikt/oracle/backend/supabase/user_contract_views.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

60 lines
2.1 KiB
SQL

-- 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)
)
)
);
-- 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 ())
)
);
-- 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;