Skip to content

Commit

Permalink
feat: change unique idx on messsaging table (#17636)
Browse files Browse the repository at this point in the history
* change unique idx on messsaging table

* not atomic
  • Loading branch information
raquelmsmith authored Oct 5, 2023
1 parent cc2c28a commit 025ed3d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion latest_migrations.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions posthog/migrations/0352_auto_20230926_1833.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.19 on 2023-09-26 18:33

from django.db import migrations, models


class Migration(migrations.Migration):
atomic = False # Cannot create index concurrently atomically

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";
""",
),
]
3 changes: 2 additions & 1 deletion posthog/models/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 025ed3d

Please sign in to comment.