Skip to content

Commit 9eda5a0

Browse files
erosselliclaude
andauthored
ENG-3288 Add onupdate to PrivacyPreferences.updated_at column (#7851)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent aaee46c commit 9eda5a0

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type: Fixed
2+
description: Fixed updated_at column on privacy_preferences to auto-populate on record updates
3+
pr: 7851
4+
labels: []

src/fides/api/models/v3/privacy_preferences.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from sqlalchemy.dialects.postgresql import JSONB
1313
from sqlalchemy.ext.declarative import declared_attr
1414
from sqlalchemy.orm import Session
15+
from sqlalchemy.sql import func
1516

1617
from fides.api.cryptography.cryptographic_util import hash_value_with_salt
1718
from fides.api.cryptography.identity_salt import get_identity_salt
@@ -76,14 +77,23 @@ def __tablename__(self) -> str:
7677
Boolean, nullable=False, server_default=text("false"), primary_key=True
7778
)
7879

79-
# Override base class timestamp columns to match migration
80+
# Override base class timestamp columns:
81+
# - created_at: indexed for query performance (base class doesn't index it)
82+
# - updated_at: nullable with no server_default (unlike base class which defaults
83+
# to now()). New records start with updated_at=NULL; it is only set when a
84+
# record is later modified (this only happens when is_latest is flipped
85+
# from True to False).
8086
created_at = Column(
8187
DateTime(timezone=True),
8288
nullable=False,
8389
server_default=text("now()"),
8490
index=True,
8591
)
86-
updated_at = Column(DateTime(timezone=True), nullable=True)
92+
updated_at = Column(
93+
DateTime(timezone=True),
94+
nullable=True,
95+
onupdate=func.now(),
96+
)
8797

8898
@classmethod
8999
def hash_value(

0 commit comments

Comments
 (0)