Skip to content

Commit ba7e130

Browse files
authored
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
1 parent 1ba97d5 commit ba7e130

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

tagstudio/src/core/enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ class LibraryPrefs(DefaultEnum):
7171
IS_EXCLUDE_LIST = True
7272
EXTENSION_LIST: list[str] = [".json", ".xmp", ".aae"]
7373
PAGE_SIZE: int = 500
74-
DB_VERSION: int = 4
74+
DB_VERSION: int = 5

tagstudio/src/core/library/alchemy/library.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def migrate_json_to_sqlite(self, json_lib: JsonLibrary):
230230
folder=folder,
231231
fields=[],
232232
id=entry.id + 1, # JSON IDs start at 0 instead of 1
233+
date_added=datetime.now(),
233234
)
234235
for entry in json_lib.entries
235236
]

tagstudio/src/core/library/alchemy/models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the GPL-3.0 License.
33
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio
44

5+
import datetime as dt
56
from pathlib import Path
67

78
from sqlalchemy import JSON, ForeignKey, ForeignKeyConstraint, Integer, event
@@ -181,6 +182,9 @@ class Entry(Base):
181182

182183
path: Mapped[Path] = mapped_column(PathType, unique=True)
183184
suffix: Mapped[str] = mapped_column()
185+
date_created: Mapped[dt.datetime | None]
186+
date_modified: Mapped[dt.datetime | None]
187+
date_added: Mapped[dt.datetime | None]
184188

185189
tags: Mapped[set[Tag]] = relationship(secondary="tag_entries")
186190

@@ -215,12 +219,23 @@ def __init__(
215219
folder: Folder,
216220
fields: list[BaseField],
217221
id: int | None = None,
222+
date_created: dt.datetime | None = None,
223+
date_modified: dt.datetime | None = None,
224+
date_added: dt.datetime | None = None,
218225
) -> None:
219226
self.path = path
220227
self.folder = folder
221228
self.id = id
222229
self.suffix = path.suffix.lstrip(".").lower()
223230

231+
# The date the file associated with this entry was created.
232+
# st_birthtime on Windows and Mac, st_ctime on Linux.
233+
self.date_created = date_created
234+
# The date the file associated with this entry was last modified: st_mtime.
235+
self.date_modified = date_modified
236+
# The date this entry was added to the library.
237+
self.date_added = date_added
238+
224239
for field in fields:
225240
if isinstance(field, TextField):
226241
self.text_fields.append(field)

tagstudio/src/core/utils/refresh_dir.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime as dt
12
from collections.abc import Iterator
23
from dataclasses import dataclass, field
34
from pathlib import Path
@@ -41,6 +42,7 @@ def save_new_files(self):
4142
path=entry_path,
4243
folder=self.library.folder,
4344
fields=[],
45+
date_added=dt.datetime.now(),
4446
)
4547
for entry_path in self.files_not_in_library
4648
]
Binary file not shown.

0 commit comments

Comments
 (0)