Skip to content
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
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ replays: 0007_organizationmember_replay_access

seer: 0006_add_night_shift_models

sentry: 1066_add_export_format_in_data_export_obj
sentry: 1067_add_dashboard_revision_model

social_auth: 0003_social_auth_json_field

Expand Down
3 changes: 3 additions & 0 deletions src/sentry/backup/comparators.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,9 @@ def get_default_comparators() -> dict[str, list[JSONScrubbingComparator]]:
"sentry.dashboardlastvisited": [
DateUpdatedComparator("last_visited", "date_added", "date_updated"),
],
"sentry.dashboardrevision": [
DateUpdatedComparator("date_added", "date_updated"),
],
"sentry.dataforwarder": [DateUpdatedComparator("date_updated", "date_added")],
"sentry.dataforwarderproject": [DateUpdatedComparator("date_updated", "date_added")],
"sentry.groupsearchview": [DateUpdatedComparator("date_updated")],
Expand Down
70 changes: 70 additions & 0 deletions src/sentry/migrations/1067_add_dashboard_revision_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Generated by Django 5.2.12 on 2026-04-14 15:38

import django.db.models.deletion
import sentry.db.models.fields.bounded
import sentry.db.models.fields.foreignkey
import sentry.db.models.fields.hybrid_cloud_foreign_key
import sentry.db.models.fields.jsonfield
from django.db import migrations, models

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", "1066_add_export_format_in_data_export_obj"),
]

operations = [
migrations.CreateModel(
name="DashboardRevision",
fields=[
(
"id",
sentry.db.models.fields.bounded.BoundedBigAutoField(
primary_key=True, serialize=False
),
),
(
"created_by_id",
sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey(
"sentry.User", db_index=True, null=True, on_delete="SET_NULL"
),
),
("date_updated", models.DateTimeField(auto_now=True)),
("date_added", models.DateTimeField(auto_now_add=True)),
("title", models.CharField(max_length=255)),
("source", models.CharField(default="edit", max_length=32)),
("snapshot", sentry.db.models.fields.jsonfield.JSONField(default=dict)),
("snapshot_schema_version", models.IntegerField()),
(
"dashboard",
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="sentry.dashboard"
),
),
],
options={
"db_table": "sentry_dashboardrevision",
"indexes": [
models.Index(
fields=["dashboard", "-date_added"], name="sentry_dashrev_dash_date_idx"
)
],
},
),
]
24 changes: 24 additions & 0 deletions src/sentry/models/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,30 @@ class Meta:
__repr__ = sane_repr("organization", "slug")


@cell_silo_model
class DashboardRevision(DefaultFieldsModel):
__relocation_scope__ = RelocationScope.Organization

created_by_id = HybridCloudForeignKey(
"sentry.User", db_index=True, null=True, on_delete="SET_NULL"
Comment on lines +434 to +435
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm assuming this is how we know who made the revision, will we just assume null created_by_id is ai? or will created_by_id just be the id of the user who prompted the ai?

If it's the later, it might be useful to know wether the revision is ai created or user created.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It will be the user that initiated/confirmed the changes made by the agent (since it doesn't save without confirming).

)
title = models.CharField(max_length=255)
source = models.CharField(max_length=32, default="edit")
snapshot: models.Field[dict[str, Any], dict[str, Any]] = JSONField(default=dict)
snapshot_schema_version = models.IntegerField()
dashboard = FlexibleForeignKey("sentry.Dashboard", on_delete=models.CASCADE)

class Meta:
app_label = "sentry"
db_table = "sentry_dashboardrevision"
indexes = [
models.Index(
fields=["dashboard", "-date_added"],
name="sentry_dashrev_dash_date_idx",
)
]


@cell_silo_model
class DashboardLastVisited(DefaultFieldsModel):
__relocation_scope__ = RelocationScope.Organization
Expand Down
3 changes: 2 additions & 1 deletion src/sentry/organizations/services/organization/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from sentry.incidents.models.alert_rule import AlertRule, AlertRuleActivity
from sentry.incidents.models.incident import IncidentActivity
from sentry.models.activity import Activity
from sentry.models.dashboard import Dashboard, DashboardFavoriteUser
from sentry.models.dashboard import Dashboard, DashboardFavoriteUser, DashboardRevision
from sentry.models.groupassignee import GroupAssignee
from sentry.models.groupbookmark import GroupBookmark
from sentry.models.groupsearchview import GroupSearchView
Expand Down Expand Up @@ -582,6 +582,7 @@ def merge_users(self, *, organization_id: int, from_user_id: int, to_user_id: in
AlertRuleActivity,
Dashboard,
DashboardFavoriteUser,
DashboardRevision,
GroupAssignee,
GroupBookmark,
GroupSeen,
Expand Down
7 changes: 7 additions & 0 deletions src/sentry/testutils/helpers/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
Dashboard,
DashboardFavoriteUser,
DashboardLastVisited,
DashboardRevision,
DashboardTombstone,
)
from sentry.models.dashboard_permissions import DashboardPermissions
Expand Down Expand Up @@ -600,6 +601,12 @@ def create_exhaustive_organization(
field="count()",
dashboard=linked_dashboard,
)
DashboardRevision.objects.create(
dashboard=dashboard,
created_by_id=owner_id,
title=dashboard.title,
snapshot_schema_version=1,
)
DashboardTombstone.objects.create(organization=org, slug=f"test-tombstone-in-{slug}")

# *Search
Expand Down
4 changes: 3 additions & 1 deletion tests/sentry/users/models/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sentry.incidents.models.incident import IncidentActivity
from sentry.models.activity import Activity
from sentry.models.authidentity import AuthIdentity
from sentry.models.dashboard import Dashboard, DashboardFavoriteUser
from sentry.models.dashboard import Dashboard, DashboardFavoriteUser, DashboardRevision
from sentry.models.groupassignee import GroupAssignee
from sentry.models.groupbookmark import GroupBookmark
from sentry.models.groupsearchview import GroupSearchView
Expand Down Expand Up @@ -498,6 +498,7 @@ def test_duplicate_memberships(self, expected_models: list[type[Model]]) -> None
AlertRuleActivity,
Dashboard,
DashboardFavoriteUser,
DashboardRevision,
GroupAssignee,
GroupBookmark,
GroupSeen,
Expand Down Expand Up @@ -541,6 +542,7 @@ def test_only_source_user_is_member_of_organization(
AlertRuleActivity,
Dashboard,
DashboardFavoriteUser,
DashboardRevision,
GroupAssignee,
GroupBookmark,
GroupSeen,
Expand Down
Loading