Skip to content

: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.

chore(modeling): add status index to jobs (#61171)

andrew j. mcgehee8c89787d8235
diff --git a/products/data_modeling/backend/migrations/0024_datamodelingjob_team_status_idx.py b/products/data_modeling/backend/migrations/0024_datamodelingjob_team_status_idx.py
new file mode 100644
index 000000000000..52d2813d850d
--- /dev/null
+++ b/products/data_modeling/backend/migrations/0024_datamodelingjob_team_status_idx.py
@@ -0,0 +1,32 @@
+from django.conf import settings
+from django.db import migrations, models
+
+from posthog.migration_helpers import CreateIndexConcurrently
+
+
+class Migration(migrations.Migration):
+ atomic = False
+
+ dependencies = [
+ ("data_modeling", "0023_migrate_data_modeling_models"),
+ ("posthog", "1193_oauthaccesstoken_label_oauthapplication_scopes"),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.SeparateDatabaseAndState(
+ state_operations=[
+ migrations.AddIndex(
+ model_name="datamodelingjob",
+ index=models.Index(fields=["team", "status"], name="datamodelingjob_team_status"),
+ ),
+ ],
+ database_operations=[
+ CreateIndexConcurrently(
+ index_name="datamodelingjob_team_status",
+ table_name="posthog_datamodelingjob",
+ columns="(team_id, status)",
+ ),
+ ],
+ ),
+ ]
diff --git a/products/data_modeling/backend/migrations/max_migration.txt b/products/data_modeling/backend/migrations/max_migration.txt
index f879e77bb216..f1310d79b978 100644
--- a/products/data_modeling/backend/migrations/max_migration.txt
+++ b/products/data_modeling/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0023_migrate_data_modeling_models
+0024_datamodelingjob_team_status_idx
diff --git a/products/data_modeling/backend/models/data_modeling_job.py b/products/data_modeling/backend/models/data_modeling_job.py
index 6f69093914b3..b3239aa790ee 100644
--- a/products/data_modeling/backend/models/data_modeling_job.py
+++ b/products/data_modeling/backend/models/data_modeling_job.py
@@ -35,3 +35,7 @@ class DataModelingJob(CreatedMetaFields, UpdatedMetaFields, UUIDTModel):
class Meta:
db_table = "posthog_datamodelingjob"
+ indexes = [
+ # serves to cut lookup times for pre-existing running jobs during the preempt stage
+ models.Index(fields=["team", "status"], name="datamodelingjob_team_status"),
+ ]