Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

narsaynorath
Copy link
Member

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.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 13, 2025
Copy link
Contributor

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";

@narsaynorath narsaynorath marked this pull request as ready for review June 13, 2025 19:04
@narsaynorath narsaynorath requested a review from a team as a code owner June 13, 2025 19:04
@narsaynorath
Copy link
Member Author

@wedamija Following up on our conversation in #92272 (comment)

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 narsaynorath requested a review from wedamija June 13, 2025 19:07
@narsaynorath narsaynorath merged commit a2f8e09 into master Jun 16, 2025
65 checks passed
@narsaynorath narsaynorath deleted the nar/fix/dashboards-add-unique-constraint-for-user-dashboard branch June 16, 2025 12:15
billyvg pushed a commit that referenced this pull request Jun 18, 2025
…93536)

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.
andrewshie-sentry pushed a commit that referenced this pull request Jun 19, 2025
…93536)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants