Add soft deletion support to async-sqlalchemy-adapter #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds soft deletion support to the async-sqlalchemy-adapter, matching the functionality available in the synchronous sqlalchemy-adapter. This resolves the feature request in issue #XX.
What is Soft Deletion?
Instead of physically deleting policy records from the database, soft deletion marks them as deleted using a boolean flag. This preserves data history and enables auditing while maintaining the same Casbin API.
Implementation
Core Changes
db_class_softdelete_attributeparameter toAdapter.__init__()_softdelete_query()helper method to filter out soft-deleted records automaticallyload_policy,load_filtered_policy,save_policy, etc.) to respect the soft delete flagremove_policy,remove_policies,remove_filtered_policy) to mark records as deleted instead of removing themUsage
To use soft deletion, define a custom database model with a boolean
is_deletedcolumn:Key Features
BooleanTesting
All 26 tests pass:
Documentation
Added complete documentation section in README.md with usage examples and feature description.
Breaking Changes
None. This is a fully backward-compatible addition. Existing code continues to work without any modifications.
Original prompt
Fixes #14
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.