feat(cells): add unique constraint to projectkeymapping table#110235
feat(cells): add unique constraint to projectkeymapping table#110235
Conversation
(project_key_id, cell_name) must be unique, we should enforce it at the db level
|
This PR has a migration; here is the generated SQL for for --
-- 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"; |
| constraints = [ | ||
| models.UniqueConstraint( | ||
| fields=["project_key_id", "cell_name"], | ||
| name="sentry_projectkeymapping_project_key_id_cell_name_uniq", | ||
| ), | ||
| ] |
There was a problem hiding this comment.
If we have this unique constraint, is sentry_projkeymapping_cell_name_date_updated_id_idx useful anymore?
There was a problem hiding this comment.
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.
markstory
left a comment
There was a problem hiding this comment.
Unique constraint looks good to me.
| constraints = [ | ||
| models.UniqueConstraint( | ||
| fields=["project_key_id", "cell_name"], | ||
| name="sentry_projectkeymapping_project_key_id_cell_name_uniq", | ||
| ), | ||
| ] |
There was a problem hiding this comment.
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.
(project_key_id, cell_name) must be unique, we should enforce it at the db level