Skip to content

Commit

Permalink
populate created_at when upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
brimoor committed Jul 27, 2024
1 parent 1e5ff25 commit 7774662
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""
FiftyOne v0.25.0 revision.
FiftyOne v0.26.0 revision.
| Copyright 2017-2024, Voxel51, Inc.
| `voxel51.com <https://voxel51.com/>`_
|
"""
import logging


logger = logging.getLogger(__name__)


def up(db, dataset_name):
Expand All @@ -15,16 +19,30 @@ def up(db, dataset_name):
if "last_modified_at" not in dataset_dict:
dataset_dict["last_modified_at"] = None

add_samples_created_at = False
sample_fields = dataset_dict.get("sample_fields", [])
if sample_fields:
_up_fields(sample_fields)
add_samples_created_at = _up_fields(sample_fields)

add_frames_created_at = False
frame_fields = dataset_dict.get("frame_fields", [])
if frame_fields:
_up_fields(frame_fields)
add_frames_created_at = _up_fields(frame_fields)

db.datasets.replace_one(match_d, dataset_dict)

if add_samples_created_at:
sample_collection_name = dataset_dict.get(
"sample_collection_name", None
)
if sample_collection_name:
_add_created_at(db, dataset_name, sample_collection_name)

if add_frames_created_at:
frame_collection_name = dataset_dict.get("frame_collection_name", None)
if frame_collection_name:
_add_created_at(db, dataset_name, frame_collection_name)


def down(db, dataset_name):
pass
Expand Down Expand Up @@ -74,3 +92,17 @@ def _up_fields(fields):
"read_only": True,
}
)

return not found_created_at


def _add_created_at(db, dataset_name, collection_name):
try:
pipeline = [{"$set": {"created_at": {"$toDate": "$_id"}}}]
db[collection_name].update_many({}, pipeline)
except Exception as e:
logger.warning(
"Failed to populate 'created_at' field for dataset %s. Reason: %s",
dataset_name,
e,
)
2 changes: 1 addition & 1 deletion package/desktop/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import shutil


VERSION = "0.35.0"
VERSION = "0.36.0"


def get_version():
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from setuptools import setup, find_packages


VERSION = "0.25.0"
VERSION = "0.26.0"


def get_version():
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_install_requirements(install_requires, choose_install_requires):
return install_requires


EXTRAS_REQUIREMENTS = {"desktop": ["fiftyone-desktop~=0.35.0"]}
EXTRAS_REQUIREMENTS = {"desktop": ["fiftyone-desktop~=0.36.0"]}


with open("README.md", "r") as fh:
Expand Down

0 comments on commit 7774662

Please sign in to comment.