Repository navigation
feat(explore): Track service account and org token creators on saved queries - #129549
Merged
Merged
Conversation
…queries Add created_by_service_account_id and created_by_org_auth_token_id to DiscoverSavedQuery, ExploreSavedQuery and ExploreSavedFormula, with an at-most-one-creator check constraint, and record the creator via get_creator_reference() on create. Fixes ENG-8935
Contributor
|
This PR has a migration; here is the generated SQL for for --
-- Add field created_by_org_auth_token_id to discoversavedquery
--
ALTER TABLE "sentry_discoversavedquery" ADD COLUMN "created_by_org_auth_token_id" bigint NULL;
--
-- Add field created_by_service_account_id to discoversavedquery
--
ALTER TABLE "sentry_discoversavedquery" ADD COLUMN "created_by_service_account_id" bigint NULL;
--
-- Create constraint sentry_discoversavedquery_single_creator on model discoversavedquery
--
ALTER TABLE "sentry_discoversavedquery" ADD CONSTRAINT "sentry_discoversavedquery_single_creator" CHECK ((("created_by_service_account_id" IS NULL AND "created_by_org_auth_token_id" IS NULL) OR ("created_by_id" IS NULL AND "created_by_org_auth_token_id" IS NULL) OR ("created_by_id" IS NULL AND "created_by_service_account_id" IS NULL))) NOT VALID;
ALTER TABLE "sentry_discoversavedquery" VALIDATE CONSTRAINT "sentry_discoversavedquery_single_creator";
CREATE INDEX CONCURRENTLY "sentry_discoversavedquery_created_by_org_auth_token_id_0ef25d16" ON "sentry_discoversavedquery" ("created_by_org_auth_token_id");
CREATE INDEX CONCURRENTLY "sentry_discoversavedquery_created_by_service_account_c8f8bc44" ON "sentry_discoversavedquery" ("created_by_service_account_id");for --
-- Add field created_by_org_auth_token_id to exploresavedformula
--
ALTER TABLE "explore_exploresavedformula" ADD COLUMN "created_by_org_auth_token_id" bigint NULL;
--
-- Add field created_by_service_account_id to exploresavedformula
--
ALTER TABLE "explore_exploresavedformula" ADD COLUMN "created_by_service_account_id" bigint NULL;
--
-- Add field created_by_org_auth_token_id to exploresavedquery
--
ALTER TABLE "explore_exploresavedquery" ADD COLUMN "created_by_org_auth_token_id" bigint NULL;
--
-- Add field created_by_service_account_id to exploresavedquery
--
ALTER TABLE "explore_exploresavedquery" ADD COLUMN "created_by_service_account_id" bigint NULL;
--
-- Create constraint explore_exploresavedformula_single_creator on model exploresavedformula
--
ALTER TABLE "explore_exploresavedformula" ADD CONSTRAINT "explore_exploresavedformula_single_creator" CHECK ((("created_by_service_account_id" IS NULL AND "created_by_org_auth_token_id" IS NULL) OR ("created_by_id" IS NULL AND "created_by_org_auth_token_id" IS NULL) OR ("created_by_id" IS NULL AND "created_by_service_account_id" IS NULL))) NOT VALID;
ALTER TABLE "explore_exploresavedformula" VALIDATE CONSTRAINT "explore_exploresavedformula_single_creator";
--
-- Create constraint explore_exploresavedquery_single_creator on model exploresavedquery
--
ALTER TABLE "explore_exploresavedquery" ADD CONSTRAINT "explore_exploresavedquery_single_creator" CHECK ((("created_by_service_account_id" IS NULL AND "created_by_org_auth_token_id" IS NULL) OR ("created_by_id" IS NULL AND "created_by_org_auth_token_id" IS NULL) OR ("created_by_id" IS NULL AND "created_by_service_account_id" IS NULL))) NOT VALID;
ALTER TABLE "explore_exploresavedquery" VALIDATE CONSTRAINT "explore_exploresavedquery_single_creator";
CREATE INDEX CONCURRENTLY "explore_exploresavedformul_created_by_org_auth_token__bc7a4fa8" ON "explore_exploresavedformula" ("created_by_org_auth_token_id");
CREATE INDEX CONCURRENTLY "explore_exploresavedformul_created_by_service_account_b4cd99a6" ON "explore_exploresavedformula" ("created_by_service_account_id");
CREATE INDEX CONCURRENTLY "explore_exploresavedquery_created_by_org_auth_token_id_6ebbce7d" ON "explore_exploresavedquery" ("created_by_org_auth_token_id");
CREATE INDEX CONCURRENTLY "explore_exploresavedquery_created_by_service_account_c069a8a1" ON "explore_exploresavedquery" ("created_by_service_account_id"); |
DominikB2014
marked this pull request as ready for review
November 2, 2026 21:12
…n-user-creator # Conflicts: # src/sentry/explore/models.py
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Saved queries created by service accounts or org auth tokens currently get no author. Same approach as #129219 for dashboards.
created_by_service_account_id/created_by_org_auth_token_idplus a single-creator check constraint toDiscoverSavedQuery,ExploreSavedQueryandExploreSavedFormulaget_creator_reference(request); existingcreated_by_idis alreadySET_NULLon all threeFixes ENG-8935