@@ -61,3 +61,33 @@ def create_permissions_for_default_groups(apps, schema_editor, app_label):
6161def create_device_firmware_for_connections (apps , schema_editor , app_label ):
6262 for device_connection in DeviceConnection .objects .all ():
6363 DeviceFirmware .create_for_device (device_connection .device )
64+
65+
66+ # Mapping of old image type identifiers to new ones
67+ IMAGE_TYPE_MAPPING = {
68+ "octeon-erlite-squashfs-sysupgrade.tar" : "octeon-generic-ubnt_edgerouter-lite-squashfs-sysupgrade.tar" ,
69+ "ath79-generic-ubnt_unifi-squashfs-sysupgrade.bin" : "ath79-generic-ubnt_unifi-ap-squashfs-sysupgrade.bin" ,
70+ "x86-generic-combined-squashfs.img.gz" : "x86-generic-generic-squashfs-combined.img.gz" ,
71+ "x86-geode-combined-squashfs.img.gz" : "x86-geode-generic-squashfs-combined.img.gz" ,
72+ }
73+
74+ # Reverse mapping for rollback
75+ REVERSE_IMAGE_TYPE_MAPPING = {v : k for k , v in IMAGE_TYPE_MAPPING .items ()}
76+
77+
78+ def update_image_types_forward (apps , schema_editor , app_label ):
79+ """
80+ Updates firmware image type identifiers from old values to new values.
81+ """
82+ FirmwareImage = apps .get_model (app_label , "FirmwareImage" )
83+ for old_type , new_type in IMAGE_TYPE_MAPPING .items ():
84+ FirmwareImage .objects .filter (type = old_type ).update (type = new_type )
85+
86+
87+ def update_image_types_reverse (apps , schema_editor , app_label ):
88+ """
89+ Reverts firmware image type identifiers from new values back to old values.
90+ """
91+ FirmwareImage = apps .get_model (app_label , "FirmwareImage" )
92+ for new_type , old_type in REVERSE_IMAGE_TYPE_MAPPING .items ():
93+ FirmwareImage .objects .filter (type = new_type ).update (type = old_type )
0 commit comments