skip to Main Content

I’m using postgres with my spring boot app and I want to make a specific table not delete able by anyone. Is there a way to implement this on spring boot side.

Revoking delete grant does the job on postgres side but I want to configure entity such that it won’t be delete able by anyone.

2

Answers


  1. Create a trigger on the table to prevent deletion:

    create function prevent_deletion()
    returns trigger as '
    begin
        raise exception ''deletion not allowed'';
    end;
    ' language plpgsql;
    
    
    create trigger prevent_deletion_trigger 
    before delete on mytable
    for each row 
    execute function prevent_deletion();
    

    See live demo.

    Login or Signup to reply.
  2. If you use JPA you could overload the delete methode from the Repository. None is then able to delete entries over it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search