Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tagstudio/src/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tagstudio/src/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def migrate_json_to_sqlite(self, json_lib: JsonLibrary):
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
]
Expand Down
15 changes: 15 additions & 0 deletions tagstudio/src/core/library/alchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -215,12 +219,23 @@ def __init__(
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)
Expand Down
2 changes: 2 additions & 0 deletions tagstudio/src/core/utils/refresh_dir.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime as dt
from collections.abc import Iterator
from dataclasses import dataclass, field
from pathlib import Path
Expand Down Expand Up @@ -41,6 +42,7 @@ def save_new_files(self):
path=entry_path,
folder=self.library.folder,
fields=[],
date_added=dt.datetime.now(),
)
for entry_path in self.files_not_in_library
]
Expand Down
Binary file not shown.
Loading