Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

12.4 KB
Raw Blame
# Generated by Django 5.2.14 on 2026-07-13 13:36

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

import posthog.models.utils

import products.stamphog.backend.facade.enums


class Migration(migrations.Migration):
    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="DigestChannel",
            fields=[
                ("team_id", models.BigIntegerField(db_index=True)),
                (
                    "id",
                    models.UUIDField(
                        default=posthog.models.utils.uuid7,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("audience_key", models.CharField(max_length=255)),
                ("slack_integration_id", models.BigIntegerField()),
                ("slack_channel_id", models.CharField(max_length=64)),
                ("slack_channel_name", models.CharField(blank=True, max_length=255)),
                (
                    "resolution_source",
                    models.CharField(
                        choices=[
                            ("manual", "manual"),
                            ("slack_name_match", "slack_name_match"),
                            ("stamphog_config", "stamphog_config"),
                            ("owners_contact", "owners_contact"),
                        ],
                        default=products.stamphog.backend.facade.enums.ChannelResolutionSource["MANUAL"],
                        max_length=32,
                    ),
                ),
                ("enabled", models.BooleanField(default=True)),
                ("last_digest_at", models.DateTimeField(null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "default_manager_name": "all_teams",
                "constraints": [
                    models.UniqueConstraint(
                        fields=("team_id", "audience_key"),
                        name="unique_stamphog_digest_audience_per_team",
                    )
                ],
            },
            managers=[
                ("all_teams", django.db.models.manager.Manager()),
            ],
        ),
        migrations.CreateModel(
            name="DigestRun",
            fields=[
                ("team_id", models.BigIntegerField(db_index=True)),
                (
                    "id",
                    models.UUIDField(
                        default=posthog.models.utils.uuid7,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "pending"),
                            ("completed", "completed"),
                            ("failed", "failed"),
                        ],
                        default=products.stamphog.backend.facade.enums.DigestRunStatus["PENDING"],
                        max_length=32,
                    ),
                ),
                ("pr_count", models.IntegerField(default=0)),
                ("summary", models.JSONField(default=dict)),
                ("slack_message_ts", models.CharField(blank=True, max_length=32)),
                ("error", models.TextField(blank=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("posted_at", models.DateTimeField(null=True)),
                (
                    "digest_channel",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="runs",
                        to="stamphog.digestchannel",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "default_manager_name": "all_teams",
            },
            managers=[
                ("all_teams", django.db.models.manager.Manager()),
            ],
        ),
        migrations.CreateModel(
            name="StamphogRepoConfig",
            fields=[
                ("team_id", models.BigIntegerField(db_index=True)),
                (
                    "id",
                    models.UUIDField(
                        default=posthog.models.utils.uuid7,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("provider", models.CharField(default="github", max_length=32)),
                ("repository", models.CharField(max_length=255)),
                ("enabled", models.BooleanField(default=True)),
                ("installation_id", models.CharField(max_length=64)),
                ("digest_enabled", models.BooleanField(default=False)),
                (
                    "review_mode",
                    models.CharField(
                        choices=[("all", "all"), ("label", "label")],
                        default=products.stamphog.backend.facade.enums.ReviewMode["ALL"],
                        max_length=16,
                    ),
                ),
                ("trigger_label", models.CharField(default="stamphog", max_length=100)),
                ("connected_by_user_id", models.BigIntegerField(blank=True, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "default_manager_name": "all_teams",
                "constraints": [
                    models.UniqueConstraint(
                        fields=("team_id", "repository"),
                        name="unique_stamphog_repo_per_team",
                    ),
                    models.UniqueConstraint(
                        condition=models.Q(("installation_id", ""), _negated=True),
                        fields=("provider", "installation_id", "repository"),
                        name="unique_stamphog_installation_repo",
                    ),
                ],
            },
            managers=[
                ("all_teams", django.db.models.manager.Manager()),
            ],
        ),
        migrations.CreateModel(
            name="PullRequest",
            fields=[
                ("team_id", models.BigIntegerField(db_index=True)),
                (
                    "id",
                    models.UUIDField(
                        default=posthog.models.utils.uuid7,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("pr_number", models.IntegerField()),
                ("title", models.CharField(blank=True, max_length=512)),
                ("author_login", models.CharField(blank=True, max_length=255)),
                ("pr_url", models.CharField(blank=True, max_length=512)),
                ("head_branch", models.CharField(blank=True, max_length=255)),
                ("body_excerpt", models.TextField(blank=True)),
                ("merged_at", models.DateTimeField(null=True)),
                ("merge_commit_sha", models.CharField(blank=True, max_length=64)),
                ("additions", models.IntegerField(default=0)),
                ("deletions", models.IntegerField(default=0)),
                ("changed_files", models.IntegerField(default=0)),
                ("audience_key", models.CharField(blank=True, max_length=255)),
                ("posted_comment_id", models.BigIntegerField(null=True)),
                ("payload_updated_at", models.DateTimeField(null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "digest_run",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="pull_requests",
                        to="stamphog.digestrun",
                    ),
                ),
                (
                    "repo_config",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="pull_requests",
                        to="stamphog.stamphogrepoconfig",
                    ),
                ),
            ],
            options={
                "default_manager_name": "all_teams",
            },
            managers=[
                ("all_teams", django.db.models.manager.Manager()),
            ],
        ),
        migrations.CreateModel(
            name="ReviewRun",
            fields=[
                ("team_id", models.BigIntegerField(db_index=True)),
                (
                    "id",
                    models.UUIDField(
                        default=posthog.models.utils.uuid7,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("head_sha", models.CharField(max_length=64)),
                (
                    "delivery_id",
                    models.CharField(max_length=64, null=True, unique=True),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("queued", "queued"),
                            ("gated", "gated"),
                            ("reviewing", "reviewing"),
                            ("completed", "completed"),
                            ("failed", "failed"),
                            ("superseded", "superseded"),
                        ],
                        default=products.stamphog.backend.facade.enums.ReviewRunStatus["QUEUED"],
                        max_length=32,
                    ),
                ),
                (
                    "verdict",
                    models.CharField(
                        choices=[
                            ("none", "none"),
                            ("approved", "approved"),
                            ("refused", "refused"),
                            ("escalate", "escalate"),
                            ("wait", "wait"),
                            ("error", "error"),
                        ],
                        default=products.stamphog.backend.facade.enums.ReviewVerdict["NONE"],
                        max_length=32,
                    ),
                ),
                ("gate_result", models.JSONField(null=True)),
                ("output", models.JSONField(default=dict)),
                ("error", models.TextField(blank=True)),
                ("verdict_posted_at", models.DateTimeField(null=True)),
                ("posted_review_id", models.BigIntegerField(null=True)),
                ("approval_dismissed_at", models.DateTimeField(null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("completed_at", models.DateTimeField(null=True)),
                (
                    "pull_request",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="review_runs",
                        to="stamphog.pullrequest",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "default_manager_name": "all_teams",
            },
            managers=[
                ("all_teams", django.db.models.manager.Manager()),
            ],
        ),
        migrations.AddIndex(
            model_name="pullrequest",
            index=models.Index(
                condition=models.Q(("digest_run__isnull", True)),
                fields=["team_id", "audience_key", "merged_at"],
                name="stamphog_pr_pending_digest",
            ),
        ),
        migrations.AddConstraint(
            model_name="pullrequest",
            constraint=models.UniqueConstraint(
                fields=("team_id", "repo_config", "pr_number"),
                name="unique_stamphog_pull_request",
            ),
        ),
    ]