diff --git a/latest_migrations.manifest b/latest_migrations.manifest index 0f95d248d4675..594614ffad06d 100644 --- a/latest_migrations.manifest +++ b/latest_migrations.manifest @@ -5,7 +5,7 @@ contenttypes: 0002_remove_content_type_name ee: 0015_add_verified_properties otp_static: 0002_throttling otp_totp: 0002_auto_20190420_0723 -posthog: 0351_team_surveys_opt_in +posthog: 0352_auto_20230926_1833 sessions: 0001_initial social_django: 0010_uid_db_index two_factor: 0007_auto_20201201_1019 diff --git a/posthog/migrations/0352_auto_20230926_1833.py b/posthog/migrations/0352_auto_20230926_1833.py new file mode 100644 index 0000000000000..388c0bae91cff --- /dev/null +++ b/posthog/migrations/0352_auto_20230926_1833.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.19 on 2023-09-26 18:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("posthog", "0351_team_surveys_opt_in"), + ] + + operations = [ + migrations.AddField( + model_name="messagingrecord", + name="campaign_count", + field=models.IntegerField(null=True), + ), + migrations.RunSQL( + sql=""" + CREATE UNIQUE INDEX CONCURRENTLY idx_messagingrecord_unique_on_email_hash_campaign_key_campaign_count + ON posthog_messagingrecord (email_hash, campaign_key, campaign_count); + """, + reverse_sql=""" + DROP INDEX CONCURRENTLY "idx_messagingrecord_unique_on_email_hash_campaign_key_campaign_count"; + """, + ), + ] diff --git a/posthog/models/messaging.py b/posthog/models/messaging.py index ee0cea515d584..c1a787e30d309 100644 --- a/posthog/models/messaging.py +++ b/posthog/models/messaging.py @@ -21,11 +21,12 @@ def get_or_create(self, defaults=None, **kwargs): class MessagingRecord(UUIDModel): - objects = MessagingRecordManager() email_hash: models.CharField = models.CharField(max_length=1024) campaign_key: models.CharField = models.CharField(max_length=128) + # Numeric indicator for repeat emails of the same campaign key + campaign_count: models.IntegerField = models.IntegerField(null=True) sent_at: models.DateTimeField = models.DateTimeField(null=True) created_at: models.DateTimeField = models.DateTimeField(auto_now_add=True)