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(crons): Remove slug null=True #45276

Merged

Conversation

evanpurkhiser
Copy link
Member

@evanpurkhiser evanpurkhiser commented Mar 1, 2023

After the completion of #45270 all slugs now have values

This is safe as we will be adding the constraint as NOT VALID and running VALIDATE immediately after (which does not lock)

@evanpurkhiser evanpurkhiser requested review from a team as code owners March 1, 2023 22:33
@evanpurkhiser evanpurkhiser requested review from rjo100 and a team and removed request for a team March 1, 2023 22:33
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 1, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

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

--
-- Alter field slug on monitor
--
ALTER TABLE "sentry_monitor" ADD CONSTRAINT "sentry_monitor_slug_ad0f637f_notnull" CHECK ("slug" IS NOT NULL) NOT VALID;
ALTER TABLE "sentry_monitor" VALIDATE CONSTRAINT "sentry_monitor_slug_ad0f637f_notnull";

@codecov
Copy link

codecov bot commented Mar 1, 2023

Codecov Report

Merging #45276 (40265a1) into master (8514418) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #45276      +/-   ##
==========================================
- Coverage   80.23%   80.23%   -0.01%     
==========================================
  Files        4724     4724              
  Lines      198821   198821              
  Branches    12020    12020              
==========================================
- Hits       159525   159520       -5     
- Misses      39034    39039       +5     
  Partials      262      262              
Impacted Files Coverage Δ
src/sentry/models/monitor.py 96.58% <100.00%> (ø)
src/sentry/api/serializers/models/plugin.py 90.76% <0.00%> (-6.16%) ⬇️
src/sentry/api/serializers/models/organization.py 97.92% <0.00%> (-0.42%) ⬇️

Copy link
Member

@JoshFerge JoshFerge left a comment

Choose a reason for hiding this comment

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

how often is this table written / read to? from what i'm understanding, the first statement will still lock, albeit not for long. https://medium.com/doctolib/adding-a-not-null-constraint-on-pg-faster-with-minimal-locking-38b2c00c4d1c

@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/feat-crons-remove-slug-null-true branch from 1cf382e to 40265a1 Compare March 1, 2023 23:12
@JoshFerge
Copy link
Member

reading https://develop.sentry.dev/database-migrations/#adding-not-null-to-columns, seems safe -- LGTM once tests pass

@@ -155,7 +155,7 @@ def save(self, *args, **kwargs):
# NOTE: We ONLY set a slug while saving when creating a new monitor and
# the slug has not been set. Otherwise existing monitors without slugs
# would have their guids changed
if self._state.adding is True and self.slug is None:
if self._state.adding is True and self.slug == "":
Copy link
Contributor

Choose a reason for hiding this comment

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

just say and not self.slug. empty strings eval to False

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 will follow up

@evanpurkhiser evanpurkhiser merged commit 177ad33 into master Mar 2, 2023
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/feat-crons-remove-slug-null-true branch March 2, 2023 00:13
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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