diff --git a/fiftyone/migrations/revisions/v0_25_0.py b/fiftyone/migrations/revisions/v0_26_0.py similarity index 63% rename from fiftyone/migrations/revisions/v0_25_0.py rename to fiftyone/migrations/revisions/v0_26_0.py index 7f54e13d38..09d5447550 100644 --- a/fiftyone/migrations/revisions/v0_25_0.py +++ b/fiftyone/migrations/revisions/v0_26_0.py @@ -1,10 +1,14 @@ """ -FiftyOne v0.25.0 revision. +FiftyOne v0.26.0 revision. | Copyright 2017-2024, Voxel51, Inc. | `voxel51.com `_ | """ +import logging + + +logger = logging.getLogger(__name__) def up(db, dataset_name): @@ -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 @@ -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, + ) diff --git a/package/desktop/setup.py b/package/desktop/setup.py index 232adcfb99..985c580dad 100644 --- a/package/desktop/setup.py +++ b/package/desktop/setup.py @@ -16,7 +16,7 @@ import shutil -VERSION = "0.35.0" +VERSION = "0.36.0" def get_version(): diff --git a/setup.py b/setup.py index ed47bbe01b..591c52e8b4 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ from setuptools import setup, find_packages -VERSION = "0.25.0" +VERSION = "0.26.0" def get_version(): @@ -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: