In user role management I use a separate database to store the different roles.
A single user from users database can have multiple roles linked as multiple rows column.
If I delete a role from a database (row deletion) the link appears as deleted row. Is there a way to handle the deletion of this rows quickly, because they cause errors.
Atm. I can think only of searching the users, that have that role and removing it by updating each single row, before I delete the role row.
The time it requires increases with the ammount of users and in that case maybe it would require to move it to the background task.
It would be automatic, if the role pointed at its grantees (users).
But as-is, you’re going to have to query all users, to see which ones have the disappearing role. As far as I can tell, Anvil does not provide SQL-style database-level referential-integrity constraints. We have to code those for ourselves, in Python.
Thankfully it is only one class on server side using it and I can add try: / except: to handle it and let background task to clean it up later
try:
#......
except anvil.tables.RowDeleted:
pass
Cleaning it will require me to loop all users and go though all links in order to find the deleted rows and then remove it. Query on that deleted row in multi link column requires a list of row objects. I don’t have that row anymore