Skip to content
Open
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
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ releases: 0001_release_models

replays: 0006_add_bulk_delete_job

sentry: 0995_add_date_updated_to_grouphash_metadata
sentry: 0996_add_dashboard_field_link_model

social_auth: 0003_social_auth_json_field

Expand Down
1 change: 1 addition & 0 deletions src/sentry/backup/comparators.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ def get_default_comparators() -> dict[str, list[JSONScrubbingComparator]]:
],
"sentry.dashboardwidgetqueryondemand": [DateUpdatedComparator("date_modified")],
"sentry.dashboardwidgetquery": [DateUpdatedComparator("date_modified")],
"sentry.dashboardfieldlink": [DateUpdatedComparator("date_modified")],
"sentry.email": [DateUpdatedComparator("date_added")],
"sentry.organization": [AutoSuffixComparator("slug")],
"sentry.organizationintegration": [DateUpdatedComparator("date_updated")],
Expand Down
62 changes: 62 additions & 0 deletions src/sentry/migrations/0996_add_dashboard_field_link_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Generated by Django 5.2.1 on 2025-10-07 19:54

import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models

import sentry.db.models.fields.bounded
import sentry.db.models.fields.foreignkey
from sentry.new_migrations.migrations import CheckedMigration


class Migration(CheckedMigration):
# This flag is used to mark that a migration shouldn't be automatically run in production.
# This should only be used for operations where it's safe to run the migration after your
# code has deployed. So this should not be used for most operations that alter the schema
# of a table.
# Here are some things that make sense to mark as post deployment:
# - Large data migrations. Typically we want these to be run manually so that they can be
# monitored and not block the deploy for a long period of time while they run.
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
# run this outside deployments so that we don't block them. Note that while adding an index
# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False

dependencies = [
("sentry", "0995_add_date_updated_to_grouphash_metadata"),
]

operations = [
migrations.CreateModel(
name="DashboardFieldLink",
fields=[
(
"id",
sentry.db.models.fields.bounded.BoundedBigAutoField(
primary_key=True, serialize=False
),
),
("field", models.TextField()),
("date_modified", models.DateTimeField(default=django.utils.timezone.now)),
(
"dashboard",
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="sentry.dashboard"
),
),
(
"dashboard_widget_query",
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="sentry.dashboardwidgetquery",
),
),
],
options={
"db_table": "sentry_dashboardfieldlink",
"unique_together": {("dashboard_widget_query", "field")},
},
),
]
18 changes: 18 additions & 0 deletions src/sentry/models/dashboard_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ class Meta:
__repr__ = sane_repr("widget", "type", "name")


@region_silo_model
class DashboardFieldLink(Model):
__relocation_scope__ = RelocationScope.Organization

dashboard_widget_query = FlexibleForeignKey(
"sentry.DashboardWidgetQuery", on_delete=models.CASCADE
)
field = models.TextField()
date_modified = models.DateTimeField(default=timezone.now)
# The dashboard that the field is linked to
dashboard = FlexibleForeignKey("sentry.Dashboard", on_delete=models.CASCADE)

class Meta:
app_label = "sentry"
db_table = "sentry_dashboardfieldlink"
unique_together = (("dashboard_widget_query", "field"),)


@region_silo_model
class DashboardWidgetQueryOnDemand(Model):
"""
Expand Down
6 changes: 6 additions & 0 deletions src/sentry/testutils/helpers/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
)
from sentry.models.dashboard_permissions import DashboardPermissions
from sentry.models.dashboard_widget import (
DashboardFieldLink,
DashboardWidget,
DashboardWidgetQuery,
DashboardWidgetQueryOnDemand,
Expand Down Expand Up @@ -596,6 +597,11 @@ def create_exhaustive_organization(
extraction_state=DashboardWidgetQueryOnDemand.OnDemandExtractionState.DISABLED_NOT_APPLICABLE,
spec_hashes=[],
)
DashboardFieldLink.objects.create(
dashboard_widget_query=widget_query,
field="count()",
dashboard=dashboard,
)
DashboardTombstone.objects.create(organization=org, slug=f"test-tombstone-in-{slug}")

# *Search
Expand Down
Loading