Skip to content

Commit a6ffb34

Browse files
authored
Merge pull request #8530 from Couchers-org/backend/feature/gallery-last-updated
Add last_updated field to PhotoGallery
2 parents d5e7d11 + 1697fa6 commit a6ffb34

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Add last_updated field to PhotoGallery
2+
3+
Revision ID: 0150
4+
Revises: 0149
5+
Create Date: 2026-05-11 04:29:37.805098
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "0150"
14+
down_revision = "0149"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
op.add_column(
21+
"photo_galleries",
22+
sa.Column("last_updated", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
23+
)
24+
25+
26+
def downgrade() -> None:
27+
op.drop_column("photo_galleries", "last_updated")

app/backend/src/couchers/models/uploads.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class PhotoGallery(Base, kw_only=True):
8080
owner_user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True)
8181

8282
created: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), init=False)
83+
last_updated: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), init=False)
8384

8485
owner_user: Mapped[User] = relationship(init=False, foreign_keys=[owner_user_id], back_populates="galleries")
8586
photos: Mapped[list[PhotoGalleryItem]] = relationship(

app/backend/src/couchers/servicers/galleries.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def AddPhotoToGallery(
9696
caption=request.caption or None,
9797
)
9898
session.add(item)
99+
gallery.last_updated = func.now()
99100
session.flush()
100101
session.refresh(gallery)
101102

@@ -124,6 +125,7 @@ def RemovePhotoFromGallery(
124125
context.abort_with_error_code(grpc.StatusCode.NOT_FOUND, "gallery_item_not_found")
125126

126127
session.delete(item)
128+
gallery.last_updated = func.now()
127129
session.flush()
128130
session.refresh(gallery)
129131

@@ -184,6 +186,7 @@ def MovePhoto(
184186
session.execute(
185187
update(PhotoGalleryItem).where(PhotoGalleryItem.id == request.item_id).values(position=new_position)
186188
)
189+
gallery.last_updated = func.now()
187190

188191
session.flush()
189192
session.refresh(gallery)
@@ -213,6 +216,7 @@ def UpdatePhotoCaption(
213216
context.abort_with_error_code(grpc.StatusCode.NOT_FOUND, "gallery_item_not_found")
214217

215218
item.caption = request.caption or None
219+
gallery.last_updated = func.now()
216220
session.flush()
217221
session.refresh(gallery)
218222

0 commit comments

Comments
 (0)