0241_nullify_empty_cable_end.py 958 B

1234567891011121314151617181920212223242526272829303132333435
  1. from django.db import migrations
  2. CABLED_MODELS = (
  3. 'ConsolePort',
  4. 'ConsoleServerPort',
  5. 'FrontPort',
  6. 'Interface',
  7. 'PowerFeed',
  8. 'PowerOutlet',
  9. 'PowerPort',
  10. 'RearPort',
  11. )
  12. def nullify_empty_cable_end(apps, schema_editor):
  13. """
  14. Replace empty strings with null values on cached cable end data. Earlier versions
  15. wrote an empty string when a cable termination was deleted, leaving disconnected
  16. endpoints inconsistent with those which have never been cabled.
  17. """
  18. db_alias = schema_editor.connection.alias
  19. for model_name in CABLED_MODELS:
  20. model = apps.get_model('dcim', model_name)
  21. model.objects.using(db_alias).filter(cable_end='').update(cable_end=None)
  22. class Migration(migrations.Migration):
  23. dependencies = [
  24. ('dcim', '0240_clear_stale_cable_profile_data'),
  25. ]
  26. operations = [
  27. migrations.RunPython(nullify_empty_cable_end, migrations.RunPython.noop),
  28. ]