Group by Schema
This recipe demonstrates how to group tables by their database schema. This is useful for databases like PostgreSQL that use schemas to organize tables.
Configuration
In your mkdocs.yml:
plugins:
- sqlalchemy:
base_class: "by_schema.models.Base"
app_path: "src"
display:
group_by_schema: true
Usage
In your markdown file:
# MkDocs SqlAlchemy Plugin
{% sqlalchemy %}
The output will be grouped by schema, with a heading for each schema.
Result
Schema: blog
Table: posts
| column | type | nullable | default | primary_key | unique | foreign_key |
|---|---|---|---|---|---|---|
id |
INTEGER | ❌ | ✔️ | ❌ | ||
title |
VARCHAR(200) | ❌ | ❌ | ❌ | ||
content |
TEXT | ✔️ | ❌ | ❌ | ||
is_published |
BOOLEAN | ✔️ | False | ❌ | ❌ | |
user_id |
INTEGER | ✔️ | ❌ | ❌ | users.id | |
created_at |
DATETIME | ✔️ | utcnow | ❌ | ❌ | |
updated_at |
DATETIME | ✔️ | utcnow | ❌ | ❌ |
Indexes:
ix_blog_posts_updated_at:updated_at
Constraints:
fk_posts_user_id_users(ForeignKeyConstraint)pk_posts(PrimaryKeyConstraint)
Schema: profiles
Table: user_profiles
| column | type | nullable | default | primary_key | unique | foreign_key |
|---|---|---|---|---|---|---|
id |
INTEGER | ❌ | ✔️ | ❌ | ||
user_id |
INTEGER | ✔️ | ❌ | ✔️ | users.id | |
first_name |
VARCHAR(50) | ✔️ | ❌ | ❌ | ||
last_name |
VARCHAR(50) | ✔️ | ❌ | ❌ | ||
bio |
TEXT | ✔️ | ❌ | ❌ |
Indexes: None
Constraints:
fk_user_profiles_user_id_users(ForeignKeyConstraint)uq_user_profiles_user_id(UniqueConstraint)pk_user_profiles(PrimaryKeyConstraint)
Table: users
| column | type | nullable | default | primary_key | unique | foreign_key |
|---|---|---|---|---|---|---|
id |
INTEGER | ❌ | ✔️ | ❌ | ||
username |
VARCHAR(50) | ❌ | ❌ | ✔️ | ||
email |
VARCHAR(120) | ❌ | ❌ | ✔️ | ||
is_active |
BOOLEAN | ✔️ | True | ❌ | ❌ | |
created_at |
DATETIME | ✔️ | utcnow | ❌ | ❌ |
Indexes: None
Constraints:
uq_users_email(UniqueConstraint)pk_users(PrimaryKeyConstraint)uq_users_username(UniqueConstraint)