fix fix fix

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-01 00:13:46 +00:00
parent 90b532d13b
commit 42bc24f2c0
11 changed files with 1592 additions and 26 deletions

View File

@@ -0,0 +1,42 @@
# Generated by Django 5.2.8 on 2025-12-01 00:05
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('igny8_core_auth', '0003_add_sync_event_model'),
('integration', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='SyncEvent',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('updated_at', models.DateTimeField(auto_now=True)),
('event_type', models.CharField(choices=[('publish', 'Content Published'), ('sync', 'Status Synced'), ('metadata_sync', 'Metadata Synced'), ('error', 'Error'), ('webhook', 'Webhook Received'), ('test', 'Connection Test')], db_index=True, help_text='Type of sync event', max_length=50)),
('action', models.CharField(choices=[('content_publish', 'Content Publish'), ('status_update', 'Status Update'), ('metadata_update', 'Metadata Update'), ('test_connection', 'Test Connection'), ('webhook_received', 'Webhook Received')], db_index=True, help_text='Specific action performed', max_length=100)),
('description', models.TextField(help_text='Human-readable description of the event')),
('success', models.BooleanField(db_index=True, default=True, help_text='Whether the event was successful')),
('content_id', models.IntegerField(blank=True, db_index=True, help_text='IGNY8 content ID if applicable', null=True)),
('external_id', models.CharField(blank=True, db_index=True, help_text='External platform ID (e.g., WordPress post ID)', max_length=255, null=True)),
('details', models.JSONField(default=dict, help_text='Additional event details (request/response data, errors, etc.)')),
('error_message', models.TextField(blank=True, help_text='Error message if event failed', null=True)),
('duration_ms', models.IntegerField(blank=True, help_text='Event duration in milliseconds', null=True)),
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('account', models.ForeignKey(db_column='tenant_id', on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_set', to='igny8_core_auth.account')),
('integration', models.ForeignKey(help_text='Integration this event belongs to', on_delete=django.db.models.deletion.CASCADE, related_name='sync_events', to='integration.siteintegration')),
('site', models.ForeignKey(help_text='Site this event belongs to', on_delete=django.db.models.deletion.CASCADE, related_name='sync_events', to='igny8_core_auth.site')),
],
options={
'verbose_name': 'Sync Event',
'verbose_name_plural': 'Sync Events',
'db_table': 'igny8_sync_events',
'ordering': ['-created_at'],
'indexes': [models.Index(fields=['integration', '-created_at'], name='idx_integration_events'), models.Index(fields=['site', '-created_at'], name='idx_site_events'), models.Index(fields=['content_id'], name='idx_content_events'), models.Index(fields=['event_type', '-created_at'], name='idx_event_type_time')],
},
),
]

View File

@@ -129,3 +129,118 @@ class SiteIntegration(AccountBaseModel):
"""
self.credentials_json = credentials
class SyncEvent(AccountBaseModel):
"""
Track sync events for debugging and monitoring.
Stores real-time events for the debug status page.
"""
EVENT_TYPE_CHOICES = [
('publish', 'Content Published'),
('sync', 'Status Synced'),
('metadata_sync', 'Metadata Synced'),
('error', 'Error'),
('webhook', 'Webhook Received'),
('test', 'Connection Test'),
]
ACTION_CHOICES = [
('content_publish', 'Content Publish'),
('status_update', 'Status Update'),
('metadata_update', 'Metadata Update'),
('test_connection', 'Test Connection'),
('webhook_received', 'Webhook Received'),
]
integration = models.ForeignKey(
SiteIntegration,
on_delete=models.CASCADE,
related_name='sync_events',
help_text="Integration this event belongs to"
)
site = models.ForeignKey(
'igny8_core_auth.Site',
on_delete=models.CASCADE,
related_name='sync_events',
help_text="Site this event belongs to"
)
event_type = models.CharField(
max_length=50,
choices=EVENT_TYPE_CHOICES,
db_index=True,
help_text="Type of sync event"
)
action = models.CharField(
max_length=100,
choices=ACTION_CHOICES,
db_index=True,
help_text="Specific action performed"
)
description = models.TextField(
help_text="Human-readable description of the event"
)
success = models.BooleanField(
default=True,
db_index=True,
help_text="Whether the event was successful"
)
# Related object references
content_id = models.IntegerField(
null=True,
blank=True,
db_index=True,
help_text="IGNY8 content ID if applicable"
)
external_id = models.CharField(
max_length=255,
null=True,
blank=True,
db_index=True,
help_text="External platform ID (e.g., WordPress post ID)"
)
# Event details (JSON for flexibility)
details = models.JSONField(
default=dict,
help_text="Additional event details (request/response data, errors, etc.)"
)
error_message = models.TextField(
null=True,
blank=True,
help_text="Error message if event failed"
)
# Duration tracking
duration_ms = models.IntegerField(
null=True,
blank=True,
help_text="Event duration in milliseconds"
)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
class Meta:
app_label = 'integration'
db_table = 'igny8_sync_events'
verbose_name = 'Sync Event'
verbose_name_plural = 'Sync Events'
ordering = ['-created_at']
indexes = [
models.Index(fields=['integration', '-created_at'], name='idx_integration_events'),
models.Index(fields=['site', '-created_at'], name='idx_site_events'),
models.Index(fields=['content_id'], name='idx_content_events'),
models.Index(fields=['event_type', '-created_at'], name='idx_event_type_time'),
]
def __str__(self):
return f"{self.get_event_type_display()} - {self.description[:50]}"