mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-14 05:00:10 +00:00
feat(backend): 实现多租户数据隔离与权限管理架构
refactor(backend): 重构模型基类支持租户与客户隔离 feat(backend): 添加客户模块相关模型、CRUD和参数校验 docs(backend): 新增SaaS数据隔离设计方案文档 refactor(backend): 优化日志模块并添加类型注解 fix(backend): 修正字典模块查询参数移除creator字段 style(frontend): 统一按钮组件代码格式 fix(frontend): 修复表格序号计算逻辑 chore(frontend): 更新lint脚本使用pnpm替代npm
This commit is contained in:
@@ -1,19 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Optional
|
||||
from sqlalchemy import Boolean, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from typing import TYPE_CHECKING
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.base_model import CreatorMixin
|
||||
from app.core.base_model import ModelMixin, UserMixin, TenantMixin, CustomerMixin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.api.v1.module_system.user.model import UserModel
|
||||
from app.api.v1.module_system.tenant.model import TenantModel
|
||||
from app.api.v1.module_system.customer.model import CustomerModel
|
||||
|
||||
|
||||
class DemoModel(CreatorMixin):
|
||||
class DemoModel(ModelMixin, UserMixin, TenantMixin, CustomerMixin):
|
||||
"""
|
||||
示例表
|
||||
|
||||
数据隔离策略:
|
||||
- 租户级示例: tenant_id必填, customer_id=NULL
|
||||
- 客户级示例: tenant_id必填, customer_id>0
|
||||
|
||||
根据业务需求,此示例表支持客户级数据隔离
|
||||
"""
|
||||
__tablename__ = 'gen_demo'
|
||||
__table_args__ = ({'comment': '示例表'})
|
||||
__loader_options__ = ["creator"]
|
||||
__tablename__: str = 'gen_demo'
|
||||
__table_args__: dict[str, str] = ({'comment': '示例表'})
|
||||
__loader_options__: list[str] = ["created_by", "updated_by", "tenant", "customer"]
|
||||
|
||||
name: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, default='', comment='名称')
|
||||
status: Mapped[bool] = mapped_column(Boolean(), default=True, nullable=False, comment="是否启用(True:启用 False:禁用)")
|
||||
name: Mapped[str | None] = mapped_column(String(64), nullable=True, default='', comment='名称')
|
||||
|
||||
# 关联关系 (覆盖Mixin中的property)
|
||||
created_by: Mapped["UserModel | None"] = relationship(
|
||||
foreign_keys="DemoModel.created_id",
|
||||
lazy="selectin"
|
||||
)
|
||||
updated_by: Mapped["UserModel | None"] = relationship(
|
||||
foreign_keys="DemoModel.updated_id",
|
||||
lazy="selectin"
|
||||
)
|
||||
tenant: Mapped["TenantModel"] = relationship(
|
||||
foreign_keys="DemoModel.tenant_id",
|
||||
lazy="selectin"
|
||||
)
|
||||
customer: Mapped["CustomerModel | None"] = relationship(
|
||||
foreign_keys="DemoModel.customer_id",
|
||||
lazy="selectin"
|
||||
)
|
||||
Reference in New Issue
Block a user