Multi-Database and Schema Workflow
March 5, 2026 ยท View on GitHub
Use this tutorial when your application needs:
- multiple databases (
registry.extra), or - per-tenant/per-schema query context.
Choosing the Right Path
flowchart TD
A["Need isolated data path"] --> B{"Different database server?"}
B -- Yes --> C["Use registry.extra + using(database=...)"]
B -- No --> D{"Same database, different schema?"}
D -- Yes --> E["Use using(schema=...) / with_schema(...)"]
D -- No --> F["Use default registry database/schema"]
Step 1: Declare Multiple Databases
{!> ../docs_src/registry/extra/declaration.py !}
Step 2: Write Data to an Extra Database
{!> ../docs_src/registry/extra/create.py !}
Step 3: Use Schema Context for Tenant-Like Routing
For schema-scoped operations:
from edgy.core.db import with_schema
with with_schema("tenant_a"):
users = await User.query.all()
Or explicitly per query:
users = await User.query.using(schema="tenant_a").all()
Operational Notes
- Keep registry lifecycle open (
async with registry:) while serving requests. - Ensure target schemas exist before querying them.
- Keep database names in
using(database=...)aligned withregistry.extrakeys.