Skip to content

Commit 2603a32

Browse files
committed
note that UpdatedAtMixin doesn't properly work on Postgres
We can't make it work; users must use a trigger Fixes #1
1 parent b75bdab commit 2603a32

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Bixomix Changelog
22

3+
## Unreleased
4+
5+
* Document `UpdatedAtMixin`’s incompatibility with Postgres (#1)
6+
37
## 0.1.0 (2023/03/30)
48

59
Initial public version.

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ class MyModel(Base, CreatedAtMixin):
3333
## Mixins
3434

3535
* `CreatedAtMixin`: add a `created_at` datetime field that’s automatically filled with the record’s creation date
36-
* `UpdatedAtMixin`: add an `updated_at` datetime field that’s automatically filled with the record’s last update date
36+
* `UpdatedAtMixin`: add an `updated_at` datetime field that’s automatically filled with the record’s last update date.
37+
Note this doesn't work on Postgres; you have to [create a trigger](https://stackoverflow.com/a/71072370/735926).
3738
* `CreatedUpdatedAtMixin`: combined version of the previous two mixins

bixomix/dates.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ class CreatedAtMixin:
1010

1111

1212
class UpdatedAtMixin:
13-
"""SQLAlchemy mixin to add an `updated_at` datetime field to a table."""
13+
"""
14+
SQLAlchemy mixin to add an `updated_at` datetime field to a table that’s set to `NOW()` every time the row is updated.
15+
Note that on Postgres this creates the column but doesn't update it.
16+
See https://stackoverflow.com/a/71072370/735926 for a possible solution.
17+
"""
1418
# NOTE:
1519
# server_default= tells the DB the default column value while default= sets the default value at the ORM level.
1620
# onupdate= sets the value on record update at the ORM level.

0 commit comments

Comments
 (0)