The monolithic compliance/db/models.py is decomposed into seven sibling
aggregate modules following the existing repo pattern (dsr_models.py,
vvt_models.py, tom_models.py, etc.):
regulation_models.py (134 LOC) — RegulationDB, RequirementDB
control_models.py (279 LOC) — ControlDB, ControlMappingDB, EvidenceDB, RiskDB
ai_system_models.py (141 LOC) — AISystemDB, AuditExportDB
service_module_models.py (176 LOC) — ServiceModuleDB, ModuleRegulationMappingDB, ModuleRiskDB
audit_session_models.py (177 LOC) — AuditSessionDB, AuditSignOffDB
isms_governance_models.py (323 LOC) — ISMSScope, Context, Policy, Objective, SoA
isms_audit_models.py (468 LOC) — AuditFinding, CAPA, ManagementReview, InternalAudit,
AuditTrail, ReadinessCheck
models.py becomes an 85-line re-export shim — every public symbol is
re-exported in dependency order so existing imports work unchanged:
from compliance.db.models import RegulationDB, ControlDB, AuditFindingDB # still works
New code SHOULD import from the aggregate module directly; the shim is
for backwards compatibility during the migration.
Schema freeze preserved:
- __tablename__ byte-identical
- Column names, types, indexes, constraints byte-identical
- relationship() string references and back_populates unchanged
- cascade directives unchanged
Verified:
- 173/173 pytest compliance/tests/ pass
- tests/contracts/test_openapi_baseline.py passes (360 paths,
484 operations — identical to baseline)
- All new sibling files under the 500-line hard cap
(largest: isms_audit_models.py at 468 LOC)
- No file in compliance/db/ now exceeds the hard cap
This is Phase 1 Step 2 from PHASE1_RUNBOOK.md. Phase 1 Step 3 (split
compliance/api/schemas.py, 1899 LOC) is the next target.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
"""
|
|
compliance.db.models — backwards-compatibility re-export shim.
|
|
|
|
Phase 1 refactor split the monolithic 1466-line models module into per-aggregate
|
|
sibling modules. Every public symbol is re-exported here so existing imports
|
|
(``from compliance.db.models import RegulationDB, ...``) continue to work
|
|
unchanged.
|
|
|
|
New code SHOULD import directly from the aggregate module:
|
|
|
|
from compliance.db.regulation_models import RegulationDB, RequirementDB
|
|
from compliance.db.control_models import ControlDB, RiskDB
|
|
from compliance.db.ai_system_models import AISystemDB
|
|
from compliance.db.service_module_models import ServiceModuleDB
|
|
from compliance.db.audit_session_models import AuditSessionDB
|
|
from compliance.db.isms_governance_models import ISMSScopeDB
|
|
from compliance.db.isms_audit_models import AuditFindingDB
|
|
|
|
Import order here also matters for SQLAlchemy mapper configuration: aggregates
|
|
that are referenced by name-string relationships must be imported before their
|
|
referrers. Regulation/Control/Risk come first, then Service Module, then the
|
|
audit sessions and ISMS layers.
|
|
|
|
DO NOT add new classes to this file. Add them to the appropriate aggregate
|
|
module and re-export here.
|
|
"""
|
|
|
|
# Order matters: later modules reference classes defined in earlier ones via
|
|
# SQLAlchemy string relationships. Keep foundational aggregates first.
|
|
|
|
from compliance.db.regulation_models import ( # noqa: F401
|
|
RegulationTypeEnum,
|
|
RegulationDB,
|
|
RequirementDB,
|
|
)
|
|
from compliance.db.control_models import ( # noqa: F401
|
|
ControlTypeEnum,
|
|
ControlDomainEnum,
|
|
ControlStatusEnum,
|
|
RiskLevelEnum,
|
|
EvidenceStatusEnum,
|
|
ControlDB,
|
|
ControlMappingDB,
|
|
EvidenceDB,
|
|
RiskDB,
|
|
)
|
|
from compliance.db.ai_system_models import ( # noqa: F401
|
|
AIClassificationEnum,
|
|
AISystemStatusEnum,
|
|
ExportStatusEnum,
|
|
AISystemDB,
|
|
AuditExportDB,
|
|
)
|
|
from compliance.db.service_module_models import ( # noqa: F401
|
|
ServiceTypeEnum,
|
|
RelevanceLevelEnum,
|
|
ServiceModuleDB,
|
|
ModuleRegulationMappingDB,
|
|
ModuleRiskDB,
|
|
)
|
|
from compliance.db.audit_session_models import ( # noqa: F401
|
|
AuditResultEnum,
|
|
AuditSessionStatusEnum,
|
|
AuditSessionDB,
|
|
AuditSignOffDB,
|
|
)
|
|
from compliance.db.isms_governance_models import ( # noqa: F401
|
|
ApprovalStatusEnum,
|
|
ISMSScopeDB,
|
|
ISMSContextDB,
|
|
ISMSPolicyDB,
|
|
SecurityObjectiveDB,
|
|
StatementOfApplicabilityDB,
|
|
)
|
|
from compliance.db.isms_audit_models import ( # noqa: F401
|
|
FindingTypeEnum,
|
|
FindingStatusEnum,
|
|
CAPATypeEnum,
|
|
AuditFindingDB,
|
|
CorrectiveActionDB,
|
|
ManagementReviewDB,
|
|
InternalAuditDB,
|
|
AuditTrailDB,
|
|
ISMSReadinessCheckDB,
|
|
)
|