from django.db import models from django.utils import timezone class ProjectAction(models.Model): class StatusChoices(models.TextChoices): SUCCESS = "success" ERROR = "error" CANCELLED = "cancelled" TIMEOUT = "timeout" project = models.ForeignKey( "labs.Project", on_delete=models.PROTECT, ) email = models.EmailField(max_length=254) statement_type = models.CharField(max_length=50) sql_text = models.TextField() status = models.CharField( max_length=10, choices=StatusChoices.choices, default=StatusChoices.SUCCESS, ) duration_ms = models.IntegerField(null=True, blank=True) error_code = models.CharField(max_length=64, null=True, blank=True) executed_at = models.DateTimeField(default=timezone.now) created_at = models.DateTimeField(auto_now_add=True) class Meta: db_table = "project_actions" indexes = [ models.Index(fields=["project", "executed_at"], name="idx_project_time"), models.Index(fields=["email", "executed_at"], name="idx_email_time"), models.Index(fields=["statement_type", "executed_at"], name="idx_stmt_time"), ]