Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /terrene-foundation_kailash-py /src /kailash /middleware /database /base.py
| """ | |
| Base models and mixins for middleware database layer. | |
| Provides common functionality for all database models. | |
| """ | |
| import uuid | |
| from datetime import datetime, timezone | |
| from typing import Any, Dict, Optional | |
| from sqlalchemy import Boolean, Column, DateTime, Integer, String, event | |
| from sqlalchemy.ext.declarative import declared_attr | |
| from sqlalchemy.sql import func | |
| class TenantMixin: | |
| """Multi-tenant support for all models.""" | |
| def tenant_id(cls): | |
| return Column(String(255), nullable=False, default="default", index=True) | |
| class AuditMixin: | |
| """Audit trail support for all models.""" | |
| def created_at(cls): | |
| return Column(DateTime(timezone=True), nullable=False, default=func.now()) | |
| def updated_at(cls): | |
| return Column(DateTime(timezone=True), onupdate=func.now()) | |
| def created_by(cls): | |
| return Column(String(255)) | |
| def updated_by(cls): | |
| return Column(String(255)) | |
| class SoftDeleteMixin: | |
| """Soft delete support for compliance.""" | |
| def deleted_at(cls): | |
| return Column(DateTime(timezone=True)) | |
| def deleted_by(cls): | |
| return Column(String(255)) | |
| def is_deleted(self) -> bool: | |
| """Check if entity is soft deleted.""" | |
| return self.deleted_at is not None | |
| def soft_delete(self, deleted_by: str): | |
| """Mark entity as deleted.""" | |
| self.deleted_at = datetime.now(timezone.utc) | |
| self.deleted_by = deleted_by | |
| class VersionMixin: | |
| """Version control support.""" | |
| def version(cls): | |
| return Column(Integer, nullable=False, default=1) | |
| def increment_version(self): | |
| """Increment version number.""" | |
| self.version = (self.version or 0) + 1 | |
| class SecurityMixin: | |
| """Security classification support.""" | |
| def security_classification(cls): | |
| return Column(String(50), default="internal") | |
| def access_permissions(cls): | |
| return Column(String, default="{}") # JSON stored as string for compatibility | |
| class ComplianceMixin: | |
| """Compliance tracking support.""" | |
| def compliance_requirements(cls): | |
| return Column(String, default="[]") # JSON array as string | |
| def retention_until(cls): | |
| return Column(DateTime(timezone=True)) | |
| class BaseMixin(TenantMixin, AuditMixin): | |
| """Common mixins for most models.""" | |
| pass | |
| class EnterpriseBaseMixin( | |
| TenantMixin, AuditMixin, SoftDeleteMixin, VersionMixin, SecurityMixin | |
| ): | |
| """Full enterprise features for critical models.""" | |
| pass | |
Xet Storage Details
- Size:
- 2.74 kB
- Xet hash:
- 5cea0276dab8d9caf5538b6a5298ba1e9a0746fc108e3c772322c3873d2dec3f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.