Pragy
11/04/2021, 6:44 PMset role authenticated;
when logging in via the db client, select current_user, session_user; gives postgres, postgreschipilov
11/04/2021, 6:55 PMPragy
11/05/2021, 2:23 PMsql
set role postgres;
select current_user, session_user;
drop table if exists public.profiles;
create table public.profiles
(
    user_id   uuid primary key references auth.users,
    full_name text,
    is_public boolean default true
);
insert into public.profiles values ('717cd048-5cf6-4d51-b43e-e71ae1ade721', 'Pragy Agarwal', true);
select * from public.profiles;
Output
postgres,postgres
717cd048-5cf6-4d51-b43e-e71ae1ade721,Pragy Agarwal,true
But when I switch to the authenticated role
sql
begin;
    set local role authenticated;
    set local request.jwt.claim.sub = '717cd048-5cf6-4d51-b43e-e71ae1ade721';
    select current_user, session_user;
    select auth.uid();
    select * from profiles;
end;
output
authenticated,postgres
717cd048-5cf6-4d51-b43e-e71ae1ade721
ERROR: relation "profiles" does not exist
The role switch works, but I can't access the table.
Edit: Resolved
Turns out, that deleting and re-creating the public schema is a bad idea as it removes all the permissions and roles setup that PostgREST needs to work ๐
silentworks
11/05/2021, 5:02 PMpublic)Pragy
11/05/2021, 5:51 PMPragy
11/05/2021, 6:24 PMnew.raw_user_meta_data->>'avatar_url'
- new.raw_user_meta_data->>'full_name'
- uuid_generate_v4()
- uuid_generate_v4()::text
weirdly, random()::text works though
any way to generate the same random value for 2 columns when inserting a value via sql?silentworks
11/05/2021, 6:35 PMjbergius
11/05/2021, 7:13 PMPragy
11/05/2021, 7:16 PMjbergius
11/05/2021, 7:24 PMPragy
11/05/2021, 7:25 PMjbergius
11/05/2021, 7:52 PMstibbs
11/07/2021, 10:58 PMsql
CREATE TABLE jobs (
  id uuid DEFAULT uuid_generate_v4 () primary key,
  invoice_id uuid references public.invoices not null,
  user_id uuid references auth.users not null,
  application_url text,
  business_name text not null,
  content_description text not null,
  content_how_to_apply text not null,
  content_who text not null,
  job_location text,
  job_type text not null,
  title text not null,
  timezone text,
  work_style text not null,
  valid_until timestamp with time zone,
);
The confusing bit to me is that in this table you either populate job job_location OR timezone depending on the value in work_style
I have no idea if I'm on the right path, but so far I have:
sql
insert into public.jobs (
  invoice_id,
  user_id,
  application_url,
  business_name,
  content_description,
  content_how_to_apply,
  content_who,
  job_location,
  job_type,
  title,
  timezone,
  work_style,
  valid_until
)
select 
  'manually created invoice_id',
  'manually created user_id',
  'https://www.google.com',
  MD5(random()::text), -- business_name
  MD5(random()::text), -- content_description
  MD5(random()::text), -- content_how_to_apply
  MD5(random()::text), -- content_who
  -- how do i make some populate job_location?
  'ft', -- job_type
  MD5(random()::text), -- title
  -- how do i make some populate timezone?
  -- work_style needs to be 'remote' or 'flex'
  now() + interval '5 day'
from generate_series(1, 100);stibbs
11/07/2021, 11:11 PMsilentworks
11/08/2021, 1:42 AMauth.users table and the only error I'm getting is "Database error saving new user" while I was expecting the message from the exception to show instead.stibbs
11/08/2021, 9:08 AMcase or if then logic in a postgres generated column?stibbs
11/08/2021, 9:20 AMsql
-- currently like this
priority smallint default 0
-- I want to change it to something like this
priority smallint generated always as (if x is not null and y is not null then 1 else 0 end) stored;silentworks
11/08/2021, 11:12 AMScott P
11/08/2021, 3:17 PMP4l4cz
11/09/2021, 12:44 PMMike92988
11/10/2021, 1:29 PMsilentworks
11/10/2021, 1:42 PMApfelsaft
11/10/2021, 10:16 PMApfelsaft
11/10/2021, 10:21 PMTodd
11/11/2021, 2:54 AMVictor Peralta
11/11/2021, 4:34 AMsilentworks
11/11/2021, 9:24 AMTodd
11/11/2021, 11:37 AMsilentworks
11/11/2021, 12:05 PM