Files
ETB/ETB-API/knowledge_learning/migrations/0001_initial.py
Iliyan Angelov 6b247e5b9f Updates
2025-09-19 11:58:53 +03:00

256 lines
21 KiB
Python

# Generated by Django 5.2.6 on 2025-09-18 17:34
import django.core.validators
import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('incident_intelligence', '0004_incident_oncall_assignment_incident_sla_override_and_more'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='KnowledgeBaseArticle',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('title', models.CharField(max_length=200)),
('slug', models.SlugField(help_text='URL-friendly identifier', unique=True)),
('content', models.TextField(help_text='Main article content')),
('summary', models.TextField(help_text='Brief summary of the article')),
('tags', models.JSONField(default=list, help_text='Tags for categorization and search')),
('article_type', models.CharField(choices=[('RUNBOOK', 'Runbook'), ('TROUBLESHOOTING', 'Troubleshooting Guide'), ('BEST_PRACTICE', 'Best Practice'), ('LESSON_LEARNED', 'Lesson Learned'), ('PROCEDURE', 'Procedure'), ('REFERENCE', 'Reference'), ('WIKI', 'Wiki Article')], max_length=20)),
('category', models.CharField(help_text='Primary category', max_length=100)),
('subcategory', models.CharField(blank=True, max_length=100, null=True)),
('related_services', models.JSONField(default=list, help_text='Services this article relates to')),
('related_components', models.JSONField(default=list, help_text='Components this article relates to')),
('status', models.CharField(choices=[('DRAFT', 'Draft'), ('REVIEW', 'Under Review'), ('APPROVED', 'Approved'), ('PUBLISHED', 'Published'), ('DEPRECATED', 'Deprecated')], default='DRAFT', max_length=20)),
('is_featured', models.BooleanField(default=False, help_text='Whether this is a featured article')),
('view_count', models.PositiveIntegerField(default=0, help_text='Number of times this article has been viewed')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('last_reviewed', models.DateTimeField(blank=True, null=True)),
('next_review_due', models.DateTimeField(blank=True, null=True)),
('confluence_url', models.URLField(blank=True, help_text='Link to Confluence page', null=True)),
('wiki_url', models.URLField(blank=True, help_text='Link to wiki page', null=True)),
('external_references', models.JSONField(default=list, help_text='External reference links')),
('search_keywords', models.JSONField(default=list, help_text='Keywords for search optimization')),
('difficulty_level', models.CharField(choices=[('BEGINNER', 'Beginner'), ('INTERMEDIATE', 'Intermediate'), ('ADVANCED', 'Advanced'), ('EXPERT', 'Expert')], default='INTERMEDIATE', max_length=20)),
('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='authored_articles', to=settings.AUTH_USER_MODEL)),
('last_updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_articles', to=settings.AUTH_USER_MODEL)),
('maintainer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='maintained_articles', to=settings.AUTH_USER_MODEL)),
('related_incidents', models.ManyToManyField(blank=True, help_text='Incidents that led to or are related to this article', related_name='knowledge_articles', to='incident_intelligence.incident')),
],
options={
'ordering': ['-updated_at', '-created_at'],
},
),
migrations.CreateModel(
name='IncidentRecommendation',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('recommendation_type', models.CharField(choices=[('SIMILAR_INCIDENT', 'Similar Incident'), ('SOLUTION', 'Solution/Resolution'), ('KNOWLEDGE_ARTICLE', 'Knowledge Article'), ('RUNBOOK', 'Runbook'), ('EXPERT', 'Expert/Team'), ('PREVENTION', 'Prevention Strategy')], max_length=20)),
('title', models.CharField(max_length=200)),
('description', models.TextField(help_text='Description of the recommendation')),
('similarity_score', models.FloatField(help_text='Similarity score between current and recommended incident (0.0-1.0)', validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('confidence_level', models.CharField(choices=[('LOW', 'Low'), ('MEDIUM', 'Medium'), ('HIGH', 'High'), ('VERY_HIGH', 'Very High')], max_length=20)),
('confidence_score', models.FloatField(help_text='AI confidence in this recommendation (0.0-1.0)', validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('suggested_actions', models.JSONField(default=list, help_text='Suggested actions to take')),
('expected_outcome', models.TextField(blank=True, help_text='Expected outcome of following this recommendation', null=True)),
('time_to_implement', models.DurationField(blank=True, help_text='Estimated time to implement', null=True)),
('is_applied', models.BooleanField(default=False, help_text='Whether this recommendation was applied')),
('applied_at', models.DateTimeField(blank=True, null=True)),
('effectiveness_rating', models.PositiveIntegerField(blank=True, help_text='User rating of recommendation effectiveness (1-5)', null=True, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(5)])),
('reasoning', models.TextField(help_text='AI explanation for why this recommendation was made')),
('matching_factors', models.JSONField(default=list, help_text='Factors that led to this recommendation')),
('model_version', models.CharField(default='v1.0', max_length=50)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('applied_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='applied_recommendations', to=settings.AUTH_USER_MODEL)),
('incident', models.ForeignKey(help_text='Incident for which this recommendation is made', on_delete=django.db.models.deletion.CASCADE, related_name='recommendations', to='incident_intelligence.incident')),
('related_incident', models.ForeignKey(blank=True, help_text='Related incident that this recommendation is based on', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='recommended_for', to='incident_intelligence.incident')),
('suggested_expert', models.ForeignKey(blank=True, help_text='Suggested expert who can help with this incident', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
('knowledge_article', models.ForeignKey(blank=True, help_text='Related knowledge base article', null=True, on_delete=django.db.models.deletion.CASCADE, to='knowledge_learning.knowledgebasearticle')),
],
options={
'ordering': ['-confidence_score', '-similarity_score'],
},
),
migrations.CreateModel(
name='KnowledgeBaseUsage',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('usage_type', models.CharField(choices=[('VIEW', 'Article View'), ('APPLY', 'Recommendation Applied'), ('RATE', 'Rating Given'), ('SHARE', 'Shared'), ('BOOKMARK', 'Bookmarked')], max_length=20)),
('context', models.JSONField(default=dict, help_text='Additional context about the usage')),
('session_id', models.CharField(blank=True, max_length=100, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('incident', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='knowledge_usage', to='incident_intelligence.incident')),
('knowledge_article', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='usage_logs', to='knowledge_learning.knowledgebasearticle')),
('recommendation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='usage_logs', to='knowledge_learning.incidentrecommendation')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='knowledge_usage', to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='Postmortem',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('title', models.CharField(max_length=200)),
('executive_summary', models.TextField(help_text='High-level summary for executives')),
('timeline', models.JSONField(default=list, help_text='Detailed timeline of events')),
('root_cause_analysis', models.TextField(help_text='Analysis of root causes')),
('impact_assessment', models.TextField(help_text='Assessment of business and technical impact')),
('lessons_learned', models.TextField(help_text='Key lessons learned from the incident')),
('action_items', models.JSONField(default=list, help_text='List of action items to prevent recurrence')),
('is_automated', models.BooleanField(default=True, help_text='Whether this postmortem was auto-generated')),
('generation_confidence', models.FloatField(blank=True, help_text='AI confidence in postmortem quality (0.0-1.0)', null=True, validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('auto_generated_sections', models.JSONField(default=list, help_text='List of sections that were auto-generated')),
('status', models.CharField(choices=[('DRAFT', 'Draft'), ('IN_REVIEW', 'In Review'), ('APPROVED', 'Approved'), ('PUBLISHED', 'Published'), ('ARCHIVED', 'Archived')], default='DRAFT', max_length=20)),
('severity', models.CharField(choices=[('LOW', 'Low'), ('MEDIUM', 'Medium'), ('HIGH', 'High'), ('CRITICAL', 'Critical')], max_length=20)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('published_at', models.DateTimeField(blank=True, null=True)),
('due_date', models.DateTimeField(blank=True, help_text='When this postmortem should be completed', null=True)),
('affected_services', models.JSONField(default=list, help_text='Services affected by the incident')),
('affected_teams', models.JSONField(default=list, help_text='Teams involved in the incident')),
('approver', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approved_postmortems', to=settings.AUTH_USER_MODEL)),
('incident', models.ForeignKey(help_text='Primary incident this postmortem is about', on_delete=django.db.models.deletion.CASCADE, related_name='postmortems', to='incident_intelligence.incident')),
('owner', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='owned_postmortems', to=settings.AUTH_USER_MODEL)),
('related_incidents', models.ManyToManyField(blank=True, help_text='Other incidents related to this postmortem', related_name='related_postmortems', to='incident_intelligence.incident')),
('reviewers', models.ManyToManyField(blank=True, related_name='reviewed_postmortems', to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='LearningPattern',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=200)),
('pattern_type', models.CharField(choices=[('ROOT_CAUSE', 'Root Cause Pattern'), ('RESOLUTION', 'Resolution Pattern'), ('PREVENTION', 'Prevention Pattern'), ('ESCALATION', 'Escalation Pattern'), ('COMMUNICATION', 'Communication Pattern')], max_length=20)),
('description', models.TextField()),
('frequency', models.PositiveIntegerField(default=1, help_text='How many times this pattern has been observed')),
('success_rate', models.FloatField(help_text='Success rate when this pattern is applied (0.0-1.0)', validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('confidence_score', models.FloatField(help_text="Confidence in this pattern's validity (0.0-1.0)", validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('triggers', models.JSONField(default=list, help_text='Conditions that trigger this pattern')),
('actions', models.JSONField(default=list, help_text='Actions associated with this pattern')),
('outcomes', models.JSONField(default=list, help_text='Expected outcomes of this pattern')),
('is_validated', models.BooleanField(default=False, help_text='Whether this pattern has been validated by experts')),
('validation_notes', models.TextField(blank=True, null=True)),
('times_applied', models.PositiveIntegerField(default=0, help_text='Number of times this pattern has been applied')),
('last_applied', models.DateTimeField(blank=True, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('source_incidents', models.ManyToManyField(help_text='Incidents that contributed to this pattern', related_name='learning_patterns', to='incident_intelligence.incident')),
('validated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='validated_patterns', to=settings.AUTH_USER_MODEL)),
('source_postmortems', models.ManyToManyField(help_text='Postmortems that contributed to this pattern', related_name='learning_patterns', to='knowledge_learning.postmortem')),
],
options={
'ordering': ['-confidence_score', '-frequency'],
},
),
migrations.AddField(
model_name='knowledgebasearticle',
name='source_postmortems',
field=models.ManyToManyField(blank=True, help_text='Postmortems that generated this article', related_name='generated_articles', to='knowledge_learning.postmortem'),
),
migrations.CreateModel(
name='AutomatedPostmortemGeneration',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('status', models.CharField(choices=[('PENDING', 'Pending'), ('PROCESSING', 'Processing'), ('COMPLETED', 'Completed'), ('FAILED', 'Failed'), ('REVIEW_REQUIRED', 'Review Required')], default='PENDING', max_length=20)),
('generation_trigger', models.CharField(help_text='What triggered the generation', max_length=50)),
('incident_data', models.JSONField(help_text='Incident data used for generation')),
('timeline_data', models.JSONField(help_text='Timeline data used for generation')),
('log_data', models.JSONField(default=list, help_text='Log data used for generation')),
('generated_content', models.JSONField(blank=True, help_text='Generated postmortem content', null=True)),
('confidence_scores', models.JSONField(default=dict, help_text='Confidence scores for different sections')),
('quality_metrics', models.JSONField(default=dict, help_text='Quality metrics for generated content')),
('processing_time', models.FloatField(blank=True, help_text='Time taken for generation in seconds', null=True)),
('model_version', models.CharField(default='v1.0', max_length=50)),
('error_message', models.TextField(blank=True, null=True)),
('started_at', models.DateTimeField(auto_now_add=True)),
('completed_at', models.DateTimeField(blank=True, null=True)),
('incident', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='postmortem_generations', to='incident_intelligence.incident')),
('generated_postmortem', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='generation_log', to='knowledge_learning.postmortem')),
],
options={
'ordering': ['-started_at'],
},
),
migrations.AddIndex(
model_name='incidentrecommendation',
index=models.Index(fields=['incident', 'recommendation_type'], name='knowledge_l_inciden_382eaa_idx'),
),
migrations.AddIndex(
model_name='incidentrecommendation',
index=models.Index(fields=['confidence_score', 'similarity_score'], name='knowledge_l_confide_478c88_idx'),
),
migrations.AddIndex(
model_name='incidentrecommendation',
index=models.Index(fields=['is_applied'], name='knowledge_l_is_appl_5da7c0_idx'),
),
migrations.AddIndex(
model_name='knowledgebaseusage',
index=models.Index(fields=['user', 'usage_type'], name='knowledge_l_user_id_c46f08_idx'),
),
migrations.AddIndex(
model_name='knowledgebaseusage',
index=models.Index(fields=['created_at'], name='knowledge_l_created_eaa6d6_idx'),
),
migrations.AddIndex(
model_name='postmortem',
index=models.Index(fields=['status', 'severity'], name='knowledge_l_status_f6ad36_idx'),
),
migrations.AddIndex(
model_name='postmortem',
index=models.Index(fields=['incident', 'status'], name='knowledge_l_inciden_7ebad7_idx'),
),
migrations.AddIndex(
model_name='postmortem',
index=models.Index(fields=['created_at'], name='knowledge_l_created_4128f5_idx'),
),
migrations.AddIndex(
model_name='learningpattern',
index=models.Index(fields=['pattern_type', 'confidence_score'], name='knowledge_l_pattern_a8d632_idx'),
),
migrations.AddIndex(
model_name='learningpattern',
index=models.Index(fields=['is_validated'], name='knowledge_l_is_vali_d95c24_idx'),
),
migrations.AddIndex(
model_name='knowledgebasearticle',
index=models.Index(fields=['article_type', 'status'], name='knowledge_l_article_05399a_idx'),
),
migrations.AddIndex(
model_name='knowledgebasearticle',
index=models.Index(fields=['category', 'subcategory'], name='knowledge_l_categor_622312_idx'),
),
migrations.AddIndex(
model_name='knowledgebasearticle',
index=models.Index(fields=['status', 'is_featured'], name='knowledge_l_status_6b05ce_idx'),
),
migrations.AddIndex(
model_name='knowledgebasearticle',
index=models.Index(fields=['created_at'], name='knowledge_l_created_49b5e7_idx'),
),
migrations.AddIndex(
model_name='automatedpostmortemgeneration',
index=models.Index(fields=['status', 'started_at'], name='knowledge_l_status_90fde2_idx'),
),
migrations.AddIndex(
model_name='automatedpostmortemgeneration',
index=models.Index(fields=['incident', 'status'], name='knowledge_l_inciden_e3b5fd_idx'),
),
]