# Generated by Django 5.2.6 on 2025-09-18 15:29 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', '0003_incident_auto_remediation_attempted_and_more'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( name='AutoRemediation', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('name', models.CharField(max_length=200, unique=True)), ('description', models.TextField()), ('remediation_type', models.CharField(choices=[('SERVICE_RESTART', 'Service Restart'), ('DEPLOYMENT_ROLLBACK', 'Deployment Rollback'), ('SCALE_UP', 'Scale Up Resources'), ('SCALE_DOWN', 'Scale Down Resources'), ('CACHE_CLEAR', 'Clear Cache'), ('CONFIG_UPDATE', 'Configuration Update'), ('CUSTOM_SCRIPT', 'Custom Script'), ('WEBHOOK', 'Webhook Call')], max_length=30)), ('trigger_conditions', models.JSONField(default=dict, help_text='Conditions that trigger this remediation')), ('trigger_condition_type', models.CharField(choices=[('SEVERITY', 'Incident Severity'), ('CATEGORY', 'Incident Category'), ('SERVICE', 'Affected Service'), ('DURATION', 'Incident Duration'), ('PATTERN', 'Pattern Match')], max_length=20)), ('remediation_config', models.JSONField(default=dict, help_text='Configuration for the remediation action')), ('timeout_seconds', models.PositiveIntegerField(default=300, help_text='Timeout for remediation action')), ('requires_approval', models.BooleanField(default=False, help_text='Whether manual approval is required')), ('max_executions_per_incident', models.PositiveIntegerField(default=1, help_text='Max times this can run per incident')), ('is_active', models.BooleanField(default=True)), ('created_at', models.DateTimeField(auto_now_add=True)), ('updated_at', models.DateTimeField(auto_now=True)), ('execution_count', models.PositiveIntegerField(default=0)), ('success_count', models.PositiveIntegerField(default=0)), ('last_executed_at', models.DateTimeField(blank=True, null=True)), ('approval_users', models.ManyToManyField(blank=True, help_text='Users who can approve this remediation', related_name='approvable_remediations', to=settings.AUTH_USER_MODEL)), ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_auto_remediations', to=settings.AUTH_USER_MODEL)), ], options={ 'ordering': ['name'], }, ), migrations.CreateModel( name='AutoRemediationExecution', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('status', models.CharField(choices=[('PENDING', 'Pending'), ('APPROVED', 'Approved'), ('EXECUTING', 'Executing'), ('COMPLETED', 'Completed'), ('FAILED', 'Failed'), ('CANCELLED', 'Cancelled'), ('TIMEOUT', 'Timeout'), ('REJECTED', 'Rejected')], default='PENDING', max_length=20)), ('trigger_data', models.JSONField(default=dict, help_text='Data that triggered the remediation')), ('approved_at', models.DateTimeField(blank=True, null=True)), ('approval_notes', models.TextField(blank=True, null=True)), ('execution_log', models.JSONField(default=list, help_text='Detailed execution log')), ('output_data', models.JSONField(default=dict, help_text='Output data from remediation')), ('error_message', models.TextField(blank=True, null=True)), ('triggered_at', models.DateTimeField(auto_now_add=True)), ('started_at', models.DateTimeField(blank=True, null=True)), ('completed_at', models.DateTimeField(blank=True, null=True)), ('duration', models.DurationField(blank=True, null=True)), ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approved_remediations', to=settings.AUTH_USER_MODEL)), ('auto_remediation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='executions', to='automation_orchestration.autoremediation')), ('incident', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='auto_remediations', to='incident_intelligence.incident')), ], options={ 'ordering': ['-triggered_at'], }, ), migrations.CreateModel( name='ChatOpsIntegration', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('name', models.CharField(max_length=200, unique=True)), ('platform', models.CharField(choices=[('SLACK', 'Slack'), ('TEAMS', 'Microsoft Teams'), ('DISCORD', 'Discord'), ('MATTERMOST', 'Mattermost')], max_length=20)), ('webhook_url', models.URLField(help_text='Webhook URL for the chat platform')), ('bot_token', models.CharField(help_text='Bot authentication token', max_length=500)), ('channel_id', models.CharField(help_text='Default channel ID', max_length=100)), ('command_prefix', models.CharField(default='!', help_text='Command prefix (e.g., !, /)', max_length=10)), ('available_commands', models.JSONField(default=list, help_text='List of available commands and their descriptions')), ('allowed_users', models.JSONField(default=list, help_text='List of user IDs allowed to use commands')), ('allowed_channels', models.JSONField(default=list, help_text='List of channel IDs where commands are allowed')), ('is_active', models.BooleanField(default=True)), ('last_activity', models.DateTimeField(blank=True, null=True)), ('created_at', models.DateTimeField(auto_now_add=True)), ('updated_at', models.DateTimeField(auto_now=True)), ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), ], options={ 'ordering': ['name'], }, ), migrations.CreateModel( name='Integration', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('name', models.CharField(max_length=200, unique=True)), ('integration_type', models.CharField(choices=[('JIRA', 'Jira'), ('GITHUB', 'GitHub'), ('JENKINS', 'Jenkins'), ('SERVICENOW', 'ServiceNow'), ('ANSIBLE', 'Ansible'), ('TERRAFORM', 'Terraform'), ('SLACK', 'Slack'), ('TEAMS', 'Microsoft Teams'), ('WEBHOOK', 'Generic Webhook'), ('API', 'Generic API')], max_length=20)), ('description', models.TextField(blank=True, null=True)), ('configuration', models.JSONField(default=dict, help_text='Integration-specific configuration (API keys, URLs, etc.)')), ('authentication_config', models.JSONField(default=dict, help_text='Authentication configuration (OAuth, API keys, etc.)')), ('status', models.CharField(choices=[('ACTIVE', 'Active'), ('INACTIVE', 'Inactive'), ('ERROR', 'Error'), ('CONFIGURING', 'Configuring')], default='CONFIGURING', max_length=20)), ('last_health_check', models.DateTimeField(blank=True, null=True)), ('health_status', models.CharField(choices=[('HEALTHY', 'Healthy'), ('WARNING', 'Warning'), ('ERROR', 'Error'), ('UNKNOWN', 'Unknown')], default='UNKNOWN', max_length=20)), ('error_message', models.TextField(blank=True, null=True)), ('request_count', models.PositiveIntegerField(default=0)), ('last_used_at', models.DateTimeField(blank=True, null=True)), ('created_at', models.DateTimeField(auto_now_add=True)), ('updated_at', models.DateTimeField(auto_now=True)), ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), ], options={ 'ordering': ['name'], }, ), migrations.CreateModel( name='MaintenanceWindow', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('name', models.CharField(max_length=200)), ('description', models.TextField()), ('start_time', models.DateTimeField(help_text='When maintenance window starts')), ('end_time', models.DateTimeField(help_text='When maintenance window ends')), ('timezone', models.CharField(default='UTC', max_length=50)), ('affected_services', models.JSONField(default=list, help_text='List of services affected by this maintenance')), ('affected_components', models.JSONField(default=list, help_text='List of components affected by this maintenance')), ('suppress_incident_creation', models.BooleanField(default=True)), ('suppress_notifications', models.BooleanField(default=True)), ('suppress_escalations', models.BooleanField(default=True)), ('status', models.CharField(choices=[('SCHEDULED', 'Scheduled'), ('ACTIVE', 'Active'), ('COMPLETED', 'Completed'), ('CANCELLED', 'Cancelled')], default='SCHEDULED', max_length=20)), ('created_at', models.DateTimeField(auto_now_add=True)), ('updated_at', models.DateTimeField(auto_now=True)), ('incidents_suppressed', models.PositiveIntegerField(default=0)), ('notifications_suppressed', models.PositiveIntegerField(default=0)), ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), ], options={ 'ordering': ['start_time'], }, ), migrations.CreateModel( name='Runbook', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('name', models.CharField(max_length=200, unique=True)), ('description', models.TextField()), ('version', models.CharField(default='1.0', max_length=20)), ('trigger_type', models.CharField(choices=[('MANUAL', 'Manual Trigger'), ('AUTOMATIC', 'Automatic Trigger'), ('SCHEDULED', 'Scheduled Trigger'), ('WEBHOOK', 'Webhook Trigger'), ('CHATOPS', 'ChatOps Trigger')], default='MANUAL', max_length=20)), ('trigger_conditions', models.JSONField(default=dict, help_text='Conditions that trigger this runbook (incident severity, category, etc.)')), ('steps', models.JSONField(default=list, help_text='List of steps to execute in order')), ('estimated_duration', models.DurationField(help_text='Estimated time to complete')), ('category', models.CharField(blank=True, max_length=100, null=True)), ('tags', models.JSONField(default=list, help_text='Tags for categorization and search')), ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('ACTIVE', 'Active'), ('INACTIVE', 'Inactive'), ('DEPRECATED', 'Deprecated')], default='DRAFT', max_length=20)), ('is_public', models.BooleanField(default=True, help_text='Whether this runbook is available to all users')), ('execution_count', models.PositiveIntegerField(default=0)), ('success_rate', models.FloatField(default=0.0, help_text='Success rate of runbook executions (0.0-1.0)', validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])), ('created_at', models.DateTimeField(auto_now_add=True)), ('updated_at', models.DateTimeField(auto_now=True)), ('last_executed_at', models.DateTimeField(blank=True, null=True)), ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_runbooks', to=settings.AUTH_USER_MODEL)), ('last_modified_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='modified_runbooks', to=settings.AUTH_USER_MODEL)), ], options={ 'ordering': ['name'], }, ), migrations.CreateModel( name='ChatOpsCommand', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('command', models.CharField(help_text='The command that was executed', max_length=100)), ('arguments', models.JSONField(default=list, help_text='Command arguments')), ('user_id', models.CharField(help_text='User ID from chat platform', max_length=100)), ('channel_id', models.CharField(help_text='Channel ID where command was executed', max_length=100)), ('status', models.CharField(choices=[('PENDING', 'Pending'), ('EXECUTING', 'Executing'), ('COMPLETED', 'Completed'), ('FAILED', 'Failed'), ('CANCELLED', 'Cancelled')], default='PENDING', max_length=20)), ('response_message', models.TextField(blank=True, null=True)), ('execution_log', models.JSONField(default=list, help_text='Detailed execution log')), ('error_message', models.TextField(blank=True, null=True)), ('executed_at', models.DateTimeField(auto_now_add=True)), ('completed_at', models.DateTimeField(blank=True, null=True)), ('related_incident', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='chatops_commands', to='incident_intelligence.incident')), ('chatops_integration', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commands', to='automation_orchestration.chatopsintegration')), ('triggered_runbook', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='chatops_triggers', to='automation_orchestration.runbook')), ], options={ 'ordering': ['-executed_at'], }, ), migrations.CreateModel( name='RunbookExecution', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('trigger_type', models.CharField(choices=[('MANUAL', 'Manual Trigger'), ('AUTOMATIC', 'Automatic Trigger'), ('SCHEDULED', 'Scheduled Trigger'), ('WEBHOOK', 'Webhook Trigger'), ('CHATOPS', 'ChatOps Trigger')], max_length=20)), ('trigger_data', models.JSONField(default=dict, help_text='Data that triggered the execution')), ('status', models.CharField(choices=[('PENDING', 'Pending'), ('RUNNING', 'Running'), ('COMPLETED', 'Completed'), ('FAILED', 'Failed'), ('CANCELLED', 'Cancelled'), ('TIMEOUT', 'Timeout')], default='PENDING', max_length=20)), ('current_step', models.PositiveIntegerField(default=0)), ('total_steps', models.PositiveIntegerField()), ('execution_log', models.JSONField(default=list, help_text='Detailed execution log')), ('error_message', models.TextField(blank=True, null=True)), ('output_data', models.JSONField(default=dict, help_text='Output data from execution')), ('started_at', models.DateTimeField(auto_now_add=True)), ('completed_at', models.DateTimeField(blank=True, null=True)), ('duration', models.DurationField(blank=True, null=True)), ('incident', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='runbook_executions', to='incident_intelligence.incident')), ('runbook', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='executions', to='automation_orchestration.runbook')), ('triggered_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), ], options={ 'ordering': ['-started_at'], }, ), migrations.CreateModel( name='WorkflowTemplate', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('name', models.CharField(max_length=200, unique=True)), ('description', models.TextField()), ('template_type', models.CharField(choices=[('INCIDENT_RESPONSE', 'Incident Response'), ('DEPLOYMENT', 'Deployment'), ('MAINTENANCE', 'Maintenance'), ('SCALING', 'Scaling'), ('MONITORING', 'Monitoring'), ('CUSTOM', 'Custom')], max_length=30)), ('workflow_steps', models.JSONField(default=list, help_text='List of workflow steps with conditions and actions')), ('input_parameters', models.JSONField(default=list, help_text='Required input parameters for the workflow')), ('output_schema', models.JSONField(default=dict, help_text='Expected output schema')), ('usage_count', models.PositiveIntegerField(default=0)), ('is_public', models.BooleanField(default=True)), ('created_at', models.DateTimeField(auto_now_add=True)), ('updated_at', models.DateTimeField(auto_now=True)), ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), ], options={ 'ordering': ['name'], }, ), migrations.CreateModel( name='WorkflowExecution', fields=[ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('name', models.CharField(help_text='Name for this execution instance', max_length=200)), ('trigger_type', models.CharField(choices=[('MANUAL', 'Manual Trigger'), ('AUTOMATIC', 'Automatic Trigger'), ('SCHEDULED', 'Scheduled Trigger'), ('WEBHOOK', 'Webhook Trigger'), ('CHATOPS', 'ChatOps Trigger')], max_length=20)), ('status', models.CharField(choices=[('PENDING', 'Pending'), ('RUNNING', 'Running'), ('COMPLETED', 'Completed'), ('FAILED', 'Failed'), ('CANCELLED', 'Cancelled'), ('PAUSED', 'Paused')], default='PENDING', max_length=20)), ('current_step', models.PositiveIntegerField(default=0)), ('total_steps', models.PositiveIntegerField()), ('input_data', models.JSONField(default=dict, help_text='Input data for the workflow')), ('output_data', models.JSONField(default=dict, help_text='Output data from the workflow')), ('execution_log', models.JSONField(default=list, help_text='Detailed execution log')), ('error_message', models.TextField(blank=True, null=True)), ('started_at', models.DateTimeField(auto_now_add=True)), ('completed_at', models.DateTimeField(blank=True, null=True)), ('duration', models.DurationField(blank=True, null=True)), ('related_incident', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='workflow_executions', to='incident_intelligence.incident')), ('related_maintenance', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='workflow_executions', to='automation_orchestration.maintenancewindow')), ('triggered_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), ('workflow_template', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='executions', to='automation_orchestration.workflowtemplate')), ], options={ 'ordering': ['-started_at'], }, ), migrations.AddIndex( model_name='autoremediation', index=models.Index(fields=['remediation_type', 'is_active'], name='automation__remedia_3c1fa8_idx'), ), migrations.AddIndex( model_name='autoremediation', index=models.Index(fields=['trigger_condition_type'], name='automation__trigger_264d7b_idx'), ), migrations.AddIndex( model_name='autoremediationexecution', index=models.Index(fields=['auto_remediation', 'status'], name='automation__auto_re_e8a9e2_idx'), ), migrations.AddIndex( model_name='autoremediationexecution', index=models.Index(fields=['incident', 'status'], name='automation__inciden_a63d49_idx'), ), migrations.AddIndex( model_name='autoremediationexecution', index=models.Index(fields=['triggered_at'], name='automation__trigger_8ef9fa_idx'), ), migrations.AddIndex( model_name='chatopsintegration', index=models.Index(fields=['platform', 'is_active'], name='automation__platfor_7d4e29_idx'), ), migrations.AddIndex( model_name='integration', index=models.Index(fields=['integration_type', 'status'], name='automation__integra_6734a8_idx'), ), migrations.AddIndex( model_name='integration', index=models.Index(fields=['status', 'health_status'], name='automation__status_30ecd5_idx'), ), migrations.AddIndex( model_name='maintenancewindow', index=models.Index(fields=['start_time', 'end_time'], name='automation__start_t_b3c4cd_idx'), ), migrations.AddIndex( model_name='maintenancewindow', index=models.Index(fields=['status'], name='automation__status_da957b_idx'), ), migrations.AddIndex( model_name='runbook', index=models.Index(fields=['status', 'trigger_type'], name='automation__status_bfcafe_idx'), ), migrations.AddIndex( model_name='runbook', index=models.Index(fields=['category'], name='automation__categor_dd8bc8_idx'), ), migrations.AddIndex( model_name='runbook', index=models.Index(fields=['created_at'], name='automation__created_ad879a_idx'), ), migrations.AddIndex( model_name='chatopscommand', index=models.Index(fields=['chatops_integration', 'status'], name='automation__chatops_3b0b3a_idx'), ), migrations.AddIndex( model_name='chatopscommand', index=models.Index(fields=['user_id', 'executed_at'], name='automation__user_id_390588_idx'), ), migrations.AddIndex( model_name='chatopscommand', index=models.Index(fields=['channel_id', 'executed_at'], name='automation__channel_35c09f_idx'), ), migrations.AddIndex( model_name='runbookexecution', index=models.Index(fields=['runbook', 'status'], name='automation__runbook_534aaf_idx'), ), migrations.AddIndex( model_name='runbookexecution', index=models.Index(fields=['triggered_by', 'started_at'], name='automation__trigger_05e907_idx'), ), migrations.AddIndex( model_name='runbookexecution', index=models.Index(fields=['incident', 'status'], name='automation__inciden_4231a4_idx'), ), migrations.AddIndex( model_name='workflowtemplate', index=models.Index(fields=['template_type', 'is_public'], name='automation__templat_3aecbb_idx'), ), migrations.AddIndex( model_name='workflowexecution', index=models.Index(fields=['workflow_template', 'status'], name='automation__workflo_1a0d89_idx'), ), migrations.AddIndex( model_name='workflowexecution', index=models.Index(fields=['triggered_by', 'started_at'], name='automation__trigger_072811_idx'), ), migrations.AddIndex( model_name='workflowexecution', index=models.Index(fields=['related_incident', 'status'], name='automation__related_08164b_idx'), ), ]