-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore(group_history): Safe removal of prev_history #102663
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Generated by Django 5.2.1 on 2025-11-04 13:30 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations | ||
|
|
||
| from sentry.db.models.fields.foreignkey import FlexibleForeignKey | ||
| from sentry.new_migrations.migrations import CheckedMigration | ||
| from sentry.new_migrations.monkey.fields import SafeRemoveField | ||
| from sentry.new_migrations.monkey.state import DeletionAction | ||
|
|
||
|
|
||
| class Migration(CheckedMigration): | ||
| # This flag is used to mark that a migration shouldn't be automatically run in production. | ||
| # This should only be used for operations where it's safe to run the migration after your | ||
| # code has deployed. So this should not be used for most operations that alter the schema | ||
| # of a table. | ||
| # Here are some things that make sense to mark as post deployment: | ||
| # - Large data migrations. Typically we want these to be run manually so that they can be | ||
| # monitored and not block the deploy for a long period of time while they run. | ||
| # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to | ||
| # run this outside deployments so that we don't block them. Note that while adding an index | ||
| # 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 | ||
|
|
||
| dependencies = [ | ||
| ("sentry", "1001_prevent_grouphistory_infinte_recursion"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name="grouphistory", | ||
| name="prev_history", | ||
| field=FlexibleForeignKey( | ||
| # We want to remove the database-level foreign key constraint | ||
| db_constraint=False, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| to="sentry.grouphistory", | ||
| ), | ||
| ), | ||
| # This marks the field as pending deletion | ||
| SafeRemoveField( | ||
| model_name="grouphistory", | ||
| name="prev_history", | ||
| deletion_action=DeletionAction.MOVE_TO_PENDING, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This simply marks the column as not useable. |
||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,8 +213,18 @@ class GroupHistory(Model): | |
| ), | ||
| ) | ||
| prev_history = FlexibleForeignKey( | ||
| "sentry.GroupHistory", null=True, on_delete=models.SET_NULL | ||
| ) # This field has no immediate use, but might be useful. | ||
| "sentry.GroupHistory", | ||
| null=True, | ||
| on_delete=models.SET_NULL, | ||
| # By default, Django creates a database-level foreign key constraint when you define a ForeignKey field. | ||
| # This constraint enforces referential integrity at the database level, preventing you from: | ||
| # * Deleting a referenced record without handling the reference | ||
| # * Creating a reference to a non-existent record | ||
| # When you set db_constraint=False, Django skips creating this database constraint. | ||
| # The field still works as a ForeignKey in Python/Django (you can traverse relationships, | ||
| # use .select_related(), etc.), but the database won't enforce the relationship. | ||
| db_constraint=False, | ||
| ) | ||
| prev_history_date = models.DateTimeField( | ||
| null=True | ||
| ) # This field is used to simplify query calculations. | ||
|
Comment on lines
228
to
230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Removing 🔍 Detailed AnalysisThe 💡 Suggested FixRetain the 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
This causes integrity errors like this: https://sentry.sentry.io/issues/6994851757/