Repository: openwisp/openwisp-firmware-upgrader (language: python)

Issue:
[cleanup] Re-generate sample app migrations
We don't need to keep migrations for the sample app since it's meant only for testing, therefore we can delete all the migrations and regenerate them, except for `0002_default_permissions.py` or any other data migration, which shall left intact.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index df685686..b412c915 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -36,7 +36,7 @@ jobs:
 
       - name: Install system packages
         run: |
-          sudo apt-get update && sudo apt-get upgrade
+          sudo apt-get update
           sudo apt-get -qq install \
           sqlite3 \
           gdal-bin \


Test patch:
diff --git a/tests/openwisp2/sample_firmware_upgrader/migrations/0001_initial.py b/tests/openwisp2/sample_firmware_upgrader/migrations/0001_initial.py
index 0be8f7f6..9363ae3c 100644
--- a/tests/openwisp2/sample_firmware_upgrader/migrations/0001_initial.py
+++ b/tests/openwisp2/sample_firmware_upgrader/migrations/0001_initial.py
@@ -1,10 +1,14 @@
-# Generated by Django 3.0 on 2020-03-08 10:20
+# Generated by Django 3.1.1 on 2021-03-12 15:10
 
+from django.conf import settings
 from django.db import migrations, models
 import django.db.models.deletion
 import django.utils.timezone
 import model_utils.fields
+import openwisp_firmware_upgrader.base.models
 import openwisp_users.mixins
+import private_storage.fields
+import private_storage.storage.files
 import uuid
 import swapper
 from openwisp_firmware_upgrader.hardware import FIRMWARE_IMAGE_TYPE_CHOICES
@@ -15,8 +19,8 @@ class Migration(migrations.Migration):
     initial = True
 
     dependencies = [
-        ('config', '0025_update_device_key'),
-        ('openwisp_users', '0007_unique_email'),
+        migrations.swappable_dependency(settings.CONFIG_DEVICE_MODEL),
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
     ]
 
     operations = [
@@ -52,17 +56,22 @@ class Migration(migrations.Migration):
                     'status',
                     models.CharField(
                         choices=[
+                            ('idle', 'idle'),
                             ('in-progress', 'in progress'),
                             ('success', 'completed successfully'),
                             ('failed', 'completed with some failures'),
                         ],
-                        default='in-progress',
+                        default='idle',
                         max_length=12,
                     ),
                 ),
                 ('details', models.CharField(blank=True, max_length=64, null=True)),
             ],
-            options={'abstract': False,},
+            options={
+                'verbose_name': 'Mass upgrade operation',
+                'verbose_name_plural': 'Mass upgrade operations',
+                'abstract': False,
+            },
         ),
         migrations.CreateModel(
             name='Build',
@@ -93,6 +102,16 @@ class Migration(migrations.Migration):
                     ),
                 ),
                 ('version', models.CharField(db_index=True, max_length=32)),
+                (
+                    'os',
+                    models.CharField(
+                        blank=True,
+                        help_text='OS identifier as presented by the device, used to automatically recognize the firmware image used by new devices that register into the system',
+                        max_length=64,
+                        null=True,
+                        verbose_name='OS identifier',
+                    ),
+                ),
                 (
                     'changelog',
                     models.TextField(
@@ -103,7 +122,12 @@ class Migration(migrations.Migration):
                 ),
                 ('details', models.CharField(blank=True, max_length=64, null=True)),
             ],
-            options={'abstract': False,},
+            options={
+                'verbose_name': 'Firmware Build',
+                'verbose_name_plural': 'Firmware Builds',
+                'ordering': ('-created',),
+                'abstract': False,
+            },
         ),
         migrations.CreateModel(
             name='FirmwareImage',
@@ -133,7 +157,14 @@ class Migration(migrations.Migration):
                         verbose_name='modified',
                     ),
                 ),
-                ('file', models.FileField(upload_to='')),
+                (
+                    'file',
+                    private_storage.fields.PrivateFileField(
+                        storage=private_storage.storage.files.PrivateFileSystemStorage(),
+                        upload_to=openwisp_firmware_upgrader.base.models.get_build_directory,
+                        verbose_name='File',
+                    ),
+                ),
                 (
                     'type',
                     models.CharField(
@@ -152,7 +183,12 @@ class Migration(migrations.Migration):
                     ),
                 ),
             ],
-            options={'abstract': False,},
+            options={
+                'verbose_name': 'Firmware Image',
+                'verbose_name_plural': 'Firmware Images',
+                'abstract': False,
+                'unique_together': {('build', 'type')},
+            },
         ),
         migrations.CreateModel(
             name='UpgradeOperation',
@@ -218,7 +254,8 @@ class Migration(migrations.Migration):
                 (
                     'image',
                     models.ForeignKey(
-                        on_delete=django.db.models.deletion.CASCADE,
+                        null=True,
+                        on_delete=django.db.models.deletion.SET_NULL,
                         to=swapper.get_model_name('firmware_upgrader', 'FirmwareImage'),
                     ),
                 ),
@@ -270,7 +307,7 @@ class Migration(migrations.Migration):
                     ),
                 ),
             ],
-            options={'abstract': False,},
+            options={'verbose_name': 'Device Firmware', 'abstract': False,},
         ),
         migrations.CreateModel(
             name='Category',
@@ -312,7 +349,12 @@ class Migration(migrations.Migration):
                     ),
                 ),
             ],
-            options={'abstract': False,},
+            options={
+                'verbose_name': 'Firmware Category',
+                'verbose_name_plural': 'Firmware Categories',
+                'abstract': False,
+                'unique_together': {('name', 'organization')},
+            },
             bases=(openwisp_users.mixins.ValidateOrgMixin, models.Model),
         ),
         migrations.AddField(
@@ -333,4 +375,7 @@ class Migration(migrations.Migration):
                 to=swapper.get_model_name('firmware_upgrader', 'Build'),
             ),
         ),
+        migrations.AlterUniqueTogether(
+            name='build', unique_together={('category', 'version')},
+        ),
     ]
diff --git a/tests/openwisp2/sample_firmware_upgrader/migrations/0002_default_permissions.py b/tests/openwisp2/sample_firmware_upgrader/migrations/0002_default_permissions.py
index 956b6970..5892114e 100644
--- a/tests/openwisp2/sample_firmware_upgrader/migrations/0002_default_permissions.py
+++ b/tests/openwisp2/sample_firmware_upgrader/migrations/0002_default_permissions.py
@@ -1,3 +1,5 @@
+# Generated by Django 3.1.1 on 2021-03-12 15:14
+
 from django.db import migrations
 
 from openwisp_firmware_upgrader.migrations import create_permissions_for_default_groups
diff --git a/tests/openwisp2/sample_firmware_upgrader/migrations/0007_create_device_firmware.py b/tests/openwisp2/sample_firmware_upgrader/migrations/0003_create_device_firmware.py
similarity index 83%
rename from tests/openwisp2/sample_firmware_upgrader/migrations/0007_create_device_firmware.py
rename to tests/openwisp2/sample_firmware_upgrader/migrations/0003_create_device_firmware.py
index 20d733cc..0db4e1f1 100644
--- a/tests/openwisp2/sample_firmware_upgrader/migrations/0007_create_device_firmware.py
+++ b/tests/openwisp2/sample_firmware_upgrader/migrations/0003_create_device_firmware.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.0.8 on 2020-07-07 17:00
+# Generated by Django 3.1.1 on 2021-03-12 15:16
 
 from django.db import migrations
 
@@ -13,7 +13,7 @@ def create_device_firmware_for_connections_helper(apps, schema_editor):
 class Migration(migrations.Migration):
 
     dependencies = [
-        ('sample_firmware_upgrader', '0006_build_os_identifier'),
+        ('sample_firmware_upgrader', '0002_default_permissions'),
     ]
 
     operations = [
diff --git a/tests/openwisp2/sample_firmware_upgrader/migrations/0003_private_media.py b/tests/openwisp2/sample_firmware_upgrader/migrations/0003_private_media.py
deleted file mode 100644
index 1918b0ff..00000000
--- a/tests/openwisp2/sample_firmware_upgrader/migrations/0003_private_media.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Generated by Django 3.0.5 on 2020-04-14 18:13
-
-from django.db import migrations
-import openwisp_firmware_upgrader.base.models
-import private_storage.fields
-import private_storage.storage.files
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('sample_firmware_upgrader', '0002_default_permissions'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='firmwareimage',
-            name='file',
-            field=private_storage.fields.PrivateFileField(
-                storage=private_storage.storage.files.PrivateFileSystemStorage(),
-                upload_to=openwisp_firmware_upgrader.base.models.get_build_directory,
-                verbose_name='File',
-            ),
-        ),
-    ]
diff --git a/tests/openwisp2/sample_firmware_upgrader/migrations/0004_model_options.py b/tests/openwisp2/sample_firmware_upgrader/migrations/0004_model_options.py
deleted file mode 100644
index f8a7580b..00000000
--- a/tests/openwisp2/sample_firmware_upgrader/migrations/0004_model_options.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# Generated by Django 3.0.5 on 2020-05-19 17:42
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('openwisp_users', '0007_unique_email'),
-        ('sample_firmware_upgrader', '0003_private_media'),
-    ]
-
-    operations = [
-        migrations.AlterModelOptions(
-            name='batchupgradeoperation',
-            options={
-                'verbose_name': 'Mass upgrade operation',
-                'verbose_name_plural': 'Mass upgrade operations',
-            },
-        ),
-        migrations.AlterModelOptions(
-            name='build',
-            options={
-                'ordering': ('-created',),
-                'verbose_name': 'Firmware Build',
-                'verbose_name_plural': 'Firmware Builds',
-            },
-        ),
-        migrations.AlterModelOptions(
-            name='category',
-            options={
-                'verbose_name': 'Firmware Category',
-                'verbose_name_plural': 'Firmware Categories',
-            },
-        ),
-        migrations.AlterModelOptions(
-            name='devicefirmware', options={'verbose_name': 'Device Firmware'},
-        ),
-        migrations.AlterModelOptions(
-            name='firmwareimage',
-            options={
-                'verbose_name': 'Firmware Image',
-                'verbose_name_plural': 'Firmware Images',
-            },
-        ),
-        migrations.AlterUniqueTogether(
-            name='build', unique_together={('category', 'version')},
-        ),
-        migrations.AlterUniqueTogether(
-            name='category', unique_together={('name', 'organization')},
-        ),
-        migrations.AlterUniqueTogether(
-            name='firmwareimage', unique_together={('build', 'type')},
-        ),
-    ]
diff --git a/tests/openwisp2/sample_firmware_upgrader/migrations/0005_batch_upgrade_operation_idle_status.py b/tests/openwisp2/sample_firmware_upgrader/migrations/0005_batch_upgrade_operation_idle_status.py
deleted file mode 100644
index ee4c89f6..00000000
--- a/tests/openwisp2/sample_firmware_upgrader/migrations/0005_batch_upgrade_operation_idle_status.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Generated by Django 3.0.5 on 2020-06-03 16:16
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('sample_firmware_upgrader', '0004_model_options'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='batchupgradeoperation',
-            name='status',
-            field=models.CharField(
-                choices=[
-                    ('idle', 'idle'),
-                    ('in-progress', 'in progress'),
-                    ('success', 'completed successfully'),
-                    ('failed', 'completed with some failures'),
-                ],
-                default='idle',
-                max_length=12,
-            ),
-        )
-    ]
diff --git a/tests/openwisp2/sample_firmware_upgrader/migrations/0006_build_os_identifier.py b/tests/openwisp2/sample_firmware_upgrader/migrations/0006_build_os_identifier.py
deleted file mode 100644
index e6ab4040..00000000
--- a/tests/openwisp2/sample_firmware_upgrader/migrations/0006_build_os_identifier.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Generated by Django 3.0.8 on 2020-07-07 17:00
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('sample_firmware_upgrader', '0005_batch_upgrade_operation_idle_status'),
-    ]
-
-    operations = [
-        migrations.AddField(
-            model_name='build',
-            name='os',
-            field=models.CharField(
-                blank=True,
-                help_text='OS identifier as presented by the device, used to automatically recognize the firmware image used by new devices that register into the system',
-                max_length=64,
-                null=True,
-                verbose_name='OS identifier',
-            ),
-        ),
-    ]
diff --git a/tests/openwisp2/sample_firmware_upgrader/migrations/0008_nullable_upgrade_operation_image.py b/tests/openwisp2/sample_firmware_upgrader/migrations/0008_nullable_upgrade_operation_image.py
deleted file mode 100644
index 6f13dbb4..00000000
--- a/tests/openwisp2/sample_firmware_upgrader/migrations/0008_nullable_upgrade_operation_image.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Generated by Django 3.1.5 on 2021-01-21 16:57
-
-from django.conf import settings
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('sample_firmware_upgrader', '0007_create_device_firmware'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='upgradeoperation',
-            name='image',
-            field=models.ForeignKey(
-                null=True,
-                on_delete=django.db.models.deletion.SET_NULL,
-                to=settings.FIRMWARE_UPGRADER_FIRMWAREIMAGE_MODEL,
-            ),
-        ),
-    ]