-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
feat(team-workflow): Add team to GroupSubscription #55805
feat(team-workflow): Add team to GroupSubscription #55805
Conversation
This PR has a migration; here is the generated SQL for --
-- Add field team to groupsubscription
--
ALTER TABLE "sentry_groupsubscription" ADD COLUMN "team_id" bigint NULL;
--
-- Alter field user_id on groupsubscription
--
ALTER TABLE "sentry_groupsubscription" ALTER COLUMN "user_id" DROP NOT NULL;
--
-- Alter unique_together for groupsubscription (2 constraint(s))
--
CREATE UNIQUE INDEX CONCURRENTLY "sentry_groupsubscription_group_id_team_id_ba7c937c_uniq" ON "sentry_groupsubscription" ("group_id", "team_id");
ALTER TABLE "sentry_groupsubscription" ADD CONSTRAINT "sentry_groupsubscription_group_id_team_id_ba7c937c_uniq" UNIQUE USING INDEX "sentry_groupsubscription_group_id_team_id_ba7c937c_uniq";
ALTER TABLE "sentry_groupsubscription" ADD CONSTRAINT "sentry_groupsubscription_team_id_255af5da_fk_sentry_team_id" FOREIGN KEY ("team_id") REFERENCES "sentry_team" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_groupsubscription" VALIDATE CONSTRAINT "sentry_groupsubscription_team_id_255af5da_fk_sentry_team_id";
CREATE INDEX CONCURRENTLY "sentry_groupsubscription_team_id_255af5da" ON "sentry_groupsubscription" ("team_id");
--
-- Create constraint subscription_team_or_user_check on model groupsubscription
--
ALTER TABLE "sentry_groupsubscription" ADD CONSTRAINT "subscription_team_or_user_check" CHECK ((("team_id" IS NOT NULL AND "user_id" IS NULL) OR ("team_id" IS NULL AND "user_id" IS NOT NULL))) NOT VALID;
ALTER TABLE "sentry_groupsubscription" VALIDATE CONSTRAINT "subscription_team_or_user_check"; |
@@ -178,7 +178,8 @@ class GroupSubscription(Model): | |||
|
|||
project = FlexibleForeignKey("sentry.Project", related_name="subscription_set") | |||
group = FlexibleForeignKey("sentry.Group", related_name="subscription_set") | |||
user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, on_delete="CASCADE") | |||
user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete="CASCADE") | |||
team_id = HybridCloudForeignKey("sentry.Team", null=True, db_index=True, on_delete="CASCADE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isabellaenriquez since this is in the region silo, I think we can just use FlexibleForeignKey
instead of HybridCloudForeignKey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Steve is correct, HybridCloudForeignKey
should only be used when a relationship spans regions. You want FlexibleForeignKey
here.
Codecov Report
@@ Coverage Diff @@
## master #55805 +/- ##
=======================================
Coverage 79.96% 79.97%
=======================================
Files 5055 5055
Lines 217220 217222 +2
Branches 36784 36784
=======================================
+ Hits 173705 173714 +9
+ Misses 38186 38180 -6
+ Partials 5329 5328 -1
|
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to | ||
# have ops run this and not block the deploy. Note that while adding an index is a schema | ||
# change, it's completely safe to run the operation after the code has deployed. | ||
is_dangerous = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The groupsubscription table has ~30M rows. You should fit within the deployment timeout, but if you want to be cautious you should make this migration is_dangerous = True
and have SRE run it.
This PR has a migration; here is the generated SQL for --
-- Add field team to groupsubscription
--
ALTER TABLE "sentry_groupsubscription" ADD COLUMN "team_id" bigint NULL;
--
-- Alter field user_id on groupsubscription
--
ALTER TABLE "sentry_groupsubscription" ALTER COLUMN "user_id" DROP NOT NULL;
--
-- Alter unique_together for groupsubscription (2 constraint(s))
--
CREATE UNIQUE INDEX CONCURRENTLY "sentry_groupsubscription_group_id_team_id_ba7c937c_uniq" ON "sentry_groupsubscription" ("group_id", "team_id");
ALTER TABLE "sentry_groupsubscription" ADD CONSTRAINT "sentry_groupsubscription_group_id_team_id_ba7c937c_uniq" UNIQUE USING INDEX "sentry_groupsubscription_group_id_team_id_ba7c937c_uniq";
ALTER TABLE "sentry_groupsubscription" ADD CONSTRAINT "sentry_groupsubscription_team_id_255af5da_fk_sentry_team_id" FOREIGN KEY ("team_id") REFERENCES "sentry_team" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_groupsubscription" VALIDATE CONSTRAINT "sentry_groupsubscription_team_id_255af5da_fk_sentry_team_id";
CREATE INDEX CONCURRENTLY "sentry_groupsubscription_team_id_255af5da" ON "sentry_groupsubscription" ("team_id");
--
-- Create constraint subscription_team_or_user_check on model groupsubscription
--
ALTER TABLE "sentry_groupsubscription" ADD CONSTRAINT "subscription_team_or_user_check" CHECK ((("team_id" IS NOT NULL AND "user_id" IS NULL) OR ("team_id" IS NULL AND "user_id" IS NOT NULL))) NOT VALID;
ALTER TABLE "sentry_groupsubscription" VALIDATE CONSTRAINT "subscription_team_or_user_check"; |
revert failed (conflict? already reverted?) -- check the logs |
Adds
team
to the GroupSubscription table and adds constraint that at least one ofteam_id
oruser_id
is set.Close #55555.