some updated

This commit is contained in:
Kulvir Singh
2025-12-26 22:39:54 +05:30
parent b22477ef13
commit b92b43c4bc
2 changed files with 231 additions and 565 deletions

View File

@@ -9,11 +9,6 @@
- to prevent such scenarios, funny strategies need to be implemented in code
- **conclusion** unnecessary complexity is introduced.
### **Funny ways versioning**
- versioning means having older versions and newer versions and maintains a relation b/w them tooo so we know what change and how.
- currently no such versioning system is there.
### **complex queries for simple things**
```python
@@ -70,10 +65,7 @@ class Document():
document_type = models.CharField(
max_length=20,
choices=DocumentType.choices
)
name = models.CharField(max_length=500)
blob_url = models.URLField(max_length=2000)
file_type = models.CharField(max_length=20, choices=FileType.choices)
) name = models.CharField(max_length=500) blob_url = models.URLField(max_length=2000) file_type = models.CharField(max_length=20, choices=FileType.choices)
size_bytes = models.BigIntegerField()
total_pages = models.IntegerField(null=True, blank=True)
@@ -129,38 +121,24 @@ class Document():
```python
class Checklist():
document = models.ForeignKey(
"Document",
on_delete=models.SET_NULL,
null=True,
blank=True,
)
id = models.UUIDField(db_index=True)
version = models.IntegerField(default=1)
previous_version = models.ForeignKey(
"self",
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name="next_versions"
)
is_current = models.BooleanField(default=True)
id = models.UUIDField()
name = models.CharField(max_length=200)
description = models.TextField(blank=True)
document = models.ForeignKey("Document", on_delete=models.SET_NULL)
organization = models.ForeignKey(
"Organization",
on_delete=models.CASCADE,
)
created_by = models.ForeignKey(
"User",
on_delete=models.SET_NULL,
null=True,
)
name = models.CharField(max_length=200)
description = models.TextField(blank=True)
```
### Keyterm
@@ -173,34 +151,22 @@ class Keyterm():
METADATA = "METADATA", "Metadata"
id = models.UUIDField(db_index=True)
version = models.IntegerField(default=1)
previous_version = models.ForeignKey(
"self",
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name="next_versions"
)
is_current = models.BooleanField(default=True)
key = models.CharField(max_length=500)
question = models.TextField()
instructions = models.TextField(blank=True)
organization = models.ForeignKey(
"Organization",
on_delete=models.CASCADE,
)
key = models.CharField(max_length=500)
question = models.TextField()
instructions = models.TextField(blank=True)
type = models.CharField(
choices=KeytermType.choices,
default=KeytermType.ANALYSIS
)
expected_answer = models.TextField(null=True, blank=True)
is_active = models.BooleanField(default=True)
```
### Contract
@@ -243,9 +209,6 @@ class Contract():
null=True,
related_name="analyzed_contracts"
)
def get_version_history(self):
return Document.get_version_history(self.document.original_id)
```
### **Analysis MODEL**
@@ -293,7 +256,22 @@ class MSAContract():
auto_renewal = models.BooleanField(default=False)
```
### **Strategy Pattern** for type specific logic
**Benefits**:
- `Contract` table stays clean
- type specific data is normalized
- no changes to existing code when adding new types, adding new contract type = new detail table + new handler
- lastly, easy to test handlers in isolation
**Concern**: Separate tables per contract type could lead to "schema explosion"
BUT....
- Current system has 10-15 distinct contract **categories**
- Many categories share similar metadata structures
- Most contract types might only need generic metadata storage
---
### **Strategy Pattern** for structuring code.
```python
class IContractHandler():
@@ -343,14 +321,6 @@ class ContractService:
return contract
```
**Benefits**:
- `Contract` table stays clean
- type specific data is normalized
- no changes to existing code when adding new types, adding new contract type = new detail table + new handler
- lastly, easy to test handlers in isolation
---
### Dependency Injection
```python
@@ -444,8 +414,6 @@ class ServiceFactory:
)
```
---
### usage in views or anything
```python
@@ -464,3 +432,4 @@ def upload_contract(request):
return Response({"contract_id": str(contract.id)})
```