Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I soft delete entries in casbin_rule table? #167

Closed
basimsahaf opened this issue Jun 18, 2022 · 8 comments
Closed

How do I soft delete entries in casbin_rule table? #167

basimsahaf opened this issue Jun 18, 2022 · 8 comments
Assignees
Labels

Comments

@basimsahaf
Copy link

basimsahaf commented Jun 18, 2022

I've been meaning to implement soft delete on my casbin_rule table i.e have a deactivated_at column that is set to the time it the policy was deleted instead of completing nuking the row from the table. This function called here mentions in the documentation that if the table has a DeletedAt column, it'll perform the soft delete. So I added a new column called deletedat but it didn't really work

Any ideas or tips?

@casbin-bot
Copy link
Member

@tangyang9464 @closetool @sagilio

@hsluoyz
Copy link
Member

hsluoyz commented Jun 19, 2022

@JalinWang @imp2002

/cc @tangyang9464

@tangyang9464
Copy link
Member

tangyang9464 commented Jun 19, 2022

@JalinWang @imp2002

Maybe we should allow users to customize the table structure instead of using the default CasbinRule. The current NewAdapterByDBWithCustomTable is not working, we need to improve it.

@basimsahaf
Copy link
Author

basimsahaf commented Jun 19, 2022

@tangyang9464 that would be great.

The way others can make it work while there is a permanent fix is to manually change the structure of CasbinRule, you can insert a new column (or replace any of the existing ones) called deletedat with type *time.Time gorm:"column:deletedat. If gorm sees this column, it will automatically soft delete the entries without changing anything in the implementation (https://gorm.io/docs/delete.html#Soft-Delete)

@tangyang9464
Copy link
Member

@tangyang9464 that would be great.

The way others can make it work is that if you change the structure of CasbinRule, you can insert a new column (or replace any of the existing ones) called deletedat with type *time.Time gorm:"column:createdat. If gorm sees this column, it will automatically soft delete the entries without changing anything in the implementation (https://gorm.io/docs/delete.html#Soft-Delete)

@basimsahaf This is not a generic field, so we will try to implement it through a custom structure

@basimsahaf
Copy link
Author

@tangyang9464 yeah, I wrote that answer for others so they can make this work while you come up with a fix.

@tangyang9464
Copy link
Member

@tangyang9464 yeah, I wrote that answer for others so they can make this work while you come up with a fix.

@basimsahaf This is exactly what we are looking for. Unfortunately, the gorm-adapter currently does not support adding fields

@hsluoyz
Copy link
Member

hsluoyz commented Aug 26, 2022

@basimsahaf you can implement and customze an adapter with soft-delete

@hsluoyz hsluoyz closed this as completed Aug 26, 2022
@hsluoyz hsluoyz added wontfix and removed question labels Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants