Skip to content

chore(alerts): Remove metric alert columns on NotificationMessage#115578

Merged
ceorourke merged 9 commits into
masterfrom
ceorourke/rm-metric-alert-columns-notificationmessag
May 19, 2026
Merged

chore(alerts): Remove metric alert columns on NotificationMessage#115578
ceorourke merged 9 commits into
masterfrom
ceorourke/rm-metric-alert-columns-notificationmessag

Conversation

@ceorourke
Copy link
Copy Markdown
Member

@ceorourke ceorourke commented May 14, 2026

Follow up to #115529 to start removing the incident and trigger_action column on NotifcationMessage. Since only action and group will be used now, I'm trying to make those not nullable.

Not to be merged until #115726 has been applied

@ceorourke ceorourke requested review from a team as code owners May 14, 2026 17:52
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 14, 2026
Comment thread src/sentry/notifications/models/notificationmessage.py Outdated
Copy link
Copy Markdown
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

If these columns already have values, you can do the same thing that I did here:
https://github.com/getsentry/sentry/pull/115524/changes

However, it looks like there are many rows with null values: https://redash.de.getsentry.net/queries/367/source

So you either need to provide a default, or clean up these rows

@github-actions
Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/notifications/migrations/0009_remove_metric_alert_columns_notificationmessage.py

for 0009_remove_metric_alert_columns_notificationmessage in notifications

--
-- Alter field action on notificationmessage
--
SET CONSTRAINTS "sentry_notificationm_action_id_e224a327_fk_workflow_" IMMEDIATE; ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationm_action_id_e224a327_fk_workflow_";
ALTER TABLE "sentry_notificationmessage" ALTER COLUMN "action_id" SET DEFAULT 0;
UPDATE "sentry_notificationmessage" SET "action_id" = 0 WHERE "action_id" IS NULL; SET CONSTRAINTS ALL IMMEDIATE;
ALTER TABLE "sentry_notificationmessage" ADD CONSTRAINT "sentry_notificationm_action_id_e224a327_fk_workflow_" FOREIGN KEY ("action_id") REFERENCES "workflow_engine_action" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_notificationmessage" VALIDATE CONSTRAINT "sentry_notificationm_action_id_e224a327_fk_workflow_";
--
-- Alter field group on notificationmessage
--
SET CONSTRAINTS "sentry_notificationm_group_id_6e588d2d_fk_sentry_gr" IMMEDIATE; ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationm_group_id_6e588d2d_fk_sentry_gr";
ALTER TABLE "sentry_notificationmessage" ALTER COLUMN "group_id" SET DEFAULT 0;
UPDATE "sentry_notificationmessage" SET "group_id" = 0 WHERE "group_id" IS NULL; SET CONSTRAINTS ALL IMMEDIATE;
ALTER TABLE "sentry_notificationmessage" ADD CONSTRAINT "sentry_notificationm_group_id_6e588d2d_fk_sentry_gr" FOREIGN KEY ("group_id") REFERENCES "sentry_groupedmessage" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_notificationmessage" VALIDATE CONSTRAINT "sentry_notificationm_group_id_6e588d2d_fk_sentry_gr";
--
-- Alter field incident on notificationmessage
--
SET CONSTRAINTS "sentry_notificationm_incident_id_536f94b5_fk_sentry_in" IMMEDIATE; ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationm_incident_id_536f94b5_fk_sentry_in";
--
-- Alter field trigger_action on notificationmessage
--
SET CONSTRAINTS "sentry_notificationm_trigger_action_id_2f8dabba_fk_sentry_al" IMMEDIATE; ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationm_trigger_action_id_2f8dabba_fk_sentry_al";
ALTER TABLE "sentry_notificationmessage" ADD CONSTRAINT "sentry_notificationmessage_action_id_e224a327_notnull" CHECK ("action_id" IS NOT NULL) NOT VALID;
ALTER TABLE "sentry_notificationmessage" VALIDATE CONSTRAINT "sentry_notificationmessage_action_id_e224a327_notnull";
ALTER TABLE "sentry_notificationmessage" ALTER COLUMN "action_id" SET NOT NULL;
ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationmessage_action_id_e224a327_notnull";
ALTER TABLE "sentry_notificationmessage" ADD CONSTRAINT "sentry_notificationmessage_group_id_6e588d2d_notnull" CHECK ("group_id" IS NOT NULL) NOT VALID;
ALTER TABLE "sentry_notificationmessage" VALIDATE CONSTRAINT "sentry_notificationmessage_group_id_6e588d2d_notnull";
ALTER TABLE "sentry_notificationmessage" ALTER COLUMN "group_id" SET NOT NULL;
ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationmessage_group_id_6e588d2d_notnull";

@ceorourke ceorourke force-pushed the ceorourke/rm-metric-alert-columns-notificationmessag branch from eea68d7 to 814a8ef Compare May 15, 2026 20:24
@ceorourke ceorourke requested a review from a team as a code owner May 15, 2026 20:24
@ceorourke ceorourke requested a review from a team as a code owner May 15, 2026 20:35
Comment thread src/sentry/integrations/repository/notification_action.py
@github-actions
Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/notifications/migrations/0010_remove_metric_alert_columns_notificationmessage.py

for 0010_remove_metric_alert_columns_notificationmessage in notifications

--
-- Alter field action on notificationmessage
--
SET CONSTRAINTS "sentry_notificationm_action_id_e224a327_fk_workflow_" IMMEDIATE; ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationm_action_id_e224a327_fk_workflow_";
ALTER TABLE "sentry_notificationmessage" ADD CONSTRAINT "sentry_notificationm_action_id_e224a327_fk_workflow_" FOREIGN KEY ("action_id") REFERENCES "workflow_engine_action" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_notificationmessage" VALIDATE CONSTRAINT "sentry_notificationm_action_id_e224a327_fk_workflow_";
--
-- Alter field group on notificationmessage
--
SET CONSTRAINTS "sentry_notificationm_group_id_6e588d2d_fk_sentry_gr" IMMEDIATE; ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationm_group_id_6e588d2d_fk_sentry_gr";
ALTER TABLE "sentry_notificationmessage" ADD CONSTRAINT "sentry_notificationm_group_id_6e588d2d_fk_sentry_gr" FOREIGN KEY ("group_id") REFERENCES "sentry_groupedmessage" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_notificationmessage" VALIDATE CONSTRAINT "sentry_notificationm_group_id_6e588d2d_fk_sentry_gr";
--
-- Alter field incident on notificationmessage
--
SET CONSTRAINTS "sentry_notificationm_incident_id_536f94b5_fk_sentry_in" IMMEDIATE; ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationm_incident_id_536f94b5_fk_sentry_in";
--
-- Alter field trigger_action on notificationmessage
--
SET CONSTRAINTS "sentry_notificationm_trigger_action_id_2f8dabba_fk_sentry_al" IMMEDIATE; ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationm_trigger_action_id_2f8dabba_fk_sentry_al";
ALTER TABLE "sentry_notificationmessage" ADD CONSTRAINT "sentry_notificationmessage_action_id_e224a327_notnull" CHECK ("action_id" IS NOT NULL) NOT VALID;
ALTER TABLE "sentry_notificationmessage" VALIDATE CONSTRAINT "sentry_notificationmessage_action_id_e224a327_notnull";
ALTER TABLE "sentry_notificationmessage" ALTER COLUMN "action_id" SET NOT NULL;
ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationmessage_action_id_e224a327_notnull";
ALTER TABLE "sentry_notificationmessage" ADD CONSTRAINT "sentry_notificationmessage_group_id_6e588d2d_notnull" CHECK ("group_id" IS NOT NULL) NOT VALID;
ALTER TABLE "sentry_notificationmessage" VALIDATE CONSTRAINT "sentry_notificationmessage_group_id_6e588d2d_notnull";
ALTER TABLE "sentry_notificationmessage" ALTER COLUMN "group_id" SET NOT NULL;
ALTER TABLE "sentry_notificationmessage" DROP CONSTRAINT "sentry_notificationmessage_group_id_6e588d2d_notnull";

@ceorourke ceorourke requested a review from a team as a code owner May 15, 2026 21:36
@ceorourke ceorourke requested review from wedamija and removed request for a team May 15, 2026 21:38
Copy link
Copy Markdown
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

I think that since this table is pretty huge we might need to set this as a post deploy migration. It doesn't add/remove any columns, just constraints so it should be fine.

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 50ab3d0. Configure here.

Comment thread src/sentry/integrations/repository/notification_action.py
@ceorourke ceorourke merged commit b592bde into master May 19, 2026
116 of 118 checks passed
@ceorourke ceorourke deleted the ceorourke/rm-metric-alert-columns-notificationmessag branch May 19, 2026 17:04
ceorourke added a commit that referenced this pull request May 20, 2026
#115823)

Follow up to #115578 to start
removal of the metric alert columns and add an index on `date_added` to
prep for adding a cleanup job on the table for rows over 90 days old.
JonasBa pushed a commit that referenced this pull request May 21, 2026
#115823)

Follow up to #115578 to start
removal of the metric alert columns and add an index on `date_added` to
prep for adding a cleanup job on the table for rows over 90 days old.
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