Skip to content

Commit a568762

Browse files
committed
reframe README around schemas instead of tenants
1 parent 29d967c commit a568762

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

README.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# django-fqq
22

3-
Lightweight PostgreSQL schema-based multi-tenancy for Django.
3+
Generate schema-prefixed table names with the Django ORM.
44

5-
django-fqq automatically qualifies table names with the appropriate PostgreSQL schema, routing queries to tenant-specific schemas using a simple `ContextVar`-based approach. Shared tables (like `auth`) stay in `public`, while tenant tables are directed to the active schema.
6-
7-
## How it works
8-
9-
django-fqq provides a custom database backend that wraps Django's built-in PostgreSQL backend. It overrides `quote_name` to prepend the active schema to table names — so `"my_table"` becomes `"tenant_schema"."my_table"` automatically. No changes to your models or queries required.
5+
django-fqq provides a custom database backend that wraps Django's built-in PostgreSQL backend. It overrides `quote_name` to prepend the active schema to table names — so `"my_table"` becomes `"my_schema"."my_table"` automatically. No changes to your models or queries required.
106

117
django-fqq does not modify queries if `set_schema` has not been called or has been set to a falsy value (e.g. None or "").
128

@@ -39,9 +35,9 @@ INSTALLED_APPS = [
3935
]
4036
```
4137

42-
### 3. Configure shared apps
38+
### 3. Configure shared apps (optional)
4339

44-
Apps listed in `FQQ_SHARED_APPS` will always use the `public` schema. Everything else uses the active tenant schema.
40+
Apps listed in `FQQ_SHARED_APPS` will always use the `public` schema, regardless of the active schema.
4541

4642
```python
4743
FQQ_SHARED_APPS = ["auth", "contenttypes"]
@@ -56,7 +52,7 @@ MIDDLEWARE = [
5652
]
5753
```
5854

59-
Subclass `SchemaMiddleware` and override `_get_schema(request)` to resolve the tenant schema from the request (e.g. from subdomain, header, or URL).
55+
Subclass `SchemaMiddleware` and override `_get_schema(request)` to resolve the schema from the request (e.g. from subdomain, header, or URL).
6056

6157
## Usage
6258

@@ -65,8 +61,8 @@ Subclass `SchemaMiddleware` and override `_get_schema(request)` to resolve the t
6561
```python
6662
from django_fqq.schema import set_schema, clear_schema
6763

68-
set_schema("tenant_abc")
69-
# All queries now target the "tenant_abc" schema
64+
set_schema("my_schema")
65+
# All queries now target the "my_schema" schema
7066
# ...
7167
clear_schema()
7268
```
@@ -78,43 +74,40 @@ from django_fqq.middleware import SchemaMiddleware
7874

7975
class MySchemaMiddleware(SchemaMiddleware):
8076
def _get_schema(self, request):
81-
# Resolve tenant from subdomain
8277
host = request.get_host().split(".")[0]
8378
return host
8479
```
8580

8681
### Using a context manager
8782

88-
`query_schema` is a context manager that sets the schema for the duration of a block and automatically restores the previous state on exit. If a schema was already active, it is restored rather than cleared.
83+
`query_schema` sets the schema for the duration of a block and restores the previous state on exit.
8984

9085
```python
9186
from django_fqq.schema import query_schema
9287

93-
with query_schema("tenant_abc"):
94-
# All queries target "tenant_abc"
88+
with query_schema("my_schema"):
89+
# All queries target "my_schema"
9590
...
9691
# Schema is restored to its previous value (or cleared if none was set)
9792
```
9893

99-
It supports nesting — each level restores the schema that was active before it:
94+
Nesting is supported — each level restores the schema that was active before it:
10095

10196
```python
10297
from django_fqq.schema import set_schema, query_schema
10398

104-
set_schema("tenant_a")
99+
set_schema("schema_a")
105100

106-
with query_schema("tenant_b"):
107-
# queries target "tenant_b"
108-
with query_schema("tenant_c"):
109-
# queries target "tenant_c"
101+
with query_schema("schema_b"):
102+
# queries target "schema_b"
103+
with query_schema("schema_c"):
104+
# queries target "schema_c"
110105
...
111-
# back to "tenant_b"
106+
# back to "schema_b"
112107

113-
# back to "tenant_a"
108+
# back to "schema_a"
114109
```
115110

116-
The previous schema is also restored if an exception is raised inside the block.
117-
118111
### Context-safe
119112

120113
Schema state is stored in a `ContextVar`, so it's safe across concurrent async requests and threads.

0 commit comments

Comments
 (0)