sentry icon indicating copy to clipboard operation
sentry copied to clipboard

fix(dashboards): Add unique constraint for user and dashboard pair

Open narsaynorath opened this issue 6 months ago • 2 comments

In an attempt to change the syntax for defining the uniqueness constraint, the original constraint was dropped and only updated the Django state.

This reintroduces the constraint so we actually enforce it in the DB on inserts.

narsaynorath avatar Jun 13 '25 18:06 narsaynorath

This PR has a migration; here is the generated SQL for src/sentry/migrations/0927_dashboard_add_unique_constraint_user_dashboard.py

for 0927_dashboard_add_unique_constraint_user_dashboard in sentry

--
-- Custom state/database change combination
--
CREATE UNIQUE INDEX CONCURRENTLY "sentry_dashboardfavoriteuser_user_id_dashboard_id_2c7267a5_uniq" ON "sentry_dashboardfavoriteuser" ("user_id", "dashboard_id");
ALTER TABLE "sentry_dashboardfavoriteuser" ADD CONSTRAINT "sentry_dashboardfavoriteuser_user_id_dashboard_id_2c7267a5_uniq" UNIQUE USING INDEX "sentry_dashboardfavoriteuser_user_id_dashboard_id_2c7267a5_uniq";

github-actions[bot] avatar Jun 13 '25 18:06 github-actions[bot]

@wedamija Following up on our conversation in https://github.com/getsentry/sentry/pull/92272#issuecomment-2971008983

I ran a query to count how many instances could violate the uniqueness constraint in this redash query and it hasn't been violated (i.e. all the counts are 1). This is my PR to update the DB to contain the constraint, since the state is pointing to sentry_dashboardfavoriteuser_user_id_dashboard_id_2c7267a5_uniq as the name, I also made the DB change use the same name

narsaynorath avatar Jun 13 '25 19:06 narsaynorath