diff --git a/lnschema_core/migrations/0030_alter_dataset_visibility_alter_file_visibility.py b/lnschema_core/migrations/0030_alter_dataset_visibility_alter_file_visibility.py new file mode 100644 index 00000000..c63412b0 --- /dev/null +++ b/lnschema_core/migrations/0030_alter_dataset_visibility_alter_file_visibility.py @@ -0,0 +1,72 @@ +# Generated by Django 4.2.1 on 2023-11-23 20:27 + +from django.db import IntegrityError, migrations, models, transaction + + +def forwards_func(apps, schema_editor): + File = apps.get_model("lnschema_core", "File") + Dataset = apps.get_model("lnschema_core", "Dataset") + db_alias = schema_editor.connection.alias + # see https://stackoverflow.com/a/23326971 + try: + with transaction.atomic(): + File.objects.using(db_alias).filter(visibility=0).update(visibility=3) + File.objects.using(db_alias).filter(visibility=1).update(visibility=0) + File.objects.using(db_alias).filter(visibility=3).update(visibility=1) + File.objects.using(db_alias).filter(visibility=2).update(visibility=-1) + Dataset.objects.using(db_alias).filter(visibility=0).update(visibility=3) + Dataset.objects.using(db_alias).filter(visibility=1).update(visibility=0) + Dataset.objects.using(db_alias).filter(visibility=3).update(visibility=1) + Dataset.objects.using(db_alias).filter(visibility=2).update(visibility=-1) + except IntegrityError: + pass + + +def reverse_func(apps, schema_editor): + File = apps.get_model("lnschema_core", "File") + Dataset = apps.get_model("lnschema_core", "Dataset") + db_alias = schema_editor.connection.alias + # see https://stackoverflow.com/a/23326971 + try: + with transaction.atomic(): + File.objects.using(db_alias).filter(visibility=0).update(visibility=3) + File.objects.using(db_alias).filter(visibility=1).update(visibility=0) + File.objects.using(db_alias).filter(visibility=3).update(visibility=1) + File.objects.using(db_alias).filter(visibility=-1).update(visibility=2) + Dataset.objects.using(db_alias).filter(visibility=0).update(visibility=3) + Dataset.objects.using(db_alias).filter(visibility=1).update(visibility=0) + Dataset.objects.using(db_alias).filter(visibility=3).update(visibility=1) + Dataset.objects.using(db_alias).filter(visibility=-1).update(visibility=2) + except IntegrityError: + pass + + +class Migration(migrations.Migration): + dependencies = [ + ( + "lnschema_core", + "0029_remove_feature_modality_remove_featureset_modality_and_more", + ), + ] + + operations = [ + migrations.AlterField( + model_name="dataset", + name="visibility", + field=models.SmallIntegerField( + choices=[(1, "Default"), (0, "Hidden"), (-1, "Trash")], + db_index=True, + default=1, + ), + ), + migrations.AlterField( + model_name="file", + name="visibility", + field=models.SmallIntegerField( + choices=[(1, "Default"), (0, "Hidden"), (-1, "Trash")], + db_index=True, + default=1, + ), + ), + migrations.RunPython(forwards_func, reverse_func), + ] diff --git a/lnschema_core/models.py b/lnschema_core/models.py index a0a49cce..b808bd6d 100644 --- a/lnschema_core/models.py +++ b/lnschema_core/models.py @@ -1434,7 +1434,7 @@ class File(Registry, Data): """Runs that use this file as an input.""" initial_version = models.ForeignKey("self", PROTECT, null=True, default=None) """Initial version of the file, a :class:`~lamindb.File` object.""" - visibility = models.SmallIntegerField(db_index=True, choices=VisibilityChoice.choices, default=0) + visibility = models.SmallIntegerField(db_index=True, choices=VisibilityChoice.choices, default=1) """Visibility of file record in queries & searches (0 default, 1 hidden, 2 trash).""" key_is_virtual = models.BooleanField() """Indicates whether `key` is virtual or part of an actual file path.""" @@ -1927,7 +1927,7 @@ class Dataset(Registry, Data): """Storage of dataset as mere paths handled by a key value store or file system.""" initial_version = models.ForeignKey("self", PROTECT, null=True, default=None) """Initial version of the dataset, a :class:`~lamindb.Dataset` object.""" - visibility = models.SmallIntegerField(db_index=True, choices=VisibilityChoice.choices, default=0) + visibility = models.SmallIntegerField(db_index=True, choices=VisibilityChoice.choices, default=1) """Visibility of record, 0-default, 1-hidden, 2-trash.""" created_at = models.DateTimeField(auto_now_add=True, db_index=True) """Time of creation of record.""" diff --git a/lnschema_core/types.py b/lnschema_core/types.py index 4f0fee9c..2e1fcbe9 100644 --- a/lnschema_core/types.py +++ b/lnschema_core/types.py @@ -42,6 +42,6 @@ class TransformType(ChoicesMixin, Enum): class VisibilityChoice(IntegerChoices): - default = 0 - hidden = 1 - trash = 2 + default = 1 + hidden = 0 + trash = -1