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.

1.5 KB
Raw Blame
# Generated by Michael M

from django.db import migrations, models


class Migration(migrations.Migration):
    atomic = False  # Required for CREATE INDEX CONCURRENTLY

    dependencies = [
        ("ee", "0034_conversation_slack_fields"),
    ]

    operations = [
        # Create partial unique index concurrently to avoid table lock.
        # Partial indexes can't be converted to constraints, but the index alone enforces uniqueness.
        # SeparateDatabaseAndState keeps Django's state in sync with raw SQL.
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.AddConstraint(
                    model_name="conversation",
                    constraint=models.UniqueConstraint(
                        condition=models.Q(("slack_thread_key__isnull", False)),
                        fields=("team", "slack_thread_key"),
                        name="unique_team_slack_thread_key",
                    ),
                ),
            ],
            database_operations=[
                migrations.RunSQL(
                    sql="""
                        CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS unique_team_slack_thread_key
                        ON ee_conversation (team_id, slack_thread_key)
                        WHERE slack_thread_key IS NOT NULL
                    """,
                    reverse_sql="DROP INDEX CONCURRENTLY IF EXISTS unique_team_slack_thread_key",
                ),
            ],
        ),
    ]