From 632bb8d8c658e5083d845ee60829cec9d1453144 Mon Sep 17 00:00:00 2001 From: David Newell Date: Thu, 24 Oct 2024 15:25:57 +0100 Subject: [PATCH] chore: create issue fingerprint table in postgres (#25690) --- latest_migrations.manifest | 2 +- ..._errortrackingissuefingerprint_and_more.py | 33 +++++++++++++++++++ .../models/error_tracking/error_tracking.py | 11 +++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 posthog/migrations/0498_errortrackingissuefingerprint_and_more.py diff --git a/latest_migrations.manifest b/latest_migrations.manifest index 8842f6c11851d..706c12ae7f1ef 100644 --- a/latest_migrations.manifest +++ b/latest_migrations.manifest @@ -5,7 +5,7 @@ contenttypes: 0002_remove_content_type_name ee: 0016_rolemembership_organization_member otp_static: 0002_throttling otp_totp: 0002_auto_20190420_0723 -posthog: 0497_experimentholdout_experiment_holdout +posthog: 0498_errortrackingissuefingerprint_and_more sessions: 0001_initial social_django: 0010_uid_db_index two_factor: 0007_auto_20201201_1019 diff --git a/posthog/migrations/0498_errortrackingissuefingerprint_and_more.py b/posthog/migrations/0498_errortrackingissuefingerprint_and_more.py new file mode 100644 index 0000000000000..cae2e30d9feea --- /dev/null +++ b/posthog/migrations/0498_errortrackingissuefingerprint_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.15 on 2024-10-24 13:21 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("posthog", "0497_experimentholdout_experiment_holdout"), + ] + + operations = [ + migrations.CreateModel( + name="ErrorTrackingIssueFingerprint", + fields=[ + ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), + ("fingerprint", models.TextField()), + ("version", models.BigIntegerField(blank=True, default=0)), + ( + "issue", + models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posthog.errortrackinggroup"), + ), + ( + "team", + models.ForeignKey(db_index=False, on_delete=django.db.models.deletion.CASCADE, to="posthog.team"), + ), + ], + ), + migrations.AddConstraint( + model_name="errortrackingissuefingerprint", + constraint=models.UniqueConstraint(fields=("team", "fingerprint"), name="unique fingerprint for team"), + ), + ] diff --git a/posthog/models/error_tracking/error_tracking.py b/posthog/models/error_tracking/error_tracking.py index 1007e12699863..7e4c625446520 100644 --- a/posthog/models/error_tracking/error_tracking.py +++ b/posthog/models/error_tracking/error_tracking.py @@ -58,3 +58,14 @@ def convert_fingerprints_to_tuples(fps: list[list[str]]): # converting back to list of lists before saving self.merged_fingerprints = [list(f) for f in merged_fingerprints] self.save() + + +class ErrorTrackingIssueFingerprint(models.Model): + team = models.ForeignKey("Team", on_delete=models.CASCADE, db_index=False) + issue = models.ForeignKey(ErrorTrackingGroup, on_delete=models.CASCADE) + fingerprint = models.TextField(null=False, blank=False) + # current version of the id, used to sync with ClickHouse and collapse rows correctly for overrides ClickHouse table + version = models.BigIntegerField(blank=True, default=0) + + class Meta: + constraints = [models.UniqueConstraint(fields=["team", "fingerprint"], name="unique fingerprint for team")]