Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add session and sprint UUID fields to fires #5832

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.1.4 on 2025-01-29 18:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("contacts", "0199_contactfire"),
]

operations = [
migrations.AddField(
model_name="contactfire",
name="session_uuid",
field=models.UUIDField(null=True),
),
migrations.AddField(
model_name="contactfire",
name="sprint_uuid",
field=models.UUIDField(null=True),
),
migrations.AlterField(
model_name="contactfire",
name="extra",
field=models.JSONField(null=True),
),
]
8 changes: 7 additions & 1 deletion temba/contacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,9 +1751,15 @@ class ContactFire(models.Model):
contact = models.ForeignKey(Contact, on_delete=models.PROTECT, related_name="fires", db_index=False) # index below
fire_type = models.CharField(max_length=1, choices=TYPE_CHOICES)
scope = models.CharField(max_length=64) # e.g. campaign event id
extra = models.JSONField(default=dict) # e.g. session id
fire_on = models.DateTimeField(db_index=True)

# used to ensure wait events don't act on a session that's already changed
session_uuid = models.UUIDField(null=True)
sprint_uuid = models.UUIDField(null=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no foreign keys.. don't want the index overhead and thinking ahead to when sessions might not be in the database at all


# TODO remove
extra = models.JSONField(null=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I was trying to be too generic..


class Meta:
constraints = [
# used to prevent adding duplicate fires for the same contact and scope
Expand Down
18 changes: 18 additions & 0 deletions temba/flows/migrations/0364_flowsession_last_sprint_uuid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.4 on 2025-01-29 18:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("flows", "0363_alter_flowsession_status"),
]

operations = [
migrations.AddField(
model_name="flowsession",
name="last_sprint_uuid",
field=models.UUIDField(null=True),
),
]
1 change: 1 addition & 0 deletions temba/flows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ class FlowSession(models.Model):
org = models.ForeignKey(Org, related_name="sessions", on_delete=models.PROTECT)
contact = models.ForeignKey("contacts.Contact", on_delete=models.PROTECT, related_name="sessions")
status = models.CharField(max_length=1, choices=STATUS_CHOICES)
last_sprint_uuid = models.UUIDField(null=True) # last sprint in this session

# the modality of this session
session_type = models.CharField(max_length=1, choices=Flow.TYPE_CHOICES, default=Flow.TYPE_MESSAGE)
Expand Down