@@ -77,21 +77,6 @@ class Singer(Base):
7777 concerts : Mapped [List ["Concert" ]] = relationship (
7878 back_populates = "singer" , cascade = "all, delete-orphan"
7979 )
80- # Create a commit timestamp column and set a client-side default of
81- # PENDING_COMMIT_TIMESTAMP() An event handler below is responsible for
82- # setting PENDING_COMMIT_TIMESTAMP() on updates. If using SQLAlchemy
83- # core rather than the ORM, callers will need to supply their own
84- # PENDING_COMMIT_TIMESTAMP() values in their inserts & updates.
85- last_update_time : Mapped [datetime .datetime ] = mapped_column (
86- spanner_allow_commit_timestamp = True ,
87- default = text ("PENDING_COMMIT_TIMESTAMP()" ),
88- )
89-
90-
91- @event .listens_for (TimestampUser , "before_update" )
92- def singer_before_update (mapper , connection , target ):
93- """Updates the commit timestamp when the row is updated."""
94- target .updated_at = text ("PENDING_COMMIT_TIMESTAMP()" )
9580
9681
9782class Album (Base ):
@@ -194,3 +179,18 @@ class TicketSale(Base):
194179 DateTime , nullable = False
195180 )
196181 singer_id : Mapped [str ] = mapped_column (String (36 ), ForeignKey ("singers.id" ))
182+ # Create a commit timestamp column and set a client-side default of
183+ # PENDING_COMMIT_TIMESTAMP() An event handler below is responsible for
184+ # setting PENDING_COMMIT_TIMESTAMP() on updates. If using SQLAlchemy
185+ # core rather than the ORM, callers will need to supply their own
186+ # PENDING_COMMIT_TIMESTAMP() values in their inserts & updates.
187+ last_update_time : Mapped [datetime .datetime ] = mapped_column (
188+ spanner_allow_commit_timestamp = True ,
189+ default = text ("PENDING_COMMIT_TIMESTAMP()" ),
190+ )
191+
192+
193+ @event .listens_for (TicketSale , "before_update" )
194+ def ticket_sale_before_update (mapper , connection , target ):
195+ """Updates the commit timestamp when the row is updated."""
196+ target .last_update_time = text ("PENDING_COMMIT_TIMESTAMP()" )
0 commit comments