Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

12.6 KB
Raw Blame
# Generated by Django 4.2.1 on 2025-01-08

import uuid

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("account_v2", "0002_user_auth_provider"),
    ]

    operations = [
        # Create EventMetricsHourly table
        migrations.CreateModel(
            name="EventMetricsHourly",
            fields=[
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("modified_at", models.DateTimeField(auto_now=True)),
                (
                    "id",
                    models.UUIDField(
                        db_comment="Primary key UUID, auto-generated",
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "timestamp",
                    models.DateTimeField(
                        db_comment="Hour bucket timestamp (truncated to hour)",
                        db_index=True,
                    ),
                ),
                (
                    "metric_name",
                    models.CharField(
                        db_comment="Metric identifier from MetricName enum",
                        db_index=True,
                        max_length=64,
                    ),
                ),
                (
                    "metric_type",
                    models.CharField(
                        choices=[("counter", "Counter"), ("histogram", "Histogram")],
                        db_comment="Type of metric (counter or histogram)",
                        default="counter",
                        max_length=16,
                    ),
                ),
                (
                    "metric_value",
                    models.FloatField(
                        db_comment="Aggregated value (sum for counters, sum for histograms)",
                        default=0,
                    ),
                ),
                (
                    "metric_count",
                    models.IntegerField(
                        db_comment="Number of events aggregated into this record",
                        default=1,
                    ),
                ),
                (
                    "project",
                    models.CharField(
                        db_comment="Project identifier for filtering",
                        db_index=True,
                        default="default",
                        max_length=64,
                    ),
                ),
                (
                    "tag",
                    models.CharField(
                        blank=True,
                        db_comment="Optional tag for categorization",
                        default="",
                        max_length=64,
                    ),
                ),
                (
                    "organization",
                    models.ForeignKey(
                        blank=True,
                        db_comment="Foreign key reference to the Organization model.",
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="account_v2.organization",
                    ),
                ),
            ],
            options={
                "verbose_name": "Event Metric (Hourly)",
                "verbose_name_plural": "Event Metrics (Hourly)",
                "db_table": "event_metrics_hourly",
                "indexes": [
                    models.Index(
                        fields=["organization", "timestamp"], name="idx_metrics_org_ts"
                    ),
                    models.Index(
                        fields=["organization", "metric_name", "timestamp"],
                        name="idx_metrics_org_name_ts",
                    ),
                    models.Index(
                        fields=["project", "timestamp"], name="idx_metrics_project_ts"
                    ),
                ],
            },
        ),
        migrations.AddConstraint(
            model_name="eventmetricshourly",
            constraint=models.UniqueConstraint(
                fields=("organization", "timestamp", "metric_name", "project", "tag"),
                name="unique_hourly_metric",
            ),
        ),
        # Create EventMetricsDaily table
        migrations.CreateModel(
            name="EventMetricsDaily",
            fields=[
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("modified_at", models.DateTimeField(auto_now=True)),
                (
                    "id",
                    models.UUIDField(
                        db_comment="Primary key UUID, auto-generated",
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "date",
                    models.DateField(
                        db_comment="Day bucket (date only)",
                        db_index=True,
                    ),
                ),
                (
                    "metric_name",
                    models.CharField(
                        db_comment="Metric identifier from MetricName enum",
                        db_index=True,
                        max_length=64,
                    ),
                ),
                (
                    "metric_type",
                    models.CharField(
                        choices=[("counter", "Counter"), ("histogram", "Histogram")],
                        db_comment="Type of metric (counter or histogram)",
                        default="counter",
                        max_length=16,
                    ),
                ),
                (
                    "metric_value",
                    models.FloatField(
                        db_comment="Aggregated value (sum for counters)",
                        default=0,
                    ),
                ),
                (
                    "metric_count",
                    models.IntegerField(
                        db_comment="Number of events aggregated into this record",
                        default=1,
                    ),
                ),
                (
                    "project",
                    models.CharField(
                        db_comment="Project identifier for filtering",
                        db_index=True,
                        default="default",
                        max_length=64,
                    ),
                ),
                (
                    "tag",
                    models.CharField(
                        blank=True,
                        db_comment="Optional tag for categorization",
                        default="",
                        max_length=64,
                    ),
                ),
                (
                    "organization",
                    models.ForeignKey(
                        blank=True,
                        db_comment="Foreign key reference to the Organization model.",
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="account_v2.organization",
                    ),
                ),
            ],
            options={
                "verbose_name": "Event Metric (Daily)",
                "verbose_name_plural": "Event Metrics (Daily)",
                "db_table": "event_metrics_daily",
                "indexes": [
                    models.Index(
                        fields=["organization", "date"],
                        name="idx_daily_org_date",
                    ),
                    models.Index(
                        fields=["organization", "metric_name", "date"],
                        name="idx_daily_org_name_date",
                    ),
                    models.Index(
                        fields=["project", "date"],
                        name="idx_daily_project_date",
                    ),
                ],
            },
        ),
        migrations.AddConstraint(
            model_name="eventmetricsdaily",
            constraint=models.UniqueConstraint(
                fields=("organization", "date", "metric_name", "project", "tag"),
                name="unique_daily_metric",
            ),
        ),
        # Create EventMetricsMonthly table
        migrations.CreateModel(
            name="EventMetricsMonthly",
            fields=[
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("modified_at", models.DateTimeField(auto_now=True)),
                (
                    "id",
                    models.UUIDField(
                        db_comment="Primary key UUID, auto-generated",
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "month",
                    models.DateField(
                        db_comment="First day of month bucket",
                        db_index=True,
                    ),
                ),
                (
                    "metric_name",
                    models.CharField(
                        db_comment="Metric identifier from MetricName enum",
                        db_index=True,
                        max_length=64,
                    ),
                ),
                (
                    "metric_type",
                    models.CharField(
                        choices=[("counter", "Counter"), ("histogram", "Histogram")],
                        db_comment="Type of metric (counter or histogram)",
                        default="counter",
                        max_length=16,
                    ),
                ),
                (
                    "metric_value",
                    models.FloatField(
                        db_comment="Aggregated value (sum for counters)",
                        default=0,
                    ),
                ),
                (
                    "metric_count",
                    models.IntegerField(
                        db_comment="Number of events aggregated into this record",
                        default=1,
                    ),
                ),
                (
                    "project",
                    models.CharField(
                        db_comment="Project identifier for filtering",
                        db_index=True,
                        default="default",
                        max_length=64,
                    ),
                ),
                (
                    "tag",
                    models.CharField(
                        blank=True,
                        db_comment="Optional tag for categorization",
                        default="",
                        max_length=64,
                    ),
                ),
                (
                    "organization",
                    models.ForeignKey(
                        blank=True,
                        db_comment="Foreign key reference to the Organization model.",
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="account_v2.organization",
                    ),
                ),
            ],
            options={
                "verbose_name": "Event Metric (Monthly)",
                "verbose_name_plural": "Event Metrics (Monthly)",
                "db_table": "event_metrics_monthly",
                "indexes": [
                    models.Index(
                        fields=["organization", "month"],
                        name="idx_monthly_org_month",
                    ),
                    models.Index(
                        fields=["organization", "metric_name", "month"],
                        name="idx_monthly_org_name_month",
                    ),
                    models.Index(
                        fields=["project", "month"],
                        name="idx_monthly_project_month",
                    ),
                ],
            },
        ),
        migrations.AddConstraint(
            model_name="eventmetricsmonthly",
            constraint=models.UniqueConstraint(
                fields=("organization", "month", "metric_name", "project", "tag"),
                name="unique_monthly_metric",
            ),
        ),
    ]