From 470dc1e16874b51882d79028ae22c6e89865b446 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 14:30:56 +0000 Subject: [PATCH 1/3] Initial plan From c7187b0006b827845da1e7eb864a9e50d148dd78 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 14:32:54 +0000 Subject: [PATCH 2/3] Add Alembic integration documentation Co-authored-by: mserico <140243407+mserico@users.noreply.github.com> --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 498c3fe..8d4d049 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,41 @@ else: > Note that AsyncAdaper must be used for AynscEnforcer. +## Alembic Integration + +For production applications, you'll want to manage database schema using Alembic migrations instead of calling `create_table()` at runtime. The adapter provides `create_casbin_rule_model()` to integrate with your existing migration workflow. + +```python +# In your alembic/env.py or models file +from casbin_async_sqlalchemy_adapter import create_casbin_rule_model +from sqlalchemy.ext.declarative import declarative_base + +# Use your application's declarative base +Base = declarative_base() + +# Create the CasbinRule model using your base +CasbinRule = create_casbin_rule_model(Base) + +# Now Alembic can auto-generate migrations for the casbin_rule table +# Run: alembic revision --autogenerate -m "Add casbin_rule table" +# Then: alembic upgrade head +``` + +When using the adapter with Alembic-managed tables, pass your custom model: + +```python +from your_app.models import CasbinRule +import casbin_async_sqlalchemy_adapter +import casbin + +adapter = casbin_async_sqlalchemy_adapter.Adapter( + 'sqlite+aiosqlite:///test.db', + db_class=CasbinRule +) + +e = casbin.AsyncEnforcer('path/to/model.conf', adapter) +``` + ## External Session Support The adapter supports using externally managed SQLAlchemy sessions. This feature is useful for: From 8a64a04aa03e79755a3b8693d99c06ac895aaf19 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 14:33:29 +0000 Subject: [PATCH 3/3] Fix typo in AsyncAdapter and AsyncEnforcer Co-authored-by: mserico <140243407+mserico@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d4d049..28dda68 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ else: pass ``` -> Note that AsyncAdaper must be used for AynscEnforcer. +> Note that AsyncAdapter must be used for AsyncEnforcer. ## Alembic Integration