feat(property): add 23-table property module with partitioned follow_logs and property_photos
This commit is contained in:
130
apps/property/models/follow_keys.py
Normal file
130
apps/property/models/follow_keys.py
Normal file
@@ -0,0 +1,130 @@
|
||||
from django.db import models
|
||||
|
||||
from core.enums import (
|
||||
PropertyFollowAiTag,
|
||||
PropertyFollowAttachmentFileType,
|
||||
PropertyFollowLogType,
|
||||
PropertyKeyType,
|
||||
)
|
||||
from core.models.base import UUIDPrimaryKeyModel
|
||||
|
||||
|
||||
class FollowLog(models.Model):
|
||||
"""Partitioned table (PARTITION BY RANGE created_at).
|
||||
|
||||
Managed via RunSQL; Django ORM treats parent as unmanaged.
|
||||
"""
|
||||
|
||||
id = models.UUIDField(primary_key=True)
|
||||
created_at = models.DateTimeField()
|
||||
property = models.ForeignKey(
|
||||
"fonrey_property.Property", on_delete=models.CASCADE, related_name="follow_logs"
|
||||
)
|
||||
|
||||
log_type = models.CharField(max_length=30, choices=PropertyFollowLogType.choices)
|
||||
purpose = models.CharField(max_length=50, blank=True, default="")
|
||||
content = models.TextField(blank=True, default="")
|
||||
|
||||
ai_tag = models.CharField(
|
||||
max_length=20, blank=True, default="", choices=PropertyFollowAiTag.choices
|
||||
)
|
||||
|
||||
change_detail = models.JSONField(null=True, blank=True)
|
||||
log_tag = models.CharField(max_length=50, blank=True, default="")
|
||||
|
||||
is_public = models.BooleanField(default=True)
|
||||
|
||||
operator = models.ForeignKey(
|
||||
"org.Staff", null=True, blank=True, on_delete=models.SET_NULL
|
||||
)
|
||||
operator_snapshot = models.JSONField(null=True, blank=True)
|
||||
|
||||
is_deletable = models.BooleanField(default=True)
|
||||
deleted_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "follow_logs"
|
||||
managed = False
|
||||
unique_together = (("id", "created_at"),)
|
||||
|
||||
|
||||
class FollowLogAttachment(UUIDPrimaryKeyModel):
|
||||
follow_log_id = models.UUIDField() # cross-partitioned FK; not enforced via Django FK
|
||||
file_key = models.TextField()
|
||||
file_name = models.CharField(max_length=255)
|
||||
file_size = models.IntegerField()
|
||||
file_type = models.CharField(
|
||||
max_length=10, blank=True, default="", choices=PropertyFollowAttachmentFileType.choices
|
||||
)
|
||||
sort_order = models.SmallIntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "follow_log_attachments"
|
||||
indexes = [models.Index(fields=["follow_log_id"], name="idx_fla_log")]
|
||||
|
||||
|
||||
class FollowLogRecording(UUIDPrimaryKeyModel):
|
||||
follow_log_id = models.UUIDField()
|
||||
file_key = models.TextField()
|
||||
duration_seconds = models.IntegerField(null=True, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "follow_log_recordings"
|
||||
indexes = [models.Index(fields=["follow_log_id"], name="idx_flr_log")]
|
||||
|
||||
|
||||
class PropertyKey(UUIDPrimaryKeyModel):
|
||||
property = models.ForeignKey(
|
||||
"fonrey_property.Property", on_delete=models.CASCADE, related_name="keys"
|
||||
)
|
||||
key_type = models.CharField(max_length=20, choices=PropertyKeyType.choices)
|
||||
|
||||
holder = models.ForeignKey(
|
||||
"org.Staff",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="held_keys",
|
||||
)
|
||||
holder_snapshot = models.JSONField(null=True, blank=True)
|
||||
storage_unit = models.ForeignKey(
|
||||
"org.OrgUnit",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="stored_keys",
|
||||
)
|
||||
|
||||
is_other_agency = models.BooleanField(default=False)
|
||||
other_agency_info = models.CharField(max_length=30, blank=True, default="")
|
||||
remarks = models.TextField(blank=True, default="")
|
||||
|
||||
is_active = models.BooleanField(default=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
created_by = models.ForeignKey(
|
||||
"org.Staff",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="created_property_keys",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
db_table = "property_keys"
|
||||
indexes = [models.Index(fields=["property"], name="idx_pk_property")]
|
||||
|
||||
|
||||
class KeyAttachment(UUIDPrimaryKeyModel):
|
||||
key = models.ForeignKey(
|
||||
PropertyKey, on_delete=models.CASCADE, related_name="attachments"
|
||||
)
|
||||
file_key = models.TextField()
|
||||
file_name = models.CharField(max_length=255)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "key_attachments"
|
||||
indexes = [models.Index(fields=["key"], name="idx_ka_key")]
|
||||
Reference in New Issue
Block a user