Skip to content
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(ACI): Break lookup table foreign keys #88407

Merged
merged 11 commits into from
Apr 2, 2025
Merged

Conversation

ceorourke
Copy link
Member

@ceorourke ceorourke commented Apr 1, 2025

Change the lookup tables' foreign keys to store IDs and rename so it reflects what it holds now.

See https://www.notion.so/sentry/Old-Endpoints-New-Models-1bd8b10e4b5d803d80a9d9d05b6b88b4?pvs=4#1c28b10e4b5d80c5a254dbb442f6859d for a lot more context on this change, but the tl;dr is we don't want to have to rely on old models that we will be deleting for IDs we only need for a short period of time.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 1, 2025
Copy link
Contributor

github-actions bot commented Apr 1, 2025

This PR has a migration; here is the generated SQL for src/sentry/workflow_engine/migrations/0039_break_lookup_fks.py ()

--
-- Custom state/database change combination
--
SET CONSTRAINTS "workflow_engine_acti_alert_rule_trigger_a_a7580a99_fk_sentry_al" IMMEDIATE; ALTER TABLE "workflow_engine_actionalertruletriggeraction" DROP CONSTRAINT "workflow_engine_acti_alert_rule_trigger_a_a7580a99_fk_sentry_al";
SET CONSTRAINTS "workflow_engine_aler_alert_rule_id_c81b0f4b_fk_sentry_al" IMMEDIATE; ALTER TABLE "workflow_engine_alertruledetector" DROP CONSTRAINT "workflow_engine_aler_alert_rule_id_c81b0f4b_fk_sentry_al";
SET CONSTRAINTS "workflow_engine_aler_rule_id_26bc9c69_fk_sentry_ru" IMMEDIATE; ALTER TABLE "workflow_engine_alertruledetector" DROP CONSTRAINT "workflow_engine_aler_rule_id_26bc9c69_fk_sentry_ru";
SET CONSTRAINTS "workflow_engine_aler_alert_rule_id_952ceb2c_fk_sentry_al" IMMEDIATE; ALTER TABLE "workflow_engine_alertruleworkflow" DROP CONSTRAINT "workflow_engine_aler_alert_rule_id_952ceb2c_fk_sentry_al";
SET CONSTRAINTS "workflow_engine_aler_rule_id_c93d1444_fk_sentry_ru" IMMEDIATE; ALTER TABLE "workflow_engine_alertruleworkflow" DROP CONSTRAINT "workflow_engine_aler_rule_id_c93d1444_fk_sentry_ru";

Copy link

codecov bot commented Apr 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #88407    +/-   ##
========================================
  Coverage   87.75%   87.75%            
========================================
  Files       10021    10028     +7     
  Lines      567728   567933   +205     
  Branches    22296    22296            
========================================
+ Hits       498183   498378   +195     
- Misses      69125    69135    +10     
  Partials      420      420            

@ceorourke
Copy link
Member Author

Need to rebase after #88407 is merged

@ceorourke ceorourke force-pushed the ceorourke/ACI-223 branch from d76157a to b996030 Compare April 1, 2025 22:17
@ceorourke ceorourke marked this pull request as ready for review April 1, 2025 22:35
@ceorourke ceorourke requested review from a team as code owners April 1, 2025 22:35
Copy link
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.

Mostly lgtm. One other thing to think about is that now that we've broken these fks, then if we deleted the rows on the other side of the key we won't automatically delete these rows, and so they'll be orphaned.

You probably need to add things to deletions so that these models know how to delete these dangling rows. Here's an example:

relations.append(ModelRelation(Monitor, {"project_id": instance.id}))

@markstory
Copy link
Member

You probably need to add things to deletions so that these models know how to delete these dangling rows. Here's an example:

Yes, you'll need to update deletions and add the relations explicitly as django won't handle the deletion cascade anymore.

@wedamija
Copy link
Member

wedamija commented Apr 2, 2025

Looks good, but you'll need to go through uses in getsentry and also fix the queries to use the id directly. You can do this without merging the changes, since the *_id fields always exist

@ceorourke
Copy link
Member Author

Looks good, but you'll need to go through uses in getsentry and also fix the queries to use the id directly. You can do this without merging the changes, since the *_id fields always exist

Oh yeah I have updated all those, just need to do one more rebase.

@ceorourke ceorourke force-pushed the ceorourke/ACI-223 branch from c28f4f9 to fb557f6 Compare April 2, 2025 19:12
Copy link
Contributor

github-actions bot commented Apr 2, 2025

This PR has a migration; here is the generated SQL for src/sentry/workflow_engine/migrations/0040_break_lookup_fks.py ()

--
-- Custom state/database change combination
--
SET CONSTRAINTS "workflow_engine_acti_alert_rule_trigger_a_a7580a99_fk_sentry_al" IMMEDIATE; ALTER TABLE "workflow_engine_actionalertruletriggeraction" DROP CONSTRAINT "workflow_engine_acti_alert_rule_trigger_a_a7580a99_fk_sentry_al";
SET CONSTRAINTS "workflow_engine_aler_alert_rule_id_c81b0f4b_fk_sentry_al" IMMEDIATE; ALTER TABLE "workflow_engine_alertruledetector" DROP CONSTRAINT "workflow_engine_aler_alert_rule_id_c81b0f4b_fk_sentry_al";
SET CONSTRAINTS "workflow_engine_aler_rule_id_26bc9c69_fk_sentry_ru" IMMEDIATE; ALTER TABLE "workflow_engine_alertruledetector" DROP CONSTRAINT "workflow_engine_aler_rule_id_26bc9c69_fk_sentry_ru";
SET CONSTRAINTS "workflow_engine_aler_alert_rule_id_952ceb2c_fk_sentry_al" IMMEDIATE; ALTER TABLE "workflow_engine_alertruleworkflow" DROP CONSTRAINT "workflow_engine_aler_alert_rule_id_952ceb2c_fk_sentry_al";
SET CONSTRAINTS "workflow_engine_aler_rule_id_c93d1444_fk_sentry_ru" IMMEDIATE; ALTER TABLE "workflow_engine_alertruleworkflow" DROP CONSTRAINT "workflow_engine_aler_rule_id_c93d1444_fk_sentry_ru";

@ceorourke
Copy link
Member Author

@wedamija ok all up to date now

@ceorourke ceorourke merged commit aced603 into master Apr 2, 2025
48 checks passed
@ceorourke ceorourke deleted the ceorourke/ACI-223 branch April 2, 2025 20:29
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
Change the lookup tables' foreign keys to store IDs and rename so it
reflects what it holds now.

See
https://www.notion.so/sentry/Old-Endpoints-New-Models-1bd8b10e4b5d803d80a9d9d05b6b88b4?pvs=4#1c28b10e4b5d80c5a254dbb442f6859d
for a lot more context on this change, but the tl;dr is we don't want to
have to rely on old models that we will be deleting for IDs we only need
for a short period of time.
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.

3 participants