Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
🚚 Recode visibility (#316)
Browse files Browse the repository at this point in the history
* 🚚 Recode visibility

* ✏️ Update default

* 🎨 Fix

* 🎨 Fix
  • Loading branch information
sunnyosun authored Nov 23, 2023
1 parent 46099bf commit 4e1424e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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),
]
4 changes: 2 additions & 2 deletions lnschema_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down
6 changes: 3 additions & 3 deletions lnschema_core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ class TransformType(ChoicesMixin, Enum):


class VisibilityChoice(IntegerChoices):
default = 0
hidden = 1
trash = 2
default = 1
hidden = 0
trash = -1

0 comments on commit 4e1424e

Please sign in to comment.