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

chore(uptime): Modify unique subscription check constraint to allow us to migrate away from it #84875

Merged
merged 5 commits into from
Feb 10, 2025

Conversation

wedamija
Copy link
Member

We want to remove the unique subscription constraint. It's getting increasingly complex to maintain it and it breaks in various ways.

As a first step, we'll add a migrated column. Once a subscription sets this to True then we won't respect the constraint anymore. We'll use this to work on moving subscriptions away from this model.

…s to migrate away from it

We want to remove the unique subscription constraint. It's getting increasingly complex to maintain it and it breaks in various ways.

As a first step, we'll add a migrated column. Once a subscription sets this to `True` then we won't respect the constraint anymore. We'll use this to work on moving subscriptions away from this model.
@wedamija wedamija requested review from a team as code owners February 10, 2025 18:33
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 10, 2025
Copy link

codecov bot commented Feb 10, 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   #84875       +/-   ##
===========================================
+ Coverage   46.38%   87.89%   +41.50%     
===========================================
  Files        9552     9569       +17     
  Lines      541139   541887      +748     
  Branches    20887    20887               
===========================================
+ Hits       250997   476278   +225281     
+ Misses     289802    65269   -224533     
  Partials      340      340               

# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False
Copy link
Member

Choose a reason for hiding this comment

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

Should this be post deployment migration, in US table has 84k rows, not much, but could still cause a timeout since we need to rebuild the index?

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be ok - we have a lock acquisition timeout for adding an index, but not a statement timeout.

Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/uptime/migrations/0025_uptime_migrate_constraint.py ()

--
-- Add field migrated to uptimesubscription
--
ALTER TABLE "uptime_uptimesubscription" ADD COLUMN "migrated" boolean DEFAULT false NOT NULL;
--
-- Create constraint uptime_uptimesubscription_unique_subscription_check_4 on model uptimesubscription
--
CREATE UNIQUE INDEX CONCURRENTLY "uptime_uptimesubscription_unique_subscription_check_4" ON "uptime_uptimesubscription" ("url", "interval_seconds", "timeout_ms", "method", "trace_sampling", (MD5("headers")), (COALESCE(MD5("body"), ''))) WHERE NOT "migrated";
--
-- Remove constraint uptime_uptimesubscription_unique_subscription_check_3 from model uptimesubscription
--
DROP INDEX CONCURRENTLY IF EXISTS "uptime_uptimesubscription_unique_subscription_check_3";

@wedamija wedamija enabled auto-merge (squash) February 10, 2025 19:30
@wedamija wedamija merged commit d94b3bb into master Feb 10, 2025
48 checks passed
@wedamija wedamija deleted the danf/uptime-remove-unique-urls branch February 10, 2025 20:18
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