forked from manifoldmarkets/manifold
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inga/supabase search replacement (manifoldmarkets#1652)
* Jk, just rbac and moving around files for now
- Loading branch information
Showing
12 changed files
with
933 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
) $$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Oops, something went wrong.