Skip to content

Class tigrbl.orm.mixins.principals.TenantColumn

tigrbl.orm.mixins.principals.TenantColumn

Adds tenant_id with a schema-qualified FK to <schema>.tenants.id.

tenant_id

tenant_id()
Source code in tigrbl/orm/mixins/principals.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@declared_attr
def tenant_id(cls) -> Mapped[UUID]:
    schema = getattr(cls, "__tenant_table_schema__", None) or _infer_schema(cls)
    spec = ColumnSpec(
        storage=S(
            type_=PgUUID(as_uuid=True),
            fk=ForeignKeySpec(target=f"{schema}.tenants.id"),
            nullable=False,
            index=True,
        ),
        field=F(py_type=UUID, constraints={"examples": [uuid_example]}),
        io=CRUD_IO,
    )
    return acol(spec=spec)