From 4e1e353eb591499736ab865f7da7750539b3a6b6 Mon Sep 17 00:00:00 2001 From: Richard Ortenberg Date: Mon, 10 Jul 2023 12:43:53 -0700 Subject: [PATCH 1/2] migration(crons): Add dangerous migration to add index for monitor environment on check-ins --- migrations_lockfile.txt | 2 +- src/sentry/monitors/models.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/migrations_lockfile.txt b/migrations_lockfile.txt index 9be643315f9c40..decee16bfe409e 100644 --- a/migrations_lockfile.txt +++ b/migrations_lockfile.txt @@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi will then be regenerated, and you should be able to merge without conflicts. nodestore: 0002_nodestore_no_dictfield -sentry: 0507_delete_pending_deletion_rules +sentry: 0508_index_checkin_monitorenvironment social_auth: 0001_initial diff --git a/src/sentry/monitors/models.py b/src/sentry/monitors/models.py index 1561a932370c19..6997e696071be9 100644 --- a/src/sentry/monitors/models.py +++ b/src/sentry/monitors/models.py @@ -400,6 +400,7 @@ class Meta: db_table = "sentry_monitorcheckin" indexes = [ models.Index(fields=["monitor", "date_added", "status"]), + models.Index(fields=["monitor_environment", "date_added", "status"]), models.Index(fields=["timeout_at", "status"]), ] From 7df7df5403aae43b6ea8769e9fd8b55344606d8f Mon Sep 17 00:00:00 2001 From: Richard Ortenberg Date: Mon, 10 Jul 2023 12:46:11 -0700 Subject: [PATCH 2/2] add migration --- .../0508_index_checkin_monitorenvironment.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/sentry/migrations/0508_index_checkin_monitorenvironment.py diff --git a/src/sentry/migrations/0508_index_checkin_monitorenvironment.py b/src/sentry/migrations/0508_index_checkin_monitorenvironment.py new file mode 100644 index 00000000000000..2dd8a32cc9f684 --- /dev/null +++ b/src/sentry/migrations/0508_index_checkin_monitorenvironment.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2.28 on 2023-07-10 19:43 + +from django.db import migrations, models + +from sentry.new_migrations.migrations import CheckedMigration + + +class Migration(CheckedMigration): + # This flag is used to mark that a migration shouldn't be automatically run in production. For + # the most part, 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 dangerous: + # - Large data migrations. Typically we want these to be run manually by ops 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 + # have ops run this and not block the deploy. Note that while adding an index is a schema + # change, it's completely safe to run the operation after the code has deployed. + is_dangerous = True + + dependencies = [ + ("sentry", "0507_delete_pending_deletion_rules"), + ] + + operations = [ + migrations.AddIndex( + model_name="monitorcheckin", + index=models.Index( + fields=["monitor_environment", "date_added", "status"], + name="sentry_moni_monitor_1fb26c_idx", + ), + ), + ]