Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-28 07:24:56

0001 """Rename alarm config params: days_window → since_days.
0002 
0003 Vocabulary cleanup. Existing alarm Entry rows in context 'swf-alarms'
0004 that have `data.params.days_window` get it moved to
0005 `data.params.since_days`. Value preserved; key renamed. If an alarm
0006 already has `since_days`, this migration leaves it alone.
0007 
0008 Idempotent; reverse is a no-op.
0009 """
0010 from __future__ import annotations
0011 
0012 from django.db import migrations
0013 
0014 
0015 CONTEXT_NAME = 'swf-alarms'
0016 
0017 
0018 def rename_key(apps, schema_editor):
0019     Entry = apps.get_model('remote_app', 'Entry')
0020     qs = Entry.objects.filter(context__name=CONTEXT_NAME, kind='alarm',
0021                               deleted_at__isnull=True)
0022     for e in qs:
0023         data = dict(e.data or {})
0024         params = dict(data.get('params') or {})
0025         if 'days_window' not in params:
0026             continue
0027         if 'since_days' in params:
0028             # Both present — trust since_days; drop the legacy key.
0029             params.pop('days_window', None)
0030         else:
0031             params['since_days'] = params.pop('days_window')
0032         data['params'] = params
0033         e.data = data
0034         e.save()
0035 
0036 
0037 def noop(apps, schema_editor):
0038     pass
0039 
0040 
0041 class Migration(migrations.Migration):
0042     dependencies = [('remote_app', '0005_drop_alarm_kind')]
0043     operations = [migrations.RunPython(rename_key, noop)]