|
| 1 | +# Generated by Django 3.2.23 on 2024-01-17 16:06 |
| 2 | + |
| 3 | +from django.db import migrations |
| 4 | + |
| 5 | +from sentry.new_migrations.migrations import CheckedMigration |
| 6 | +from sentry.utils.query import RangeQuerySetWrapperWithProgressBar |
| 7 | + |
| 8 | + |
| 9 | +def backfill_last_token_characters(apps, _): |
| 10 | + from sentry.models.apitoken import ApiToken |
| 11 | + |
| 12 | + for api_token in RangeQuerySetWrapperWithProgressBar(ApiToken.objects.all()): |
| 13 | + if api_token.token_last_characters is None: |
| 14 | + last_four = api_token.token[-4:] |
| 15 | + api_token.token_last_characters = last_four |
| 16 | + api_token.save() |
| 17 | + |
| 18 | + |
| 19 | +class Migration(CheckedMigration): |
| 20 | + # This flag is used to mark that a migration shouldn't be automatically run in production. For |
| 21 | + # the most part, this should only be used for operations where it's safe to run the migration |
| 22 | + # after your code has deployed. So this should not be used for most operations that alter the |
| 23 | + # schema of a table. |
| 24 | + # Here are some things that make sense to mark as dangerous: |
| 25 | + # - Large data migrations. Typically we want these to be run manually by ops so that they can |
| 26 | + # be monitored and not block the deploy for a long period of time while they run. |
| 27 | + # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to |
| 28 | + # have ops run this and not block the deploy. Note that while adding an index is a schema |
| 29 | + # change, it's completely safe to run the operation after the code has deployed. |
| 30 | + is_dangerous = True |
| 31 | + |
| 32 | + dependencies = [ |
| 33 | + ("sentry", "0631_add_priority_columns_to_groupedmessage"), |
| 34 | + ] |
| 35 | + |
| 36 | + operations = [ |
| 37 | + migrations.RunPython( |
| 38 | + backfill_last_token_characters, |
| 39 | + migrations.RunPython.noop, |
| 40 | + hints={ |
| 41 | + "tables": [ |
| 42 | + "sentry_apitoken", |
| 43 | + ] |
| 44 | + }, |
| 45 | + ), |
| 46 | + ] |
0 commit comments