|
| 1 | +# Generated by Django 5.1.7 on 2025-04-17 21:24 |
| 2 | + |
| 3 | +from django.db import migrations |
| 4 | +from django.db.backends.base.schema import BaseDatabaseSchemaEditor |
| 5 | +from django.db.migrations.state import StateApps |
| 6 | + |
| 7 | +from sentry.new_migrations.migrations import CheckedMigration |
| 8 | +from sentry.utils.query import RangeQuerySetWrapperWithProgressBar |
| 9 | + |
| 10 | + |
| 11 | +def backfill_uptime_status(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None: |
| 12 | + ProjectUptimeSubscription = apps.get_model("uptime", "ProjectUptimeSubscription") |
| 13 | + |
| 14 | + monitors = ProjectUptimeSubscription.objects.filter().select_related("uptime_subscription") |
| 15 | + for monitor in RangeQuerySetWrapperWithProgressBar(monitors): |
| 16 | + sub = monitor.uptime_subscription |
| 17 | + sub.uptime_status = monitor.uptime_status |
| 18 | + sub.uptime_status_update_date = monitor.uptime_status_update_date |
| 19 | + sub.save() |
| 20 | + |
| 21 | + |
| 22 | +class Migration(CheckedMigration): |
| 23 | + # This flag is used to mark that a migration shouldn't be automatically run in production. |
| 24 | + # This should only be used for operations where it's safe to run the migration after your |
| 25 | + # code has deployed. So this should not be used for most operations that alter the schema |
| 26 | + # of a table. |
| 27 | + # Here are some things that make sense to mark as post deployment: |
| 28 | + # - Large data migrations. Typically we want these to be run manually so that they can be |
| 29 | + # monitored and not block the deploy for a long period of time while they run. |
| 30 | + # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to |
| 31 | + # run this outside deployments so that we don't block them. Note that while adding an index |
| 32 | + # is a schema change, it's completely safe to run the operation after the code has deployed. |
| 33 | + # Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment |
| 34 | + |
| 35 | + is_post_deployment = True |
| 36 | + |
| 37 | + dependencies = [ |
| 38 | + ("uptime", "0033_uptime_backfill_to_detectors"), |
| 39 | + ] |
| 40 | + |
| 41 | + operations = [] |
| 42 | + operations = [ |
| 43 | + migrations.RunPython( |
| 44 | + code=backfill_uptime_status, |
| 45 | + reverse_code=migrations.RunPython.noop, |
| 46 | + hints={ |
| 47 | + "tables": [ |
| 48 | + "uptime_projectuptimesubscription", |
| 49 | + "uptime_uptimesubscription", |
| 50 | + ] |
| 51 | + }, |
| 52 | + ), |
| 53 | + ] |
0 commit comments