: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(tasks): add task pin table (#74596)
Alessandro Pogliaghi39bed25a2196
diff --git a/.semgrep/rules/security/idor-team-scoped-models.yaml b/.semgrep/rules/security/idor-team-scoped-models.yamlindex 3182729c4e9a..732f15859cb4 100644--- a/.semgrep/rules/security/idor-team-scoped-models.yaml+++ b/.semgrep/rules/security/idor-team-scoped-models.yaml@@ -902,6 +902,7 @@ rules:|PersonalAPIKey|ScoreDefinitionVersion|SignalUserAutonomyConfig+ |TaskPin|UserPushToken|WebauthnCredential)$@@ -956,6 +957,7 @@ rules:|PersonalAPIKey|ScoreDefinitionVersion|SignalUserAutonomyConfig+ |TaskPin|UserPushToken|WebauthnCredential)$diff --git a/products/tasks/backend/migrations/0075_task_pin.py b/products/tasks/backend/migrations/0075_task_pin.pynew file mode 100644index 000000000000..113e0394f400--- /dev/null+++ b/products/tasks/backend/migrations/0075_task_pin.py@@ -0,0 +1,40 @@+import django.utils.timezone+import django.db.models.deletion+from django.db import migrations, models++import posthog.uuidt+++class Migration(migrations.Migration):+ dependencies = [("tasks", "0074_task_session")]++ operations = [+ migrations.CreateModel(+ name="TaskPin",+ fields=[+ (+ "id",+ models.UUIDField(default=posthog.uuidt.uuid7, editable=False, primary_key=True, serialize=False),+ ),+ ("pinned_at", models.DateTimeField(default=django.utils.timezone.now)),+ (+ "task",+ models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name="+", to="tasks.task"),+ ),+ (+ "user",+ models.ForeignKey(+ db_constraint=False,+ on_delete=django.db.models.deletion.CASCADE,+ related_name="+",+ to="posthog.user",+ ),+ ),+ ],+ options={+ "db_table": "posthog_task_pin",+ "indexes": [models.Index(fields=["user", "-pinned_at"], name="task_pin_user_pinned_idx")],+ "constraints": [models.UniqueConstraint(fields=("user", "task"), name="task_pin_user_task_unique")],+ },+ ),+ ]diff --git a/products/tasks/backend/migrations/max_migration.txt b/products/tasks/backend/migrations/max_migration.txtindex 4fc010358639..718239371425 100644--- a/products/tasks/backend/migrations/max_migration.txt+++ b/products/tasks/backend/migrations/max_migration.txt@@ -1 +1 @@-0074_task_session+0075_task_pindiff --git a/products/tasks/backend/models.py b/products/tasks/backend/models.pyindex 67772255cc88..0d3aa5d3737e 100644--- a/products/tasks/backend/models.py+++ b/products/tasks/backend/models.py@@ -1096,6 +1096,18 @@ class TaskActivity(TeamScopedRootMixin):)+class TaskPin(models.Model):+ id = models.UUIDField(primary_key=True, default=uuid7, editable=False)+ user = models.ForeignKey("posthog.User", on_delete=models.CASCADE, related_name="+", db_constraint=False)+ task = models.ForeignKey(Task, on_delete=models.CASCADE, related_name="+")+ pinned_at = models.DateTimeField(default=django_timezone.now)++ class Meta:+ db_table = "posthog_task_pin"+ constraints = [models.UniqueConstraint(fields=["user", "task"], name="task_pin_user_task_unique")]+ indexes = [models.Index(fields=["user", "-pinned_at"], name="task_pin_user_pinned_idx")]++@receiver(post_save, sender=Task)def project_task_created_activity(sender, instance: Task, created: bool, **kwargs) -> None:"""Seed the creator's activity row. A signal rather than a facade call because tasks are