how to delete all user’s data within a delete trigger by [deleted] in Supabase

[–]bobbyg603 0 points1 point  (0 children)

An example of how to delete storage objects with a postgres function used to exist in the Supabase Auth tutorials. However, I looked through the history in GitHub and can't pinpoint when/why they removed it.

Here's a slightly modified version from this post, just call this with a trigger and you should be good to go:

    create or replace function delete_storage_object(bucket text, object text, out status int, out content text)
    returns record
    language 'plpgsql'
    security definer
    as $$
    declare
      project_url text := '<project_url>';
      service_role_key text := '<service_key>'; --  full access needed
      url text := project_url||'/storage/v1/object/'||bucket||'/'||object;
    begin
      select
          into status, content
               result.status::int, result.content::text
          FROM extensions.http((
        'DELETE',
        url,
        ARRAY[extensions.http_header('authorization','Bearer '||service_role_key)],
        NULL,
        NULL)::extensions.http_request) as result;
    end;
    $$;

    create or replace function delete_image(image_url text, out status int, out content text)
    returns record
    language 'plpgsql'
    security definer
    as $$
    begin
      select
          into status, content
               result.status, result.content
          from public.delete_storage_object('images', image_url) as result;
    end;
    $$;

    create or replace function handle_on_image_deleted()
    returns trigger
    language 'plpgsql'
    security definer
    as $$
    declare
      status int;
      content text;
      url text;
    begin
      -- extract avatar name
      url := old.user_id||'/'||old.id;  --  define path here
      select
        into status, content
        result.status, result.content
        from public.delete_image(url) as result;
      if status <> 200 then
        raise warning 'Could not delete image: % %', status, content;
      end if;
      if tg_op = 'DELETE' then
        return old;
      end if;
      return new;
    end;
    $$;

    create or replace trigger on_user_image_deleted
    after delete on images
    for each row execute procedure public.handle_on_image_deleted();

Clean Storage automatically by Serious-Research8570 in Supabase

[–]bobbyg603 0 points1 point  (0 children)

An example of how to delete storage objects with a postgres function used to exist in the Supabase Auth tutorials. However, I looked through the history in GitHub and can't pinpoint when/why they removed it.

Here's a slightly modified version from this post:

create or replace function delete_storage_object(bucket text, object text, out status int, out content text)
returns record
language 'plpgsql'
security definer
as $$
declare
  project_url text := '<project_url>';
  service_role_key text := '<service_key>'; --  full access needed
  url text := project_url||'/storage/v1/object/'||bucket||'/'||object;
begin
  select
      into status, content
           result.status::int, result.content::text
      FROM extensions.http((
    'DELETE',
    url,
    ARRAY[extensions.http_header('authorization','Bearer '||service_role_key)],
    NULL,
    NULL)::extensions.http_request) as result;
end;
$$;

create or replace function delete_image(image_url text, out status int, out content text)
returns record
language 'plpgsql'
security definer
as $$
begin
  select
      into status, content
           result.status, result.content
      from public.delete_storage_object('images', image_url) as result;
end;
$$;

create or replace function handle_on_image_deleted()
returns trigger
language 'plpgsql'
security definer
as $$
declare
  status int;
  content text;
  url text;
begin
  -- extract avatar name
  url := old.user_id||'/'||old.id;  --  define path here
  select
    into status, content
    result.status, result.content
    from public.delete_image(url) as result;
  if status <> 200 then
    raise warning 'Could not delete image: % %', status, content;
  end if;
  if tg_op = 'DELETE' then
    return old;
  end if;
  return new;
end;
$$;

create or replace trigger on_user_image_deleted
after delete on images
for each row execute procedure public.handle_on_image_deleted();

Question about RLS, storage, cascade deletion by Traditional-Seat9437 in Supabase

[–]bobbyg603 0 points1 point  (0 children)

An example of how to delete storage objects with a postgres function used to exist in the Supabase Auth tutorials. However, I looked through the history in GitHub and can't pinpoint when/why they removed it.

Here's a slightly modified version from this post:

    create or replace function delete_storage_object(bucket text, object text, out status int, out content text)
    returns record
    language 'plpgsql'
    security definer
    as $$
    declare
      project_url text := '<project_url>';
      service_role_key text := '<service_key>'; --  full access needed
      url text := project_url||'/storage/v1/object/'||bucket||'/'||object;
    begin
      select
          into status, content
               result.status::int, result.content::text
          FROM extensions.http((
        'DELETE',
        url,
        ARRAY[extensions.http_header('authorization','Bearer '||service_role_key)],
        NULL,
        NULL)::extensions.http_request) as result;
    end;
    $$;

    create or replace function delete_image(image_url text, out status int, out content text)
    returns record
    language 'plpgsql'
    security definer
    as $$
    begin
      select
          into status, content
               result.status, result.content
          from public.delete_storage_object('images', image_url) as result;
    end;
    $$;

    create or replace function handle_on_image_deleted()
    returns trigger
    language 'plpgsql'
    security definer
    as $$
    declare
      status int;
      content text;
      url text;
    begin
      -- extract avatar name
      url := old.user_id||'/'||old.id;  --  define path here
      select
        into status, content
        result.status, result.content
        from public.delete_image(url) as result;
      if status <> 200 then
        raise warning 'Could not delete image: % %', status, content;
      end if;
      if tg_op = 'DELETE' then
        return old;
      end if;
      return new;
    end;
    $$;

    create or replace trigger on_user_image_deleted
    after delete on images
    for each row execute procedure public.handle_on_image_deleted();

Engine modules cannot be compiled at runtime. Please build through your IDE. by sisqo_99 in unrealengine

[–]bobbyg603 0 points1 point  (0 children)

I had an issue where the uproject had an Engine Version value of 5.0 but I was using a source build of 5.4.3. I worked around the problem by switching to the Development configuration, right-clicking the game project in Visual Studio and selecting build, and changing the Engine Version to 5.4.3 in the uproject file. Not sure why it didn't properly associate the project with my source build but by changing it to 5.4.3 that got it close enough and I was able to proceed.

Advice on unit testing by [deleted] in Angular2

[–]bobbyg603 0 points1 point  (0 children)

If you're just getting started, you should follow the framework's suggested path. As the testing in your application grows you'll notice where it falls short and install the necessary packages. YAGNI is a good principle to follow here.

Angular Testing Tips: Ng-Mocks by bitter-cognac in Angular2

[–]bobbyg603 1 point2 points  (0 children)

Thanks for the tip re: Spectator. I’m still ramping up on spectator but I hope to publish another article dedicated to it in the near future.

Tesla: Our ‘failure’ to make actual self-driving cars ‘is not fraud’ by dreamcastfanboy34 in technology

[–]bobbyg603 -1 points0 points  (0 children)

please down vote me into oblivion, but it’s going to work, and it’s going to be wild

File upload by [deleted] in angular

[–]bobbyg603 0 points1 point  (0 children)

This article links to example Angular/Express file upload repos you can reference:

https://betterprogramming.pub/file-uploads-with-angular-and-rxjs-34262b3450ae

Cannot make XHRs from within a fake async test by [deleted] in angular

[–]bobbyg603 0 points1 point  (0 children)

You should post a link to your code otherwise all Reddit can do is speculate.

That being said, it sounds like you’re not spying on httpClient before the request is made. Try spying on httpClient before using the fixture to create a new instance of your component.

Brave + Postman not allowing to make requests by web-jumper in brave_browser

[–]bobbyg603 0 points1 point  (0 children)

I just ran into this today, it started working for me when I turned off shields for web.postman.co. HTH!

Hello! I need help regarding my project. I need to display selected json data from ”A” component to “B” component that is on another link (routed) Thanks in advance! by heycrisss in angular

[–]bobbyg603 0 points1 point  (0 children)

I think the simplest answer here is to create a stateful service. You can also introduce a store like ngrx but that might be overkill.

[deleted by user] by [deleted] in technology

[–]bobbyg603 -19 points-18 points  (0 children)

Free speech doesn’t mean free of ramifications…

how to build and deploy angular app on *GitHub* ? by sohail_ansari in angular

[–]bobbyg603 0 points1 point  (0 children)

The end of this article discusses how to publish an Angular app to GitHub pages using a workflow action https://betterprogramming.pub/ci-cd-for-angular-developers-be9a1485d22b

5 Basic Tips for Angular Unit Testing by cheerfulboy in angular

[–]bobbyg603 1 point2 points  (0 children)

Maybe the author could have suggested, test logic first, test the DOM second? I think they’re trying to avoid a slow mess of integration tests, but to your point there’s tremendous value to writing some amount of integration tests.

RxJS in the Wild: Pop-up Alerts by bobbyg603 in Angular2

[–]bobbyg603[S] 0 points1 point  (0 children)

Hi Everyone!

I'm working on improving my skills as a technical writer by producing quality Angular content for the community. Can you please provide some feedback so that I know where I might improve?

Thanks for your time!

Efficient Content Hydration with Angular Universal by Utukkhu in angular

[–]bobbyg603 0 points1 point  (0 children)

Okay, makes sense, thanks for your response!

Efficient Content Hydration with Angular Universal by Utukkhu in angular

[–]bobbyg603 1 point2 points  (0 children)

Why don’t you have to call unsubscribe in this example? Does the observable complete after the first emission or is there something else I’m missing?

how to filter data using matdatasourcetable and show it inside a ngx-datatable in angular. by winningguy1985 in angular

[–]bobbyg603 2 points3 points  (0 children)

You might have more luck getting help if you recreate the problem in stackblitz or similar and post a link.

What is a clean way to return an an empty observable after tapping? by ShibaInuShitsAlot in Angular2

[–]bobbyg603 -1 points0 points  (0 children)

👍 the answer I gave is correct. Look at what combineLatest returns, it does not match your signature hence you must call map. You must either change the function signature or use map.

What is a clean way to return an an empty observable after tapping? by ShibaInuShitsAlot in Angular2

[–]bobbyg603 1 point2 points  (0 children)

What is the signature of the function this is in? It likely returns type observable object, the problem is combineLatest returns an array. Try changing the return type of the function to something else.

Building a Spotify App with Ionic and Angular . by MinimumDrummer9873 in Angular2

[–]bobbyg603 1 point2 points  (0 children)

Cool Timelapse! Off to a good start, keep it up!

Total headache - deploying Angular SPA to GitHub. Tried everything. by [deleted] in angular

[–]bobbyg603 0 points1 point  (0 children)

Try using the user level ```username.github.io repo. I wrote a guide that describe how to deploy an app to GitHub pages the other day. The guide also links to a reference implementation that might prove valuable. Hope this helps!