feat: add date columns to the entries table (#740)

* feat: add date_created, date_modified, and date_added columns to entries table

* feat: start storing date_added dates
This commit is contained in:
Travis Abendshien
2025-01-28 01:57:01 -08:00
committed by GitHub
parent 1ba97d50c2
commit ba7e13041b
5 changed files with 19 additions and 1 deletions

View File

@@ -71,4 +71,4 @@ class LibraryPrefs(DefaultEnum):
IS_EXCLUDE_LIST = True
EXTENSION_LIST: list[str] = [".json", ".xmp", ".aae"]
PAGE_SIZE: int = 500
DB_VERSION: int = 4
DB_VERSION: int = 5

View File

@@ -230,6 +230,7 @@ class Library:
folder=folder,
fields=[],
id=entry.id + 1, # JSON IDs start at 0 instead of 1
date_added=datetime.now(),
)
for entry in json_lib.entries
]

View File

@@ -2,6 +2,7 @@
# Licensed under the GPL-3.0 License.
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio
import datetime as dt
from pathlib import Path
from sqlalchemy import JSON, ForeignKey, ForeignKeyConstraint, Integer, event
@@ -181,6 +182,9 @@ class Entry(Base):
path: Mapped[Path] = mapped_column(PathType, unique=True)
suffix: Mapped[str] = mapped_column()
date_created: Mapped[dt.datetime | None]
date_modified: Mapped[dt.datetime | None]
date_added: Mapped[dt.datetime | None]
tags: Mapped[set[Tag]] = relationship(secondary="tag_entries")
@@ -215,12 +219,23 @@ class Entry(Base):
folder: Folder,
fields: list[BaseField],
id: int | None = None,
date_created: dt.datetime | None = None,
date_modified: dt.datetime | None = None,
date_added: dt.datetime | None = None,
) -> None:
self.path = path
self.folder = folder
self.id = id
self.suffix = path.suffix.lstrip(".").lower()
# The date the file associated with this entry was created.
# st_birthtime on Windows and Mac, st_ctime on Linux.
self.date_created = date_created
# The date the file associated with this entry was last modified: st_mtime.
self.date_modified = date_modified
# The date this entry was added to the library.
self.date_added = date_added
for field in fields:
if isinstance(field, TextField):
self.text_fields.append(field)

View File

@@ -1,3 +1,4 @@
import datetime as dt
from collections.abc import Iterator
from dataclasses import dataclass, field
from pathlib import Path
@@ -41,6 +42,7 @@ class RefreshDirTracker:
path=entry_path,
folder=self.library.folder,
fields=[],
date_added=dt.datetime.now(),
)
for entry_path in self.files_not_in_library
]