Skip to content

Commit

Permalink
Adjust how commits get the current time
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Hadley committed May 3, 2023
1 parent 4d7b413 commit 2833708
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- `ParamDB.dispose()` function for cases where it is required to fully clean up the
database before the program ends, such as in testing suites.

### Changed

- Commits get the current time in a way that can be mocked in tests where we
want to control the time.

## [0.5.0] (Apr 11 2023)

### Changed
Expand Down
13 changes: 10 additions & 3 deletions paramdb/_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,16 @@ class _Snapshot(_Base):
__tablename__ = "snapshot"

message: Mapped[str]
"""Commit message."""
data: Mapped[bytes]
"""Compressed data."""
id: Mapped[int] = mapped_column(init=False, primary_key=True)
timestamp: Mapped[datetime] = mapped_column(default_factory=datetime.utcnow)
"""Commit ID."""
# datetime.utcnow is wrapped in a lambda function to allow it to be mocked in tests
# where we want to control the time.
timestamp: Mapped[datetime] = mapped_column(
default_factory=lambda: datetime.utcnow() # pylint: disable=unnecessary-lambda
)
"""Naive datetime in UTC time (since this is how SQLite stores datetimes)."""


Expand All @@ -110,9 +117,9 @@ class CommitEntry:
"""Entry for a commit given commit containing the ID, message, and timestamp."""

id: int
"""Commit ID"""
"""Commit ID."""
message: str
"""Message for this commit."""
"""Commit message."""
timestamp: datetime
"""When this commit was created."""

Expand Down

0 comments on commit 2833708

Please sign in to comment.