From a576170ad4f912da33b9bcc6646641b1a0e087ea Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Mon, 27 Feb 2023 18:00:37 -0800 Subject: [PATCH 1/2] feat(crons): Migrate guid to slug --- migrations_lockfile.txt | 2 +- .../0367_migrate_monitor_guid_to_slug.py | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/sentry/migrations/0367_migrate_monitor_guid_to_slug.py diff --git a/migrations_lockfile.txt b/migrations_lockfile.txt index 4b69a76ad70f09..47f37999fbb239 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: 0366_add_slug_to_monitors +sentry: 0367_migrate_monitor_guid_to_slug social_auth: 0001_initial diff --git a/src/sentry/migrations/0367_migrate_monitor_guid_to_slug.py b/src/sentry/migrations/0367_migrate_monitor_guid_to_slug.py new file mode 100644 index 00000000000000..c894b1a5a8c11f --- /dev/null +++ b/src/sentry/migrations/0367_migrate_monitor_guid_to_slug.py @@ -0,0 +1,44 @@ +# Generated by Django 2.2.28 on 2023-02-28 01:51 + +from django.db import migrations + +from sentry.utils.query import RangeQuerySetWrapperWithProgressBar +from sentry.new_migrations.migrations import CheckedMigration + + +def migrate_monitor_slugs(apps, schema_editor): + Monitor = apps.get_model("sentry", "Monitor") + + for monitor in RangeQuerySetWrapperWithProgressBar(Monitor.objects.filter()): + # Nothing to migrate if the monitor already has a slug + if monitor.slug is not None: + continue + + monitor.slug = str(monitor.guid) + monitor.save() + + +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 = False + + dependencies = [ + ("sentry", "0366_add_slug_to_monitors"), + ] + + operations = [ + migrations.RunPython( + migrate_monitor_slugs, + migrations.RunPython.noop, + hints={"tables": ["sentry_monitior"]}, + ), + ] From fa6311c24d9b2356b5f1e3f34a0c5d9948f42bad Mon Sep 17 00:00:00 2001 From: "getsantry[bot]" <66042841+getsantry[bot]@users.noreply.github.com> Date: Wed, 1 Mar 2023 21:35:28 +0000 Subject: [PATCH 2/2] style(lint): Auto commit lint changes --- src/sentry/migrations/0367_migrate_monitor_guid_to_slug.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/migrations/0367_migrate_monitor_guid_to_slug.py b/src/sentry/migrations/0367_migrate_monitor_guid_to_slug.py index c894b1a5a8c11f..a4b37afad2200d 100644 --- a/src/sentry/migrations/0367_migrate_monitor_guid_to_slug.py +++ b/src/sentry/migrations/0367_migrate_monitor_guid_to_slug.py @@ -2,8 +2,8 @@ from django.db import migrations -from sentry.utils.query import RangeQuerySetWrapperWithProgressBar from sentry.new_migrations.migrations import CheckedMigration +from sentry.utils.query import RangeQuerySetWrapperWithProgressBar def migrate_monitor_slugs(apps, schema_editor):