jason-lynx
02/09/2022, 3:15 AMSET request.jwt.claim.sub = 'MY USER ID';
SET ROLE authenticated;
zecik11
02/09/2022, 7:54 AMError: Error resetting database: ERROR: could not open file "./my-file.csv" for reading: No such file or directory
HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy.
osaxma
02/09/2022, 10:27 AMCOPY
with stdin
in the seed file.
I created a separate manual_seed.sql
that I feed the database after each supabase start
or supabase db reset
using psql
sql
psql postgresql://postgres:postgres@localhost:54322/postgres < manual_seed.sql
^ something like that may helpzecik11
02/09/2022, 10:28 AMCarloshs94
02/09/2022, 11:48 AMmadx
02/09/2022, 7:11 PMInfrapuna
02/12/2022, 7:55 PM(( SELECT user_roles.admin
FROM user_roles
WHERE (uid() = user_roles.id)) = true)
I am trying to subquery the role (which is currently a boolean value in column "admin"). The above I tried does not work.Infrapuna
02/12/2022, 8:39 PMgaryaustin
02/12/2022, 8:42 PMstelofo
02/14/2022, 2:17 PMstelofo
02/14/2022, 2:20 PMsilentworks
02/14/2022, 3:39 PMDenzo
02/17/2022, 10:22 AMsql
create or replace function create_planet(new_planet "planet")
returns varchar
language plpgsql
as $$
declare
new_row bigint;
begin
insert into public."planets"(new_planet)
values(new_planet)
returning "id" into new_row;
return new_row;
end;
$$
Arosh
02/18/2022, 3:14 PMTremalJack
02/18/2022, 4:15 PMsilentworks
02/18/2022, 4:23 PMdmytro.eth
02/21/2022, 9:27 AMauth.users
table so that I can reference both native auth and my auth users from the same table. I dont get how to add documents into auth.users
. Should it be some custom trigger?KirioXX
02/21/2022, 2:41 PMErwin
02/21/2022, 7:23 PMcontributors
table that maps user_id
to document_id
Two solutions I have so far:
1. Define policies that perform joins to find the document_id
and check that the user is a contributor of the document. At the deepest level, this is a join across 5 tables (4 levels + contributors table) within RLS policies.
2. Keep a document_id
column for entities at each level of the hierarchy, since that value will never change after creation anyways. Breaks normalization, but RLS policies become very simple & efficient.
So far, I'm leaning towards 2. but would love input from people with more experience!silentworks
02/21/2022, 7:40 PMJoão Vitor
02/21/2022, 8:27 PMJoão Vitor
02/21/2022, 8:27 PMgaryaustin
02/21/2022, 9:04 PMdmytro.eth
02/22/2022, 10:36 AMdmytro.eth
02/22/2022, 2:03 PMWITH CHECK
to this policy as well?Erwin
02/22/2022, 11:12 PMauth.users.raw_user_meta_data
in a trigger. I save a user name in there during sign up and use it to populate a profile.
Here's the trigger:
pgsql
create function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
begin
insert into public.users(id, user_name, email)
-- this works, but populates the `user_name` column with quoted text (as expected)
values (new.id, new.raw_user_meta_data->'user_name', new.email);
-- this does not work:
-- values (new.id, new.raw_user_meta_data->>'user_name', new.email);
return null;
end;
$$;
create trigger on_new_user after insert on auth.users
for each row execute function public.handle_new_user();
For some reason, using the ->>
operator to extract the value as unquoted text seems to trigger a database error. Anyone has an idea why?Erwin
02/23/2022, 1:02 AMextensions
to search_path
did the trick. If someone knows why, I'm interested in the explanation!discoding
02/24/2022, 6:30 AMrequests
and tasks
. The requests table contains requests to run tasks. A request will have a status of pending
or approved
or rejected
.
How do I write a policy that prevents anyone from inserting a request for task when a similar request with a same task id have a status pending
?
Thenkssylar815
02/24/2022, 8:04 AMErwin
02/24/2022, 11:04 AMpgsql
create policy "Do not schedule tasks twice"
on requests for insert
with check (
not exists (
select 1
from requests as reqs
where reqs.status = 'pending' and reqs.task_id = task_id
)
);