Dynamic RLS generation for a dataset

We have a dataset file with the following values

category_id, value
1, Test1
2, Test2
1, Test3
3, Test4

We have RLS file defined with the following

username, category_id

This is working perfectly fine and the data is restricted based on RLS

This is integrated into our application as an embedded URL which is generated by calling the generate_embed_url_for_registered_user.

Now we are planning to implement the following

Say an user 3 onboards into our platform and based on his eligibility / preference the categories that he can view is determined in the platform. Now the ask is that we need to update the RLS file dynamically.

We are using Ruby on Rails and use Ruby’s SDK to generate the embedded URL based on the logged in user. Is there any way to automate the following in Ruby on rails once the user onboards in our platform.

  1. fetch the RLS file (csv & user based) for the dataset used by the dashboard
  2. update the RLS file with the new user Id & category Id
  3. publish the RLS file
  4. Associate the RLS against the dataset

I would suggest trying to turn this RLS file into a table in database, where you can write updates to it. Or even have it in s3 and then you could update that file with AWS apis.