Skip to content

feat(cells): add unique constraint to projectkeymapping table#110235

Merged
lynnagara merged 1 commit intomasterfrom
projectkeymapping-constraint
Mar 9, 2026
Merged

feat(cells): add unique constraint to projectkeymapping table#110235
lynnagara merged 1 commit intomasterfrom
projectkeymapping-constraint

Conversation

@lynnagara
Copy link
Copy Markdown
Member

(project_key_id, cell_name) must be unique, we should enforce it at the db level

(project_key_id, cell_name) must be unique, we should enforce it at the db level
@lynnagara lynnagara requested a review from a team as a code owner March 9, 2026 18:59
@lynnagara lynnagara requested a review from a team March 9, 2026 18:59
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

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

for 1050_projectkeymapping_uniq_constraint in sentry

--
-- Alter field project_key_id on projectkeymapping
--
DROP INDEX CONCURRENTLY IF EXISTS "sentry_projectkeymapping_project_key_id_fee1d050";
--
-- Create constraint sentry_projectkeymapping_project_key_id_cell_name_uniq on model projectkeymapping
--
CREATE UNIQUE INDEX CONCURRENTLY "sentry_projectkeymapping_project_key_id_cell_name_uniq" ON "sentry_projectkeymapping" ("project_key_id", "cell_name");
ALTER TABLE "sentry_projectkeymapping" ADD CONSTRAINT "sentry_projectkeymapping_project_key_id_cell_name_uniq" UNIQUE USING INDEX "sentry_projectkeymapping_project_key_id_cell_name_uniq";

Comment on lines +33 to +38
constraints = [
models.UniqueConstraint(
fields=["project_key_id", "cell_name"],
name="sentry_projectkeymapping_project_key_id_cell_name_uniq",
),
]
Copy link
Copy Markdown
Member

@wedamija wedamija Mar 9, 2026

Choose a reason for hiding this comment

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

If we have this unique constraint, is sentry_projkeymapping_cell_name_date_updated_id_idx useful anymore?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is, as that index includes the truncated timestamp that we'll be using to paginate through records with. Without that index, filtering on date_trunc(date_updated) will do a table scan.

Copy link
Copy Markdown
Member

@markstory markstory left a comment

Choose a reason for hiding this comment

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

Unique constraint looks good to me.

Comment on lines +33 to +38
constraints = [
models.UniqueConstraint(
fields=["project_key_id", "cell_name"],
name="sentry_projectkeymapping_project_key_id_cell_name_uniq",
),
]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is, as that index includes the truncated timestamp that we'll be using to paginate through records with. Without that index, filtering on date_trunc(date_updated) will do a table scan.

@lynnagara lynnagara merged commit d7a08dd into master Mar 9, 2026
78 checks passed
@lynnagara lynnagara deleted the projectkeymapping-constraint branch March 9, 2026 20:43
@github-actions github-actions bot locked and limited conversation to collaborators Mar 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants