Skip to content

Commit

Permalink
Inga/supabase search replacement (manifoldmarkets#1652)
Browse files Browse the repository at this point in the history
* Jk, just rbac and moving around files for now
  • Loading branch information
ingawei authored Mar 30, 2023
1 parent 7aedb21 commit ae802d9
Show file tree
Hide file tree
Showing 12 changed files with 933 additions and 589 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[sql]": {
"editor.defaultFormatter": "mtxr.sqltools"
}
}
6 changes: 6 additions & 0 deletions backend/supabase/contracts/create-question-fts-col.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
alter table public.contracts
add column question_fts tsvector generated always as (
to_tsvector('english', description || ' ' || title)
) stored;
create index if not exists question_fts on contracts using gin (question_fts);
-- generate the index
16 changes: 16 additions & 0 deletions backend/supabase/contracts/functions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
create or replace function can_access_contract(contract_id text, member_id text) returns boolean stable parallel safe language sql as $$
select EXISTS (
SELECT 1
FROM (
group_members
JOIN group_contracts ON (
(
group_members.group_id = group_contracts.group_id
)
)
)
WHERE (
(group_contracts.contract_id = contract_id)
AND (group_members.member_id = member_id)
)
) $$;
8 changes: 8 additions & 0 deletions backend/supabase/contracts/indexes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
create index if not exists contracts_data_gin on contracts using GIN (data);
create index if not exists contracts_group_slugs_gin on contracts using GIN ((data->'groupSlugs'));
create index if not exists contracts_slug on contracts (slug);
create index if not exists contracts_creator_id on contracts (creator_id, created_time);
create index if not exists contracts_created_time on contracts (created_time desc);
create index if not exists contracts_close_time on contracts (close_time desc);
create index if not exists contracts_unique_bettors on contracts (((data->'uniqueBettors7Days')::int) desc);
create index if not exists contracts_popularity_score on contracts (((data->>'popularityScore')::real) desc);
11 changes: 11 additions & 0 deletions backend/supabase/contracts/rls.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- ALTER TABLE public.contracts ENABLE ROW LEVEL SECURITY;

drop policy if exists "enable read access all public/unlisted markets" on public.contracts;
CREATE POLICY "Enable read access all public/unlisted markets" ON public.contracts FOR
SELECT USING ((visibility <> 'private'::text));

drop policy if exists "Enable read access for admins" ON public.contracts;
CREATE POLICY "Enable read access for admins" ON public.contracts FOR SELECT TO service_role USING (true);

drop policy if exists "Enable read access for private group markets if user is member" ON public.contracts;
CREATE POLICY "Enable read access for private group markets if user is member" ON public.contracts FOR SELECT USING ((visibility = 'private'::text));
Loading

0 comments on commit ae802d9

Please sign in to comment.