feat(migrations): add Django migration for DeletionRequest model

Created migration 1076_add_deletion_request.py to add the DeletionRequest model
to the database schema. This model tracks AI-initiated deletion requests that
require explicit user approval before any documents are deleted.

Migration includes:
- All model fields (created_at, updated_at, requested_by_ai, ai_reason, status, etc.)
- ManyToMany relationship with Document model
- Foreign keys to User model (user and reviewed_by)
- Custom indexes for common query patterns (status+user, created_at)
- Proper ordering and metadata

Fixes #10

Co-authored-by: dawnsystem <42047891+dawnsystem@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-13 00:51:41 +00:00
parent f8f2a72c6d
commit ad2df8c7ff

View file

@ -0,0 +1,148 @@
# Generated manually for DeletionRequest model
# Based on model definition in documents/models.py
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
"""
Add DeletionRequest model for AI-initiated deletion requests.
This model tracks deletion requests that require user approval,
implementing the safety requirement from agents.md to ensure
no documents are deleted without explicit user consent.
"""
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("documents", "1075_add_performance_indexes"),
]
operations = [
migrations.CreateModel(
name="DeletionRequest",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"created_at",
models.DateTimeField(auto_now_add=True),
),
(
"updated_at",
models.DateTimeField(auto_now=True),
),
(
"requested_by_ai",
models.BooleanField(default=True),
),
(
"ai_reason",
models.TextField(
help_text="Detailed explanation from AI about why deletion is recommended"
),
),
(
"status",
models.CharField(
choices=[
("pending", "Pending"),
("approved", "Approved"),
("rejected", "Rejected"),
("cancelled", "Cancelled"),
("completed", "Completed"),
],
default="pending",
max_length=20,
),
),
(
"impact_summary",
models.JSONField(
default=dict,
help_text="Summary of what will be affected by this deletion",
),
),
(
"reviewed_at",
models.DateTimeField(blank=True, null=True),
),
(
"review_comment",
models.TextField(
blank=True,
help_text="User's comment when reviewing",
),
),
(
"completed_at",
models.DateTimeField(blank=True, null=True),
),
(
"completion_details",
models.JSONField(
default=dict,
help_text="Details about the deletion execution",
),
),
(
"documents",
models.ManyToManyField(
help_text="Documents that would be deleted if approved",
related_name="deletion_requests",
to="documents.document",
),
),
(
"reviewed_by",
models.ForeignKey(
blank=True,
help_text="User who reviewed and approved/rejected",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="reviewed_deletion_requests",
to=settings.AUTH_USER_MODEL,
),
),
(
"user",
models.ForeignKey(
help_text="User who must approve this deletion",
on_delete=django.db.models.deletion.CASCADE,
related_name="deletion_requests",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "deletion request",
"verbose_name_plural": "deletion requests",
"ordering": ["-created_at"],
},
),
# Add composite index for status + user (common query pattern)
migrations.AddIndex(
model_name="deletionrequest",
index=models.Index(
fields=["status", "user"],
name="del_req_status_user_idx",
),
),
# Add index for created_at (for chronological queries)
migrations.AddIndex(
model_name="deletionrequest",
index=models.Index(
fields=["created_at"],
name="del_req_created_idx",
),
),
]