Todd
11/11/2021, 1:39 PMmaxbaluev
11/12/2021, 7:48 AMcreate policy "Can update own user data." on users for update using (auth.uid() = id);
Question - how can I additionally forbid a user to change balance(num) cell in users_data table by using policy?chipilov
11/12/2021, 7:53 AMNander
11/12/2021, 9:10 PMtable_name too) but it doesn't work. Can somebody help me (ping appreciated)garyaustin
11/12/2021, 9:18 PMNander
11/12/2021, 9:21 PMgaryaustin
11/12/2021, 9:26 PMNander
11/12/2021, 9:27 PMfor each row, went through without errors but i have to check if it actually checks the bucket_id nowNander
11/12/2021, 9:28 PMNander
11/12/2021, 9:35 PMNander
11/12/2021, 9:36 PMNander
11/13/2021, 2:16 PMpath_tokens, so my approach was to modify it in the function.
sql
create or replace function
  public.create_post_on_bucket_upload()
  returns trigger as
  $$
  declare
    post_id text;
  begin
    insert into public.posts (user_id)
    values (
      auth.uid()
    )
    returning id into post_id;
    new.path_tokens[2] = post_id;
    return new;
  end;
  $$ language plpgsql security definer;
it creates the function and I can run the upload process on my website, but the file name/location doesn't change. What did I do wrong?silentworks
11/13/2021, 2:45 PMjon.m
11/13/2021, 11:29 PMstibbs
11/16/2021, 3:30 AMsql
create or replace function count_open_jobs(out job_count integer)
returns integer
language plpgsql
as $$
begin
  select count(*) into job_count
  from public.jobs
  where valid_until > now()
    and closed = false;
end; $$
In my code I have
js
// in my db.js file, call the plpgsql function
export const countOpenJobs = async () => {
  return supabase.rpc('count_open_jobs');
};
// this bit is in my SvelteKit endpoint
const result = await countOpenJobs();
const count = result.data['job_count'];
Example response when it works is
json
{
  "error": null,     
  "data": {
    "job_count": 94  
  },
  "count": null,     
  "status": 200,     
  "statusText": "OK",
  "body": {
    "job_count": 94
  }
}stibbs
11/16/2021, 9:18 AMstibbs
11/16/2021, 9:18 AMchipilov
11/16/2021, 9:22 AMstibbs
11/16/2021, 9:23 AMstibbs
11/16/2021, 9:23 AMchipilov
11/16/2021, 9:24 AMchipilov
11/16/2021, 9:24 AMCREATE VIEW public.count_open_jobs AS
SELECT count(*)
FROM public.jobs
WHERE valid_until > now() AND close = false;
-- Then you call it like this (or using the supabase client as if querying a table)
SELECT * from public.count_open_jobs;chipilov
11/16/2021, 9:25 AMstibbs
11/16/2021, 9:34 AMstibbs
11/16/2021, 9:34 AMstibbs
11/16/2021, 9:34 AMchipilov
11/16/2021, 9:39 AMchipilov
11/16/2021, 9:39 AMsupabase.from('jobs')
      .select(undefined, { head: true, count: 'exact' })
      .eq('close', false)
      .gt('valid_until', now());stibbs
11/16/2021, 9:39 AMstibbs
11/16/2021, 9:39 AM